diff --git a/src/main/java/de/shiewk/resourcepackprivacy/client/ResourcePackPrivacyClient.java b/src/main/java/de/shiewk/resourcepackprivacy/client/ResourcePackPrivacyClient.java index 6636640..5861802 100644 --- a/src/main/java/de/shiewk/resourcepackprivacy/client/ResourcePackPrivacyClient.java +++ b/src/main/java/de/shiewk/resourcepackprivacy/client/ResourcePackPrivacyClient.java @@ -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()); } } diff --git a/src/main/java/de/shiewk/resourcepackprivacy/event/ChatAnnouncer.java b/src/main/java/de/shiewk/resourcepackprivacy/event/ChatAnnouncer.java new file mode 100644 index 0000000..951df75 --- /dev/null +++ b/src/main/java/de/shiewk/resourcepackprivacy/event/ChatAnnouncer.java @@ -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 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); + } +} diff --git a/src/main/java/de/shiewk/resourcepackprivacy/mixin/MixinServerResourcePackLoader.java b/src/main/java/de/shiewk/resourcepackprivacy/mixin/MixinServerResourcePackLoader.java new file mode 100644 index 0000000..855508c --- /dev/null +++ b/src/main/java/de/shiewk/resourcepackprivacy/mixin/MixinServerResourcePackLoader.java @@ -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()) + ); + } +} diff --git a/src/main/resources/assets/resourcepackprivacy/lang/en_us.json b/src/main/resources/assets/resourcepackprivacy/lang/en_us.json index 50e5240..047f7e6 100644 --- a/src/main/resources/assets/resourcepackprivacy/lang/en_us.json +++ b/src/main/resources/assets/resourcepackprivacy/lang/en_us.json @@ -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" } \ No newline at end of file diff --git a/src/main/resources/resourcepackprivacy.mixins.json b/src/main/resources/resourcepackprivacy.mixins.json index 66f692d..5a8247c 100644 --- a/src/main/resources/resourcepackprivacy.mixins.json +++ b/src/main/resources/resourcepackprivacy.mixins.json @@ -8,7 +8,8 @@ "client": [ "AccessorConfirmServerResourcePackScreen", "AccessorConfirmServerResourcePackScreenPack", - "MixinClientCommonNetworkHandler" + "MixinClientCommonNetworkHandler", + "MixinServerResourcePackLoader" ], "injectors": { "defaultRequire": 1