aboutsummaryrefslogtreecommitdiff
path: root/versions/src/main/java/cc/polyfrost/oneconfig
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-08-19 19:23:39 +0200
committerGitHub <noreply@github.com>2022-08-20 00:23:39 +0700
commit87e7c92526ac894525079305932de80f20372679 (patch)
treee61325d1fe416b1857685d5162bc0a4ac83f8664 /versions/src/main/java/cc/polyfrost/oneconfig
parentb6a4394db3dd58f6eea0d45b4e5f6630fc67a328 (diff)
downloadOneConfig-87e7c92526ac894525079305932de80f20372679.tar.gz
OneConfig-87e7c92526ac894525079305932de80f20372679.tar.bz2
OneConfig-87e7c92526ac894525079305932de80f20372679.zip
integrate with forge chat event (#106)
Diffstat (limited to 'versions/src/main/java/cc/polyfrost/oneconfig')
-rw-r--r--versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/EventBusMixin.java (renamed from versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java)29
-rw-r--r--versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java10
2 files changed, 22 insertions, 17 deletions
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/EventBusMixin.java
index d8a6691..231a861 100644
--- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java
+++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/EventBusMixin.java
@@ -29,25 +29,26 @@ package cc.polyfrost.oneconfig.internal.mixin;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.ChatReceiveEvent;
-import cc.polyfrost.oneconfig.events.event.SendPacketEvent;
-import net.minecraft.client.network.NetHandlerPlayClient;
-import net.minecraft.network.Packet;
-import net.minecraft.network.play.server.S02PacketChat;
+import net.minecraftforge.client.event.ClientChatReceivedEvent;
+import net.minecraftforge.fml.common.eventhandler.Event;
+import net.minecraftforge.fml.common.eventhandler.EventBus;
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 = NetHandlerPlayClient.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(BLnet/minecraft/util/IChatComponent;)Lnet/minecraft/util/IChatComponent;", remap = false), cancellable = true, remap = true)
- private void onClientChat(S02PacketChat packetIn, CallbackInfo ci) {
- if (packetIn.getType() == 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.type == 0) {
+ ChatReceiveEvent customEvent = new ChatReceiveEvent(event.message);
+ EventManager.INSTANCE.post(customEvent);
+ if (customEvent.isCancelled) {
+ e.setCanceled(true);
}
}
}
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java
index e272932..e242e2f 100644
--- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java
+++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java
@@ -67,8 +67,13 @@ public class OneConfigMixinPlugin implements IMixinConfigPlugin {
@Override
public List<String> getMixins() {
+ ArrayList<String> mixins = new ArrayList<>();
+ if (Platform.getInstance().getLoader().equals(Platform.Loader.FORGE)) {
+ mixins.add("EventBusMixin");
+ } else if (Platform.getInstance().getLoader().equals(Platform.Loader.FABRIC)) {
+ mixins.add("NetHandlerPlayClientMixin");
+ }
if (Platform.getInstance().getMinecraftVersion() >= 11600) {
- ArrayList<String> mixins = new ArrayList<>();
if (Platform.getInstance().getLoader() == Platform.Loader.FORGE) {
mixins.add("ClientModLoaderMixin");
} else {
@@ -80,9 +85,8 @@ public class OneConfigMixinPlugin implements IMixinConfigPlugin {
mixins.add("MouseMixin");
mixins.add("TickTimeTrackerMixin");
return mixins;
- } else {
- return null;
}
+ return mixins.isEmpty() ? null : mixins;
}
@Override