Make GT packets process on the server/client thread instead of netty

This commit is contained in:
David Vierra 2017-01-22 19:42:17 -10:00
parent 721f417a7c
commit 210504462c

View file

@ -1,6 +1,8 @@
package gregtech.api.net; package gregtech.api.net;
import gregtech.GT_Mod; import gregtech.GT_Mod;
import net.minecraft.client.Minecraft;
import net.minecraft.util.IThreadListener;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
@ -33,11 +35,19 @@ public class GT_PacketHandler extends SimpleNetworkWrapper {
@Override @Override
public GT_Packet onMessage(GT_Packet message, MessageContext ctx) { public GT_Packet onMessage(GT_Packet message, MessageContext ctx) {
IThreadListener listener;
World world;
if(ctx.side == Side.SERVER) { if(ctx.side == Side.SERVER) {
message.process(ctx.getServerHandler().playerEntity.worldObj); world = ctx.getServerHandler().playerEntity.worldObj;
listener = world.getMinecraftServer();
} else { } else {
message.process(GT_Mod.gregtechproxy.getThePlayer().worldObj); world = GT_Mod.gregtechproxy.getThePlayer().worldObj;
listener = Minecraft.getMinecraft();
} }
listener.addScheduledTask(() -> {
message.process(world);
});
return null; return null;
} }
} }