aboutsummaryrefslogtreecommitdiff
path: root/versions/1.16.2-forge/src
diff options
context:
space:
mode:
Diffstat (limited to 'versions/1.16.2-forge/src')
-rw-r--r--versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/EventBusMixin.java (renamed from versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java)32
1 files changed, 19 insertions, 13 deletions
diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/EventBusMixin.java
index dc00be9..047a8dd 100644
--- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java
+++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/EventBusMixin.java
@@ -24,28 +24,34 @@
* <https://polyfrost.cc/legal/oneconfig/additional-terms>
*/
+//#if FORGE==1
package cc.polyfrost.oneconfig.internal.mixin;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.ChatReceiveEvent;
-import net.minecraft.client.network.play.ClientPlayNetHandler;
-import net.minecraft.network.play.server.SChatPacket;
+import net.minecraft.util.text.ChatType;
+import net.minecraftforge.client.event.ClientChatReceivedEvent;
+import net.minecraftforge.eventbus.EventBus;
+import net.minecraftforge.eventbus.api.Event;
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-@Mixin(value = ClientPlayNetHandler.class, priority = Integer.MAX_VALUE)
-public class NetHandlerPlayClientMixin {
+@Mixin(EventBus.class)
+public class EventBusMixin {
- @Inject(method = "handleChat", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;onClientChat(Lnet/minecraft/util/text/ChatType;Lnet/minecraft/util/text/ITextComponent;Ljava/util/UUID;)Lnet/minecraft/util/text/ITextComponent;", remap = false), cancellable = true, remap = true)
- private void onClientChat(SChatPacket packetIn, CallbackInfo ci) {
- if (packetIn.getType().getId() == 0) {
- ChatReceiveEvent event = new ChatReceiveEvent(packetIn.getChatComponent());
- EventManager.INSTANCE.post(event);
- if (event.isCancelled) {
- ci.cancel();
+ @Inject(method = "post", at = @At(value = "HEAD"), remap = false)
+ private void post(Event e, CallbackInfoReturnable<Boolean> cir) {
+ if(!(e instanceof ClientChatReceivedEvent)) return;
+ ClientChatReceivedEvent event = (ClientChatReceivedEvent) e;
+ if (event.getType() == ChatType.CHAT) {
+ ChatReceiveEvent customEvent = new ChatReceiveEvent(event.getMessage());
+ EventManager.INSTANCE.post(customEvent);
+ if (customEvent.isCancelled) {
+ e.setCanceled(true);
}
}
}
-} \ No newline at end of file
+}
+//#endif \ No newline at end of file