diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index 4c7de2d7..574cca29 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -76,6 +76,7 @@ import buildcraft.core.ItemWrench; import buildcraft.core.SpringPopulate; import buildcraft.core.TickHandlerCoreClient; import buildcraft.core.Version; +import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.EntityIds; import buildcraft.core.network.PacketHandler; import buildcraft.core.network.PacketUpdate; @@ -298,7 +299,7 @@ public class BuildCraftCore extends BuildCraftMod { BuildCraftAPI.proxy = CoreProxy.proxy; channels = NetworkRegistry.INSTANCE.newChannel - (DefaultProps.NET_CHANNEL_NAME + "-CORE", new PacketHandler()); + (DefaultProps.NET_CHANNEL_NAME + "-CORE", new BuildCraftChannelHandler(), new PacketHandler()); ActionManager.registerTriggerProvider(new DefaultTriggerProvider()); ActionManager.registerActionProvider(new DefaultActionProvider()); diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index dfdc3060..ee49912f 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -52,6 +52,7 @@ import buildcraft.core.BlockSpring; import buildcraft.core.DefaultProps; import buildcraft.core.InterModComms; import buildcraft.core.Version; +import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.triggers.BCTrigger; import buildcraft.energy.BlockBuildcraftFluid; @@ -328,7 +329,7 @@ public class BuildCraftEnergy extends BuildCraftMod { @Mod.EventHandler public void init(FMLInitializationEvent evt) { channels = NetworkRegistry.INSTANCE.newChannel - (DefaultProps.NET_CHANNEL_NAME + "-ENERGY", new PacketHandlerTransport()); + (DefaultProps.NET_CHANNEL_NAME + "-ENERGY", new BuildCraftChannelHandler(), new PacketHandlerTransport()); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); diff --git a/common/buildcraft/BuildCraftFactory.java b/common/buildcraft/BuildCraftFactory.java index ccff599a..cdddae55 100644 --- a/common/buildcraft/BuildCraftFactory.java +++ b/common/buildcraft/BuildCraftFactory.java @@ -41,6 +41,7 @@ import buildcraft.builders.schematics.SchematicIgnoreMeta; import buildcraft.core.DefaultProps; import buildcraft.core.InterModComms; import buildcraft.core.Version; +import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.ConfigUtils; import buildcraft.factory.BlockAutoWorkbench; @@ -161,7 +162,7 @@ public class BuildCraftFactory extends BuildCraftMod { @Mod.EventHandler public void initialize(FMLPreInitializationEvent evt) { channels = NetworkRegistry.INSTANCE.newChannel - (DefaultProps.NET_CHANNEL_NAME + "-FACTORY", new PacketHandlerFactory()); + (DefaultProps.NET_CHANNEL_NAME + "-FACTORY", new BuildCraftChannelHandler(), new PacketHandlerFactory()); ConfigUtils genCat = new ConfigUtils(BuildCraftCore.mainConfiguration, Configuration.CATEGORY_GENERAL); diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index 9a270bbd..cf25f20d 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -35,6 +35,7 @@ import buildcraft.core.InterModComms; import buildcraft.core.ItemBuildCraft; import buildcraft.core.ItemRobot; import buildcraft.core.Version; +import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.robots.RobotIntegrationRecipe; import buildcraft.core.robots.boards.BoardRobotPickerNBT; @@ -113,7 +114,7 @@ public class BuildCraftSilicon extends BuildCraftMod { @Mod.EventHandler public void init(FMLInitializationEvent evt) { channels = NetworkRegistry.INSTANCE.newChannel - (DefaultProps.NET_CHANNEL_NAME + "-SILICON", new PacketHandlerSilicon()); + (DefaultProps.NET_CHANNEL_NAME + "-SILICON", new BuildCraftChannelHandler(), new PacketHandlerSilicon()); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); CoreProxy.proxy.registerTileEntity(TileLaser.class, "net.minecraft.src.buildcraft.factory.TileLaser"); diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 31f43dec..97211936 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -46,6 +46,7 @@ import buildcraft.core.DefaultProps; import buildcraft.core.InterModComms; import buildcraft.core.ItemBuildCraft; import buildcraft.core.Version; +import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.triggers.BCAction; import buildcraft.core.triggers.BCTrigger; @@ -419,7 +420,7 @@ public class BuildCraftTransport extends BuildCraftMod { @Mod.EventHandler public void init(FMLInitializationEvent evt) { channels = NetworkRegistry.INSTANCE.newChannel - (DefaultProps.NET_CHANNEL_NAME + "-TRANSPORT", new PacketHandlerTransport()); + (DefaultProps.NET_CHANNEL_NAME + "-TRANSPORT", new BuildCraftChannelHandler(), new PacketHandlerTransport()); // Register connection handler // MinecraftForge.registerConnectionHandler(new ConnectionHandler()); diff --git a/common/buildcraft/core/network/PacketHandler.java b/common/buildcraft/core/network/PacketHandler.java index 5be1c8bb..b64d35ae 100644 --- a/common/buildcraft/core/network/PacketHandler.java +++ b/common/buildcraft/core/network/PacketHandler.java @@ -10,8 +10,9 @@ package buildcraft.core.network; import java.io.IOException; -import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.INetHandler; @@ -20,13 +21,10 @@ import net.minecraft.world.World; import cpw.mods.fml.common.network.NetworkRegistry; -import net.minecraftforge.common.DimensionManager; - import buildcraft.core.proxy.CoreProxy; -import buildcraft.transport.TileGenericPipe; - -public class PacketHandler extends BuildCraftChannelHandler { +@Sharable +public class PacketHandler extends SimpleChannelInboundHandler { private void onTileUpdate(EntityPlayer player, PacketTileUpdate packet) throws IOException { World world = player.worldObj; @@ -46,10 +44,7 @@ public class PacketHandler extends BuildCraftChannelHandler { } @Override - - public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) { - super.decodeInto(ctx, data, packet); - + protected void channelRead0(ChannelHandlerContext ctx, BuildCraftPacket packet) { try { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler); @@ -69,7 +64,7 @@ public class PacketHandler extends BuildCraftChannelHandler { TileEntity tile = world.getTileEntity(pkt.posX, pkt.posY, pkt.posZ); if (tile instanceof ISyncedTile) { - pkt.applyStates(data, (ISyncedTile) tile); + pkt.applyStates((ISyncedTile) tile); } break; @@ -92,36 +87,32 @@ public class PacketHandler extends BuildCraftChannelHandler { } case PacketIds.RPC_PIPE: { - PacketRPCPipe rpc = new PacketRPCPipe(); - rpc.sender = player; + // TODO: RPC pipes are not used right now. Ressurect this + // code if needed later. + /* + * PacketRPCPipe rpc = new PacketRPCPipe(); rpc.sender = player; + * + * int dimId = data.readShort(); World world = null; + * + * if (!rpc.sender.worldObj.isRemote) { // if this is a server, + * then get the world + * + * world = DimensionManager.getProvider(dimId).worldObj; } else + * if (rpc.sender.worldObj.provider.dimensionId == dimId) { // + * if the player is on this world, then synchronize things + * + * world = rpc.sender.worldObj; } + * + * if (world != null) { int x = data.readInt(); int y = + * data.readInt(); int z = data.readInt(); + * + * TileEntity tile = world.getTileEntity(x, y, z); + * + * if (tile instanceof TileGenericPipe) { rpc.setPipe + * (((TileGenericPipe) tile).pipe); rpc.readData(data); } } + */ + break; - int dimId = data.readShort(); - World world = null; - - if (!rpc.sender.worldObj.isRemote) { - // if this is a server, then get the world - - world = DimensionManager.getProvider(dimId).worldObj; - } else if (rpc.sender.worldObj.provider.dimensionId == dimId) { - // if the player is on this world, then synchronize things - - world = rpc.sender.worldObj; - } - - if (world != null) { - int x = data.readInt(); - int y = data.readInt(); - int z = data.readInt(); - - TileEntity tile = world.getTileEntity(x, y, z); - - if (tile instanceof TileGenericPipe) { - rpc.setPipe (((TileGenericPipe) tile).pipe); - rpc.readData(data); - } - } - - break; } } } catch (Exception ex) { diff --git a/common/buildcraft/core/network/PacketRPCPipe.java b/common/buildcraft/core/network/PacketRPCPipe.java index 2b9ad0eb..7cb35bc5 100755 --- a/common/buildcraft/core/network/PacketRPCPipe.java +++ b/common/buildcraft/core/network/PacketRPCPipe.java @@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayer; import buildcraft.transport.Pipe; +// TODO: This is not yet used public class PacketRPCPipe extends BuildCraftPacket { public Pipe pipe; diff --git a/common/buildcraft/core/network/PacketTileState.java b/common/buildcraft/core/network/PacketTileState.java index 67acb1b4..9be5a4d1 100644 --- a/common/buildcraft/core/network/PacketTileState.java +++ b/common/buildcraft/core/network/PacketTileState.java @@ -13,9 +13,12 @@ import java.util.LinkedList; import java.util.List; import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; public class PacketTileState extends PacketCoordinates { + private ByteBuf state; + private class StateWithId { public byte stateId; public IClientState state; @@ -36,7 +39,7 @@ public class PacketTileState extends PacketCoordinates { /** * Constructor for outgoing packets - * + * * @param x * , y, z - the coordinates the tile to sync */ @@ -50,16 +53,11 @@ public class PacketTileState extends PacketCoordinates { return PacketIds.STATE_UPDATE; } - @Override - public void readData(ByteBuf data) { - super.readData(data); - } - - public void applyStates(ByteBuf data, ISyncedTile tile) throws IOException { - byte stateCount = data.readByte(); + public void applyStates(ISyncedTile tile) throws IOException { + byte stateCount = state.readByte(); for (int i = 0; i < stateCount; i++) { - byte stateId = data.readByte(); - tile.getStateInstance(stateId).readData(data); + byte stateId = state.readByte(); + tile.getStateInstance(stateId).readData(state); tile.afterStateUpdated(stateId); } } @@ -71,10 +69,25 @@ public class PacketTileState extends PacketCoordinates { @Override public void writeData(ByteBuf data) { super.writeData(data); - data.writeByte(stateList.size()); + + ByteBuf tmpState = Unpooled.buffer(); + + tmpState.writeByte(stateList.size()); for (StateWithId stateWithId : stateList) { - data.writeByte(stateWithId.stateId); - stateWithId.state.writeData(data); + tmpState.writeByte(stateWithId.stateId); + stateWithId.state.writeData(tmpState); } + + data.writeInt(tmpState.readableBytes()); + data.writeBytes(tmpState.readBytes(tmpState.readableBytes())); + } + + @Override + public void readData(ByteBuf data) { + super.readData(data); + + state = Unpooled.buffer(); + int length = data.readInt(); + state.writeBytes(data.readBytes(length)); } } diff --git a/common/buildcraft/factory/network/PacketHandlerFactory.java b/common/buildcraft/factory/network/PacketHandlerFactory.java index 328e3c3a..3d59babf 100644 --- a/common/buildcraft/factory/network/PacketHandlerFactory.java +++ b/common/buildcraft/factory/network/PacketHandlerFactory.java @@ -11,7 +11,9 @@ package buildcraft.factory.network; import java.io.IOException; import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.INetHandler; @@ -22,19 +24,17 @@ import cpw.mods.fml.common.network.NetworkRegistry; import net.minecraftforge.fluids.FluidRegistry; -import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketUpdate; import buildcraft.core.proxy.CoreProxy; import buildcraft.factory.TileRefinery; -public class PacketHandlerFactory extends BuildCraftChannelHandler { +@Sharable +public class PacketHandlerFactory extends SimpleChannelInboundHandler { @Override - public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) { - super.decodeInto(ctx, data, packet); - + protected void channelRead0(ChannelHandlerContext ctx, BuildCraftPacket packet) { try { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler); diff --git a/common/buildcraft/silicon/network/PacketHandlerSilicon.java b/common/buildcraft/silicon/network/PacketHandlerSilicon.java index d04377ec..e7a1a068 100644 --- a/common/buildcraft/silicon/network/PacketHandlerSilicon.java +++ b/common/buildcraft/silicon/network/PacketHandlerSilicon.java @@ -8,8 +8,9 @@ */ package buildcraft.silicon.network; -import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; @@ -19,7 +20,6 @@ import net.minecraft.world.World; import cpw.mods.fml.common.network.NetworkRegistry; -import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.PacketCoordinates; import buildcraft.core.network.PacketIds; @@ -31,12 +31,11 @@ import buildcraft.silicon.TileAssemblyTable; import buildcraft.silicon.TileAssemblyTable.SelectionMessage; import buildcraft.silicon.gui.ContainerAssemblyTable; -public class PacketHandlerSilicon extends BuildCraftChannelHandler { +@Sharable +public class PacketHandlerSilicon extends SimpleChannelInboundHandler { @Override - public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) { - super.decodeInto(ctx, data, packet); - + protected void channelRead0(ChannelHandlerContext ctx, BuildCraftPacket packet) { try { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); diff --git a/common/buildcraft/transport/network/PacketHandlerTransport.java b/common/buildcraft/transport/network/PacketHandlerTransport.java index add654ba..dc283c55 100644 --- a/common/buildcraft/transport/network/PacketHandlerTransport.java +++ b/common/buildcraft/transport/network/PacketHandlerTransport.java @@ -8,8 +8,9 @@ */ package buildcraft.transport.network; -import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; @@ -19,7 +20,6 @@ import net.minecraft.world.World; import cpw.mods.fml.common.network.NetworkRegistry; -import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.PacketCoordinates; import buildcraft.core.network.PacketIds; @@ -33,7 +33,8 @@ import buildcraft.transport.gui.ContainerGateInterface; import buildcraft.transport.pipes.PipeItemsDiamond; import buildcraft.transport.pipes.PipeItemsEmerald; -public class PacketHandlerTransport extends BuildCraftChannelHandler { +@Sharable +public class PacketHandlerTransport extends SimpleChannelInboundHandler { /** * TODO: A lot of this is based on the player to retrieve the world. @@ -42,8 +43,7 @@ public class PacketHandlerTransport extends BuildCraftChannelHandler { * RPCs. */ @Override - public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) { - super.decodeInto(ctx, data, packet); + protected void channelRead0(ChannelHandlerContext ctx, BuildCraftPacket packet) { try { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler);