Integrate serverside transport packethandler into common and wipe server folder

This commit is contained in:
Krapht 2012-08-22 22:45:27 +02:00
parent 58b3ad5f24
commit dbb04486c3
2 changed files with 117 additions and 149 deletions

View file

@ -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);
}
}

View file

@ -3,12 +3,18 @@ package buildcraft.transport.network;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import cpw.mods.fml.common.network.IPacketHandler; import net.minecraft.src.Container;
import cpw.mods.fml.common.network.Player; 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.PacketIds;
import buildcraft.core.network.PacketNBT; import buildcraft.core.network.PacketNBT;
import buildcraft.core.network.PacketPipeTransportContent; import buildcraft.core.network.PacketPipeTransportContent;
import buildcraft.core.network.PacketSlotChange;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.transport.PipeLogicDiamond; import buildcraft.transport.PipeLogicDiamond;
import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportItems;
@ -16,16 +22,8 @@ import buildcraft.transport.PipeTransportLiquids;
import buildcraft.transport.PipeTransportPower; import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.gui.ContainerGateInterface; import buildcraft.transport.gui.ContainerGateInterface;
import buildcraft.transport.network.PacketLiquidUpdate; import cpw.mods.fml.common.network.IPacketHandler;
import buildcraft.transport.network.PacketPowerUpdate; import cpw.mods.fml.common.network.Player;
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;
public class PacketHandlerTransport implements IPacketHandler { public class PacketHandlerTransport implements IPacketHandler {
@ -76,7 +74,34 @@ public class PacketHandlerTransport implements IPacketHandler {
packet.readData(data); packet.readData(data);
onGateSelection(packet); onGateSelection(packet);
break; 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) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -256,5 +281,84 @@ public class PacketHandlerTransport implements IPacketHandler {
BuildCraftCore.bufferedDescriptions.put(index, packet); 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);
}
} }