Search in sources :

Example 1 with TileEntityDeepStorageUnit

use of powercrystals.minefactoryreloaded.tile.machine.TileEntityDeepStorageUnit 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)

Example 2 with TileEntityDeepStorageUnit

use of powercrystals.minefactoryreloaded.tile.machine.TileEntityDeepStorageUnit in project MineFactoryReloaded by powercrystals.

the class BlockFactoryMachine method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, int blockId, int meta) {
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (te instanceof IInventory && !(te instanceof TileEntityDeepStorageUnit)) {
        IInventory inventory = ((IInventory) te);
        inv: for (int i = 0; i < inventory.getSizeInventory(); i++) {
            if (te instanceof TileEntityFactoryInventory && !((TileEntityFactoryInventory) te).shouldDropSlotWhenBroken(i)) {
                continue;
            }
            ItemStack itemstack = inventory.getStackInSlot(i);
            if (itemstack == null) {
                continue;
            }
            float xOffset = world.rand.nextFloat() * 0.8F + 0.1F;
            float yOffset = world.rand.nextFloat() * 0.8F + 0.1F;
            float zOffset = world.rand.nextFloat() * 0.8F + 0.1F;
            do {
                if (itemstack.stackSize <= 0) {
                    continue inv;
                }
                int amountToDrop = world.rand.nextInt(21) + 10;
                if (amountToDrop > itemstack.stackSize) {
                    amountToDrop = itemstack.stackSize;
                }
                itemstack.stackSize -= amountToDrop;
                EntityItem entityitem = new EntityItem(world, x + xOffset, y + yOffset, z + zOffset, new ItemStack(itemstack.itemID, amountToDrop, itemstack.getItemDamage()));
                if (itemstack.getTagCompound() != null) {
                    entityitem.getEntityItem().setTagCompound(itemstack.getTagCompound());
                }
                float motionMultiplier = 0.05F;
                entityitem.motionX = (float) world.rand.nextGaussian() * motionMultiplier;
                entityitem.motionY = (float) world.rand.nextGaussian() * motionMultiplier + 0.2F;
                entityitem.motionZ = (float) world.rand.nextGaussian() * motionMultiplier;
                world.spawnEntityInWorld(entityitem);
            } while (true);
        }
    }
    if (te instanceof TileEntityFactoryInventory) {
        ((TileEntityFactoryInventory) te).onBlockBroken();
    }
    if (te instanceof TileEntityAutoJukebox) {
        ((TileEntityAutoJukebox) te).stopRecord();
    }
    super.breakBlock(world, x, y, z, blockId, meta);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) TileEntityAutoJukebox(powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox) TileEntityFactoryInventory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryInventory) TileEntityDeepStorageUnit(powercrystals.minefactoryreloaded.tile.machine.TileEntityDeepStorageUnit) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

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