1
mirror of https://github.com/Shiewk/ViewServerResources.git synced 2026-04-28 03:44:17 +02:00

Show downloaded pack URLs in chat

This commit is contained in:
Shy
2024-08-24 13:08:03 +02:00
parent deefdf90c3
commit 45afdde854
5 changed files with 51 additions and 5 deletions
@@ -3,8 +3,6 @@ package de.shiewk.resourcepackprivacy.client;
import de.shiewk.resourcepackprivacy.event.ChatAnnouncer;
import de.shiewk.resourcepackprivacy.event.ScreenListener;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
@@ -13,6 +11,6 @@ public class ResourcePackPrivacyClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ScreenEvents.AFTER_INIT.register(new ScreenListener());
ClientTickEvents.END_CLIENT_TICK.register(new ChatAnnouncer());
}
}
@@ -0,0 +1,21 @@
package de.shiewk.resourcepackprivacy.event;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
public class ChatAnnouncer implements ClientTickEvents.EndTick {
private static final ObjectArrayList<Text> queue = new ObjectArrayList<>();
@Override
public void onEndTick(MinecraftClient client) {
if (client.player != null && !queue.isEmpty()){
client.player.sendMessage(queue.removeFirst());
}
}
public static void announce(Text text){
queue.add(text);
}
}
@@ -0,0 +1,25 @@
package de.shiewk.resourcepackprivacy.mixin;
import de.shiewk.resourcepackprivacy.event.ChatAnnouncer;
import net.minecraft.client.resource.server.ServerResourcePackLoader;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.awt.*;
import java.net.URL;
import java.util.UUID;
@Mixin(ServerResourcePackLoader.class)
public class MixinServerResourcePackLoader {
@Inject(at = @At("HEAD"), method = "addResourcePack(Ljava/util/UUID;Ljava/net/URL;Ljava/lang/String;)V")
public void onResourcePackAdd(UUID id, URL url, String hash, CallbackInfo ci){
ChatAnnouncer.announce(Text.translatable("gui.resourcepackprivacy.downloading",
Text.literal(url.toString()))
.withColor(Color.ORANGE.getRGB())
);
}
}
@@ -8,5 +8,6 @@
"gui.resourcepackprivacy.alwaysURLs": "Always accept these URLs",
"gui.resourcepackprivacy.alwaysHost": "Always accept packs from %s",
"gui.resourcepackprivacy.viewURL": "View download URL",
"gui.resourcepackprivacy.viewURLs": "View download URLs"
"gui.resourcepackprivacy.viewURLs": "View download URLs",
"gui.resourcepackprivacy.downloading": "Downloading server resource pack from %s"
}
@@ -8,7 +8,8 @@
"client": [
"AccessorConfirmServerResourcePackScreen",
"AccessorConfirmServerResourcePackScreenPack",
"MixinClientCommonNetworkHandler"
"MixinClientCommonNetworkHandler",
"MixinServerResourcePackLoader"
],
"injectors": {
"defaultRequire": 1