diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index 834e3800..627b863c 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -65,9 +65,11 @@ import buildcraft.core.InterModComms; import buildcraft.core.Version; import buildcraft.core.blueprints.BptPlayerIndex; import buildcraft.core.blueprints.BptRootIndex; +import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.PacketHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.BCLog; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -92,6 +94,7 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; + import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.MinecraftForge; @@ -123,7 +126,7 @@ public class BuildCraftBuilders extends BuildCraftMod { @EventHandler public void init(FMLInitializationEvent evt) { channels = NetworkRegistry.INSTANCE.newChannel - (DefaultProps.NET_CHANNEL_NAME + "-BUILDERS", new PacketHandlerBuilders()); + (DefaultProps.NET_CHANNEL_NAME + "-BUILDERS", new BuildCraftChannelHandler(), new PacketHandlerBuilders()); // Register gui handler NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index ce33430a..f9c17ef2 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -26,6 +26,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.network.Packet; import net.minecraft.util.IIcon; import net.minecraft.world.World; + import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.IPlantable; @@ -34,6 +35,7 @@ import net.minecraftforge.common.config.Property; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.fluids.BlockFluidBase; import net.minecraftforge.fluids.IFluidBlock; + import buildcraft.api.core.BuildCraftAPI; import buildcraft.api.core.IIconProvider; import buildcraft.api.gates.ActionManager; @@ -56,6 +58,7 @@ import buildcraft.core.SpringPopulate; import buildcraft.core.TickHandlerCoreClient; import buildcraft.core.Version; import buildcraft.core.blueprints.BptItem; +import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.EntityIds; import buildcraft.core.network.PacketHandler; @@ -78,6 +81,7 @@ import buildcraft.core.utils.BCLog; import buildcraft.core.recipes.AssemblyRecipeManager; import buildcraft.core.recipes.IntegrationRecipeManager; import buildcraft.core.triggers.TriggerRedstoneInput; + import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; @@ -270,7 +274,7 @@ public class BuildCraftCore extends BuildCraftMod { @EventHandler public void initialize(FMLInitializationEvent evt) { 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 ffff0c0b..fc0bf6e3 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -20,6 +20,7 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.biome.BiomeGenBase; + import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.common.MinecraftForge; @@ -28,6 +29,7 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; + import buildcraft.api.fuels.IronEngineCoolant; import buildcraft.api.fuels.IronEngineFuel; import buildcraft.api.recipes.BuildcraftRecipes; @@ -36,6 +38,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.core.utils.BCLog; @@ -53,6 +56,7 @@ import buildcraft.energy.worldgen.BiomeGenOilOcean; import buildcraft.energy.worldgen.BiomeInitializer; import buildcraft.energy.worldgen.OilPopulate; import buildcraft.transport.network.PacketHandlerTransport; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -258,7 +262,7 @@ public class BuildCraftEnergy extends BuildCraftMod { @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 0069bcda..81441589 100644 --- a/common/buildcraft/BuildCraftFactory.java +++ b/common/buildcraft/BuildCraftFactory.java @@ -11,6 +11,7 @@ package buildcraft; import buildcraft.core.DefaultProps; import buildcraft.core.InterModComms; import buildcraft.core.Version; +import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.PacketHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.ConfigUtils; @@ -65,6 +66,7 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; + import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.ForgeChunkManager; @@ -161,7 +163,7 @@ public class BuildCraftFactory extends BuildCraftMod { @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 67f0857c..bf3db0f5 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -17,6 +17,7 @@ import buildcraft.core.InterModComms; import buildcraft.silicon.ItemRedstoneChipset; import buildcraft.silicon.ItemRedstoneChipset.Chipset; import buildcraft.core.Version; +import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.PacketHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.silicon.BlockLaser; @@ -37,6 +38,7 @@ import buildcraft.transport.gates.GateDefinition.GateLogic; import buildcraft.transport.gates.GateExpansionRedstoneFader; import buildcraft.transport.gates.GateExpansionTimer; import buildcraft.transport.gates.ItemGate; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -55,6 +57,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; + import net.minecraftforge.common.config.Property; @Mod(name = "BuildCraft Silicon", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Silicon", dependencies = DefaultProps.DEPENDENCY_TRANSPORT) @@ -90,7 +93,7 @@ public class BuildCraftSilicon extends BuildCraftMod { @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 06db5136..9e449e7d 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -18,6 +18,7 @@ import buildcraft.core.BuildCraftConfiguration; 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; @@ -86,6 +87,7 @@ import buildcraft.transport.triggers.TriggerPipeContents.PipeContents; import buildcraft.transport.triggers.TriggerPipeSignal; import buildcraft.transport.triggers.TriggerRedstoneFaderInput; import buildcraft.transport.triggers.ActionRedstoneFaderOutput; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -106,6 +108,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.world.World; + import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.config.Property; @@ -399,7 +402,7 @@ public class BuildCraftTransport extends BuildCraftMod { @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/builders/network/PacketHandlerBuilders.java b/common/buildcraft/builders/network/PacketHandlerBuilders.java index aff0bd54..abca5169 100644 --- a/common/buildcraft/builders/network/PacketHandlerBuilders.java +++ b/common/buildcraft/builders/network/PacketHandlerBuilders.java @@ -10,9 +10,13 @@ package buildcraft.builders.network; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.ChannelHandler.Sharable; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.INetHandler; import net.minecraft.tileentity.TileEntity; + import buildcraft.builders.TileArchitect; import buildcraft.builders.TileBlueprintLibrary; import buildcraft.core.network.BuildCraftChannelHandler; @@ -21,14 +25,14 @@ import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketPayloadArrays; import buildcraft.core.network.PacketUpdate; import buildcraft.core.proxy.CoreProxy; + import cpw.mods.fml.common.network.NetworkRegistry; -public class PacketHandlerBuilders extends BuildCraftChannelHandler { +@Sharable +public class PacketHandlerBuilders 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/core/network/PacketHandler.java b/common/buildcraft/core/network/PacketHandler.java index c38885d4..da714081 100644 --- a/common/buildcraft/core/network/PacketHandler.java +++ b/common/buildcraft/core/network/PacketHandler.java @@ -10,6 +10,8 @@ package buildcraft.core.network; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.ChannelHandler.Sharable; import java.io.IOException; @@ -17,10 +19,13 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.INetHandler; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; + import buildcraft.core.proxy.CoreProxy; + import cpw.mods.fml.common.network.NetworkRegistry; -public class PacketHandler extends BuildCraftChannelHandler { +@Sharable +public class PacketHandler extends SimpleChannelInboundHandler { private void onTileUpdate(EntityPlayer player, PacketTileUpdate packet) throws IOException { World world = player.worldObj; @@ -41,9 +46,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); @@ -63,7 +66,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; diff --git a/common/buildcraft/core/network/PacketTileState.java b/common/buildcraft/core/network/PacketTileState.java index 7fdca50c..9be5a4d1 100644 --- a/common/buildcraft/core/network/PacketTileState.java +++ b/common/buildcraft/core/network/PacketTileState.java @@ -8,16 +8,17 @@ */ package buildcraft.core.network; -import io.netty.buffer.ByteBuf; - -import java.io.DataInputStream; -import java.io.DataOutputStream; import java.io.IOException; 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; @@ -38,7 +39,7 @@ public class PacketTileState extends PacketCoordinates { /** * Constructor for outgoing packets - * + * * @param x * , y, z - the coordinates the tile to sync */ @@ -52,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); } } @@ -73,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 080841e8..fb8abb29 100644 --- a/common/buildcraft/factory/network/PacketHandlerFactory.java +++ b/common/buildcraft/factory/network/PacketHandlerFactory.java @@ -10,6 +10,8 @@ package buildcraft.factory.network; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.ChannelHandler.Sharable; import java.io.IOException; @@ -17,7 +19,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.INetHandler; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; + import net.minecraftforge.fluids.FluidRegistry; + import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.PacketIds; @@ -25,14 +29,14 @@ import buildcraft.core.network.PacketPayloadStream; import buildcraft.core.network.PacketUpdate; import buildcraft.core.proxy.CoreProxy; import buildcraft.factory.TileRefinery; + import cpw.mods.fml.common.network.NetworkRegistry; -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 ea0c2402..0b5565d8 100644 --- a/common/buildcraft/silicon/network/PacketHandlerSilicon.java +++ b/common/buildcraft/silicon/network/PacketHandlerSilicon.java @@ -10,11 +10,15 @@ package buildcraft.silicon.network; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.ChannelHandler.Sharable; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.network.INetHandler; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; + import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.PacketCoordinates; @@ -26,14 +30,14 @@ import buildcraft.silicon.TileAdvancedCraftingTable; import buildcraft.silicon.TileAssemblyTable; import buildcraft.silicon.TileAssemblyTable.SelectionMessage; import buildcraft.silicon.gui.ContainerAssemblyTable; + import cpw.mods.fml.common.network.NetworkRegistry; -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 d57945f7..02cf5612 100644 --- a/common/buildcraft/transport/network/PacketHandlerTransport.java +++ b/common/buildcraft/transport/network/PacketHandlerTransport.java @@ -10,11 +10,15 @@ package buildcraft.transport.network; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.ChannelHandler.Sharable; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.network.INetHandler; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; + import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.PacketCoordinates; @@ -28,9 +32,11 @@ import buildcraft.transport.TileGenericPipe; import buildcraft.transport.gui.ContainerGateInterface; import buildcraft.transport.pipes.PipeItemsDiamond; import buildcraft.transport.pipes.PipeItemsEmerald; + import cpw.mods.fml.common.network.NetworkRegistry; -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. @@ -39,8 +45,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);