fix net handler leak (#130)

This commit is contained in:
Alexdoru authored and GitHub committed 2026-05-18 18:35:07 +02:00
1 parent 306aa90a28
commit 22d703da79
4 files changed
+26 -37

No files matched your search

@@ -65,6 +65,7 @@ import WayofTime.alchemicalWizardry.common.CommonProxy;
import WayofTime.alchemicalWizardry.common.LifeBucketHandler;
import WayofTime.alchemicalWizardry.common.LifeEssence;
import WayofTime.alchemicalWizardry.common.ModLivingDropsEvent;
import WayofTime.alchemicalWizardry.common.NewPacketHandler;
import WayofTime.alchemicalWizardry.common.achievements.ModAchievements;
import WayofTime.alchemicalWizardry.common.alchemy.CombinedPotionRegistry;
import WayofTime.alchemicalWizardry.common.block.ArmourForge;
@@ -689,6 +690,7 @@ public class AlchemicalWizardry {
HoldingPacketHandler.init();
ClientToServerPacketHandler.init();
ModAchievements.init();
NewPacketHandler.init();
}
/**
@@ -250,7 +250,6 @@ public class ClientProxy extends CommonProxy {
Object ob = new ClientEventHandler();
FMLCommonHandler.instance().bus().register(ob);
MinecraftForge.EVENT_BUS.register(ob);
KeyBindings.init();
MinecraftForge.EVENT_BUS.register(new ScrollHelper());
}
}
@@ -1,11 +0,0 @@
package WayofTime.alchemicalWizardry.client;
public class KeyBindings {
// public static KeyBinding omegaTest;
public static void init() {
// omegaTest = new KeyBinding("key.ping", Keyboard.KEY_O, "key.categories.alchemicalwizardry");
//
// ClientRegistry.registerKeyBinding(omegaTest);
}
}
@@ -60,10 +60,16 @@ public enum NewPacketHandler {
}
}
public static void init() {
// called on the client thread
// to avoid leaking the server thread
// if initialized on the server thread
}
@SideOnly(Side.CLIENT)
private void addClientHandler() {
FMLEmbeddedChannel clientChannel = this.channels.get(Side.CLIENT);
// spotless:off
String tileAltarCodec = clientChannel.findChannelHandlerNameForType(TEAltarCodec.class);
clientChannel.pipeline().addAfter(tileAltarCodec, "TEAltarHandler", new TEAltarMessageHandler());
clientChannel.pipeline().addAfter(tileAltarCodec, "TEOrientableHandler", new TEOrientableMessageHandler());
@@ -75,15 +81,12 @@ public enum NewPacketHandler {
clientChannel.pipeline().addAfter(tileAltarCodec, "ParticleHandler", new ParticleMessageHandler());
clientChannel.pipeline().addAfter(tileAltarCodec, "VelocityHandler", new VelocityMessageHandler());
clientChannel.pipeline().addAfter(tileAltarCodec, "TEMasterStoneHandler", new TEMasterStoneMessageHandler());
clientChannel.pipeline()
.addAfter(tileAltarCodec, "TEReagentConduitHandler", new TEReagentConduitMessageHandler());
clientChannel.pipeline().addAfter(tileAltarCodec, "TEReagentConduitHandler", new TEReagentConduitMessageHandler());
clientChannel.pipeline().addAfter(tileAltarCodec, "CurrentLPMessageHandler", new CurrentLPMessageHandler());
clientChannel.pipeline()
.addAfter(tileAltarCodec, "CurrentReagentBarMessageHandler", new CurrentReagentBarMessageHandler());
clientChannel.pipeline()
.addAfter(tileAltarCodec, "CurrentAddedHPMessageHandler", new CurrentAddedHPMessageHandler());
clientChannel.pipeline()
.addAfter(tileAltarCodec, "GaiaBiomeChangeHandler", new GaiaBiomeChangeMessageHandler());
clientChannel.pipeline().addAfter(tileAltarCodec, "CurrentReagentBarMessageHandler", new CurrentReagentBarMessageHandler());
clientChannel.pipeline().addAfter(tileAltarCodec, "CurrentAddedHPMessageHandler", new CurrentAddedHPMessageHandler());
clientChannel.pipeline().addAfter(tileAltarCodec, "GaiaBiomeChangeHandler", new GaiaBiomeChangeMessageHandler());
// spotless:on
}
@SideOnly(Side.SERVER)
@@ -997,37 +1000,33 @@ public enum NewPacketHandler {
return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg);
}
// spotless:off
public void sendTo(Packet message, EntityPlayerMP player) {
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.PLAYER);
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
this.channels.get(Side.SERVER).writeAndFlush(message);
this.channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
public void sendToAll(Packet message) {
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.ALL);
this.channels.get(Side.SERVER).writeAndFlush(message);
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
this.channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
public void sendToAllAround(Packet message, NetworkRegistry.TargetPoint point) {
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point);
this.channels.get(Side.SERVER).writeAndFlush(message);
this.channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
public void sendToDimension(Packet message, Integer dimensionId) {
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.DIMENSION);
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION);
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId);
this.channels.get(Side.SERVER).writeAndFlush(message);
this.channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
public void sendToServer(Packet message) {
this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.TOSERVER);
this.channels.get(Side.CLIENT).writeAndFlush(message)
.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER);
this.channels.get(Side.CLIENT).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
// spotless:on
}