package pneumaticCraft.common.block; import java.util.List; import java.util.Random; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import pneumaticCraft.common.tileentity.TileEntityAssemblyIOUnit; import pneumaticCraft.lib.BBConstants; public class BlockAssemblyIOUnit extends BlockPneumaticCraftModeled{ public BlockAssemblyIOUnit(Material par2Material){ super(par2Material); } @Override public boolean rotateBlock(World world, EntityPlayer player, int x, int y, int z, ForgeDirection side){ if(player.isSneaking()) { return super.rotateBlock(world, player, x, y, z, side); } else { return ((TileEntityAssemblyIOUnit)world.getTileEntity(x, y, z)).switchMode(); } } @Override public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4){ setBlockBounds(BBConstants.ASSEMBLY_ROBOT_MIN_POS, 0F, BBConstants.ASSEMBLY_ROBOT_MIN_POS, BBConstants.ASSEMBLY_ROBOT_MAX_POS, BBConstants.ASSEMBLY_ROBOT_MAX_POS_TOP, BBConstants.ASSEMBLY_ROBOT_MAX_POS); } @Override public void addCollisionBoxesToList(World world, int i, int j, int k, AxisAlignedBB axisalignedbb, List arraylist, Entity par7Entity){ setBlockBounds(BBConstants.ASSEMBLY_ROBOT_MIN_POS, BBConstants.ASSEMBLY_ROBOT_MIN_POS, BBConstants.ASSEMBLY_ROBOT_MIN_POS, BBConstants.ASSEMBLY_ROBOT_MAX_POS, BBConstants.ASSEMBLY_ROBOT_MAX_POS_TOP, BBConstants.ASSEMBLY_ROBOT_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } @Override protected Class<? extends TileEntity> getTileEntityClass(){ return TileEntityAssemblyIOUnit.class; } @Override //Overriden here because the IOUnit isn't implementing IInventory (intentionally). protected void dropInventory(World world, int x, int y, int z){ TileEntity tileEntity = world.getTileEntity(x, y, z); if(!(tileEntity instanceof TileEntityAssemblyIOUnit)) return; TileEntityAssemblyIOUnit inventory = (TileEntityAssemblyIOUnit)tileEntity; Random rand = new Random(); ItemStack itemStack = inventory.inventory[0]; if(itemStack != null && itemStack.stackSize > 0) { float dX = rand.nextFloat() * 0.8F + 0.1F; float dY = rand.nextFloat() * 0.8F + 0.1F; float dZ = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage())); if(itemStack.hasTagCompound()) { entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = rand.nextGaussian() * factor + 0.2F; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); itemStack.stackSize = 0; } } }