From dbb04486c3d1877ad664dcf888f9e99e3a5241ec Mon Sep 17 00:00:00 2001 From: Krapht Date: Wed, 22 Aug 2012 22:45:27 +0200 Subject: [PATCH] Integrate serverside transport packethandler into common and wipe server folder --- .../transport/network/PacketHandler.java | 136 ------------------ .../network/PacketHandlerTransport.java | 130 +++++++++++++++-- 2 files changed, 117 insertions(+), 149 deletions(-) delete mode 100644 buildcraft_server/buildcraft/transport/network/PacketHandler.java diff --git a/buildcraft_server/buildcraft/transport/network/PacketHandler.java b/buildcraft_server/buildcraft/transport/network/PacketHandler.java deleted file mode 100644 index 8b87ae07..00000000 --- a/buildcraft_server/buildcraft/transport/network/PacketHandler.java +++ /dev/null @@ -1,136 +0,0 @@ -package buildcraft.transport.network; - -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; - -import buildcraft.core.network.PacketCoordinates; -import buildcraft.core.network.PacketIds; -import buildcraft.core.network.PacketSlotChange; -import buildcraft.core.network.PacketUpdate; -import buildcraft.transport.CraftingGateInterface; -import buildcraft.transport.PipeLogicDiamond; -import buildcraft.transport.TileGenericPipe; - -import net.minecraft.src.EntityPlayerMP; -import net.minecraft.src.NetServerHandler; -import net.minecraft.src.NetworkManager; -import net.minecraft.src.TileEntity; -import net.minecraft.src.World; -import net.minecraft.src.forge.IPacketHandler; - -public class PacketHandler implements IPacketHandler { - - @Override - public void onPacketData(NetworkManager network, String channel, byte[] bytes) { - DataInputStream data = new DataInputStream(new ByteArrayInputStream(bytes)); - try { - NetServerHandler net = (NetServerHandler) network.getNetHandler(); - int packetID = data.read(); - switch (packetID) { - - case PacketIds.DIAMOND_PIPE_SELECT: - PacketSlotChange packet = new PacketSlotChange(); - packet.readData(data); - onDiamondPipeSelect(net.getPlayerEntity(), packet); - break; - - case PacketIds.GATE_REQUEST_INIT: - PacketCoordinates packetU = new PacketCoordinates(); - packetU.readData(data); - onGateInitRequest(net.getPlayerEntity(), packetU); - break; - - case PacketIds.GATE_REQUEST_SELECTION: - PacketCoordinates packetS = new PacketCoordinates(); - packetS.readData(data); - onGateSelectionRequest(net.getPlayerEntity(), packetS); - break; - - case PacketIds.GATE_SELECTION_CHANGE: - PacketUpdate packetC = new PacketUpdate(); - packetC.readData(data); - onGateSelectionChange(net.getPlayerEntity(), packetC); - break; - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - /** - * Handles selection changes on a gate. - * - * @param playerEntity - * @param packet - */ - private void onGateSelectionChange(EntityPlayerMP playerEntity, PacketUpdate packet) { - if (!(playerEntity.craftingInventory instanceof CraftingGateInterface)) - return; - - ((CraftingGateInterface) playerEntity.craftingInventory).handleSelectionChange(packet); - } - - /** - * Handles gate gui (current) selection requests. - * - * @param playerEntity - * @param packet - */ - private void onGateSelectionRequest(EntityPlayerMP playerEntity, PacketCoordinates packet) { - if (!(playerEntity.craftingInventory instanceof CraftingGateInterface)) - return; - - ((CraftingGateInterface) playerEntity.craftingInventory).sendSelection(playerEntity); - } - - /** - * Handles received gate gui initialization requests. - * - * @param playerEntity - * @param packet - */ - private void onGateInitRequest(EntityPlayerMP playerEntity, PacketCoordinates packet) { - if (!(playerEntity.craftingInventory instanceof CraftingGateInterface)) - return; - - ((CraftingGateInterface) playerEntity.craftingInventory).handleInitRequest(playerEntity); - } - - /** - * Retrieves pipe at specified coordinates if any. - * - * @param world - * @param x - * @param y - * @param z - * @return - */ - private TileGenericPipe getPipe(World world, int x, int y, int z) { - if (!world.blockExists(x, y, z)) - return null; - - TileEntity tile = world.getBlockTileEntity(x, y, z); - if (!(tile instanceof TileGenericPipe)) - return null; - - return (TileGenericPipe) tile; - } - - /** - * Handles selection changes on diamond pipe guis. - * - * @param player - * @param packet - */ - private void onDiamondPipeSelect(EntityPlayerMP player, PacketSlotChange packet) { - TileGenericPipe pipe = getPipe(player.worldObj, packet.posX, packet.posY, packet.posZ); - if (pipe == null) - return; - - if (!(pipe.pipe.logic instanceof PipeLogicDiamond)) - return; - - ((PipeLogicDiamond)pipe.pipe.logic).setInventorySlotContents(packet.slot, packet.stack); - } - -} diff --git a/common/buildcraft/transport/network/PacketHandlerTransport.java b/common/buildcraft/transport/network/PacketHandlerTransport.java index d8490bc3..df22453a 100644 --- a/common/buildcraft/transport/network/PacketHandlerTransport.java +++ b/common/buildcraft/transport/network/PacketHandlerTransport.java @@ -3,12 +3,18 @@ package buildcraft.transport.network; import java.io.ByteArrayInputStream; import java.io.DataInputStream; -import cpw.mods.fml.common.network.IPacketHandler; -import cpw.mods.fml.common.network.Player; - +import net.minecraft.src.Container; +import net.minecraft.src.EntityPlayerMP; +import net.minecraft.src.ModLoader; +import net.minecraft.src.NetworkManager; +import net.minecraft.src.Packet250CustomPayload; +import net.minecraft.src.TileEntity; +import net.minecraft.src.World; +import buildcraft.core.network.PacketCoordinates; import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketNBT; import buildcraft.core.network.PacketPipeTransportContent; +import buildcraft.core.network.PacketSlotChange; import buildcraft.core.network.PacketUpdate; import buildcraft.transport.PipeLogicDiamond; import buildcraft.transport.PipeTransportItems; @@ -16,16 +22,8 @@ import buildcraft.transport.PipeTransportLiquids; import buildcraft.transport.PipeTransportPower; import buildcraft.transport.TileGenericPipe; import buildcraft.transport.gui.ContainerGateInterface; -import buildcraft.transport.network.PacketLiquidUpdate; -import buildcraft.transport.network.PacketPowerUpdate; -import buildcraft.transport.network.PipeRenderStatePacket; - -import net.minecraft.src.Container; -import net.minecraft.src.ModLoader; -import net.minecraft.src.NetworkManager; -import net.minecraft.src.Packet250CustomPayload; -import net.minecraft.src.TileEntity; -import net.minecraft.src.World; +import cpw.mods.fml.common.network.IPacketHandler; +import cpw.mods.fml.common.network.Player; public class PacketHandlerTransport implements IPacketHandler { @@ -76,7 +74,34 @@ public class PacketHandlerTransport implements IPacketHandler { packet.readData(data); onGateSelection(packet); break; + + /** SERVER SIDE **/ + case PacketIds.DIAMOND_PIPE_SELECT: + PacketSlotChange packet1 = new PacketSlotChange(); + packet1.readData(data); + onDiamondPipeSelect((EntityPlayerMP) player, packet1); + break; + + case PacketIds.GATE_REQUEST_INIT: + PacketCoordinates packetU = new PacketCoordinates(); + packetU.readData(data); + onGateInitRequest((EntityPlayerMP) player, packetU); + break; + + case PacketIds.GATE_REQUEST_SELECTION: + PacketCoordinates packetS = new PacketCoordinates(); + packetS.readData(data); + onGateSelectionRequest((EntityPlayerMP) player, packetS); + break; + + case PacketIds.GATE_SELECTION_CHANGE: + PacketUpdate packet3 = new PacketUpdate(); + packet3.readData(data); + onGateSelectionChange((EntityPlayerMP) player, packet3); + break; } + + } catch (Exception ex) { ex.printStackTrace(); @@ -256,5 +281,84 @@ public class PacketHandlerTransport implements IPacketHandler { BuildCraftCore.bufferedDescriptions.put(index, packet); */ } + + /******************** SERVER ******************** **/ + + /** + * Handles selection changes on a gate. + * + * @param playerEntity + * @param packet + */ + private void onGateSelectionChange(EntityPlayerMP playerEntity, PacketUpdate packet) { + if (!(playerEntity.craftingInventory instanceof ContainerGateInterface)) + return; + + ((ContainerGateInterface) playerEntity.craftingInventory).handleSelectionChange(packet); + } + + /** + * Handles gate gui (current) selection requests. + * + * @param playerEntity + * @param packet + */ + private void onGateSelectionRequest(EntityPlayerMP playerEntity, PacketCoordinates packet) { + if (!(playerEntity.craftingInventory instanceof ContainerGateInterface)) + return; + + ((ContainerGateInterface) playerEntity.craftingInventory).sendSelection(playerEntity); + } + + /** + * Handles received gate gui initialization requests. + * + * @param playerEntity + * @param packet + */ + private void onGateInitRequest(EntityPlayerMP playerEntity, PacketCoordinates packet) { + if (!(playerEntity.craftingInventory instanceof ContainerGateInterface)) + return; + + ((ContainerGateInterface) playerEntity.craftingInventory).handleInitRequest(playerEntity); + } + + /** + * Retrieves pipe at specified coordinates if any. + * + * @param world + * @param x + * @param y + * @param z + * @return + */ + private TileGenericPipe getPipe(World world, int x, int y, int z) { + if (!world.blockExists(x, y, z)) + return null; + + TileEntity tile = world.getBlockTileEntity(x, y, z); + if (!(tile instanceof TileGenericPipe)) + return null; + + return (TileGenericPipe) tile; + } + + /** + * Handles selection changes on diamond pipe guis. + * + * @param player + * @param packet + */ + private void onDiamondPipeSelect(EntityPlayerMP player, PacketSlotChange packet) { + TileGenericPipe pipe = getPipe(player.worldObj, packet.posX, packet.posY, packet.posZ); + if (pipe == null) + return; + + if (!(pipe.pipe.logic instanceof PipeLogicDiamond)) + return; + + ((PipeLogicDiamond)pipe.pipe.logic).setInventorySlotContents(packet.slot, packet.stack); + } + }