use of powercrystals.minefactoryreloaded.tile.machine.TileEntityItemRouter in project MineFactoryReloaded by powercrystals.
the class ServerPacketHandler method onPacketData.
@SuppressWarnings("rawtypes")
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
int packetType = PacketWrapper.readPacketID(data);
if (// client -> server: autoenchanter GUI buttons
packetType == Packets.EnchanterButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityAutoEnchanter) {
((TileEntityAutoEnchanter) te).setTargetLevel(((TileEntityAutoEnchanter) te).getTargetLevel() + (Integer) packetReadout[3]);
} else if (te instanceof TileEntityBlockSmasher) {
((TileEntityBlockSmasher) te).setFortune(((TileEntityBlockSmasher) te).getFortune() + (Integer) packetReadout[3]);
} else if (te instanceof TileEntityAutoDisenchanter) {
Integer v = (Integer) packetReadout[3];
((TileEntityAutoDisenchanter) te).setRepeatDisenchant(v == 1 ? true : false);
}
} else if (// client -> server: harvester setting
packetType == Packets.HarvesterButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, String.class, Boolean.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityHarvester) {
((TileEntityHarvester) te).getSettings().put((String) packetReadout[3], (Boolean) packetReadout[4]);
}
} else if (// client -> server: toggle chronotyper
packetType == Packets.ChronotyperButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityChronotyper) {
((TileEntityChronotyper) te).setMoveOld(!((TileEntityChronotyper) te).getMoveOld());
}
} else if (// client -> server: toggle DSU output side
packetType == Packets.DSUButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityDeepStorageUnit) {
int side = (Integer) packetReadout[3];
((TileEntityDeepStorageUnit) te).setSideIsOutput(side, (!((TileEntityDeepStorageUnit) te).getIsSideOutput(side)));
}
} else if (// client -> server: copy record
packetType == Packets.AutoJukeboxButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityAutoJukebox) {
TileEntityAutoJukebox j = ((TileEntityAutoJukebox) te);
int button = (Integer) packetReadout[3];
if (button == 1)
j.playRecord();
else if (button == 2)
j.stopRecord();
else if (button == 3)
j.copyRecord();
}
} else if (// client -> server: toggle autospawner
packetType == Packets.AutoSpawnerButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityAutoSpawner) {
((TileEntityAutoSpawner) te).setSpawnExact(!((TileEntityAutoSpawner) te).getSpawnExact());
}
} else if (// client -> server: request circuit from server
packetType == Packets.LogicRequestCircuitDefinition) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
((TileEntityRedNetLogic) te).sendCircuitDefinition((Integer) packetReadout[3]);
}
} else if (// client -> server: set circuit
packetType == Packets.LogicSetCircuit) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, String.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
((TileEntityRedNetLogic) te).initCircuit((Integer) packetReadout[3], (String) packetReadout[4]);
((TileEntityRedNetLogic) te).sendCircuitDefinition((Integer) packetReadout[3]);
}
} else if (// client -> server: set pin
packetType == Packets.LogicSetPin) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
if ((Integer) packetReadout[3] == 0) {
((TileEntityRedNetLogic) te).setInputPinMapping((Integer) packetReadout[4], (Integer) packetReadout[5], (Integer) packetReadout[6], (Integer) packetReadout[7]);
} else if ((Integer) packetReadout[3] == 1) {
((TileEntityRedNetLogic) te).setOutputPinMapping((Integer) packetReadout[4], (Integer) packetReadout[5], (Integer) packetReadout[6], (Integer) packetReadout[7]);
}
((TileEntityRedNetLogic) te).sendCircuitDefinition((Integer) packetReadout[4]);
}
} else if (// client -> server: set circuit
packetType == Packets.LogicReinitialize) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
((TileEntityRedNetLogic) te).reinitialize((EntityPlayer) player);
}
} else if (// client -> server: toggle 'levels'/'reject unmapped' mode
packetType == Packets.RouterButton) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityEnchantmentRouter) {
((TileEntityEnchantmentRouter) te).setMatchLevels(!((TileEntityEnchantmentRouter) te).getMatchLevels());
} else if (te instanceof TileEntityItemRouter) {
((TileEntityItemRouter) te).setRejectUnmapped(!((TileEntityItemRouter) te).getRejectUnmapped());
}
} else if (// client -> server: client clicked on a fake slot
packetType == Packets.FakeSlotChange) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
ItemStack playerStack = ((EntityPlayer) player).inventory.getItemStack();
Integer slotNumber = (Integer) packetReadout[3];
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof IInventory) {
if (playerStack == null) {
((IInventory) te).setInventorySlotContents(slotNumber, null);
} else {
playerStack = playerStack.copy();
playerStack.stackSize = 1;
((IInventory) te).setInventorySlotContents(slotNumber, playerStack);
}
}
} else if (packetType == Packets.RocketLaunchWithLock) {
Class[] decodeAs = { Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
World world = ((EntityPlayer) player).worldObj;
Entity owner = world.getEntityByID((Integer) packetReadout[0]);
Entity target = null;
if (((Integer) packetReadout[1]) != Integer.MIN_VALUE) {
target = world.getEntityByID((Integer) packetReadout[1]);
}
if (owner instanceof EntityLiving) {
EntityRocket r = new EntityRocket(world, ((EntityLiving) owner), target);
world.spawnEntityInWorld(r);
}
}
}
use of powercrystals.minefactoryreloaded.tile.machine.TileEntityItemRouter in project MineFactoryReloaded by powercrystals.
the class BlockFactoryMachine method onEntityCollidedWithBlock.
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if (world.isRemote) {
return;
}
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityItemRouter && entity instanceof EntityItem && !entity.isDead) {
ItemStack s = ((TileEntityItemRouter) te).routeItem(((EntityItem) entity).getEntityItem());
if (s == null) {
entity.setDead();
} else {
((EntityItem) entity).setEntityItemStack(s);
}
} else if (te instanceof TileEntityCollector && entity instanceof EntityItem && !entity.isDead) {
((TileEntityCollector) te).addToChests((EntityItem) entity);
}
super.onEntityCollidedWithBlock(world, x, y, z, entity);
}
Aggregations