Search in sources :

Example 1 with TileEntityChronotyper

use of powercrystals.minefactoryreloaded.tile.machine.TileEntityChronotyper 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);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityLiving(net.minecraft.entity.EntityLiving) TileEntityEnchantmentRouter(powercrystals.minefactoryreloaded.tile.machine.TileEntityEnchantmentRouter) TileEntityRedNetLogic(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetLogic) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityAutoEnchanter(powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoEnchanter) TileEntityChronotyper(powercrystals.minefactoryreloaded.tile.machine.TileEntityChronotyper) TileEntityAutoDisenchanter(powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoDisenchanter) IInventory(net.minecraft.inventory.IInventory) TileEntityAutoSpawner(powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoSpawner) TileEntityItemRouter(powercrystals.minefactoryreloaded.tile.machine.TileEntityItemRouter) EntityRocket(powercrystals.minefactoryreloaded.entity.EntityRocket) DataInputStream(java.io.DataInputStream) TileEntityDeepStorageUnit(powercrystals.minefactoryreloaded.tile.machine.TileEntityDeepStorageUnit) ByteArrayInputStream(java.io.ByteArrayInputStream) TileEntityHarvester(powercrystals.minefactoryreloaded.tile.machine.TileEntityHarvester) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntityAutoJukebox(powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox) TileEntityBlockSmasher(powercrystals.minefactoryreloaded.tile.machine.TileEntityBlockSmasher) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 Entity (net.minecraft.entity.Entity)1 EntityLiving (net.minecraft.entity.EntityLiving)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 World (net.minecraft.world.World)1 EntityRocket (powercrystals.minefactoryreloaded.entity.EntityRocket)1 TileEntityAutoDisenchanter (powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoDisenchanter)1 TileEntityAutoEnchanter (powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoEnchanter)1 TileEntityAutoJukebox (powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox)1 TileEntityAutoSpawner (powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoSpawner)1 TileEntityBlockSmasher (powercrystals.minefactoryreloaded.tile.machine.TileEntityBlockSmasher)1 TileEntityChronotyper (powercrystals.minefactoryreloaded.tile.machine.TileEntityChronotyper)1 TileEntityDeepStorageUnit (powercrystals.minefactoryreloaded.tile.machine.TileEntityDeepStorageUnit)1 TileEntityEnchantmentRouter (powercrystals.minefactoryreloaded.tile.machine.TileEntityEnchantmentRouter)1 TileEntityHarvester (powercrystals.minefactoryreloaded.tile.machine.TileEntityHarvester)1 TileEntityItemRouter (powercrystals.minefactoryreloaded.tile.machine.TileEntityItemRouter)1