Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src;
- import java.util.Random;
- public class BlockTiny extends BlockContainer {
- protected BlockTiny(int id) {
- super(id, Material.wood);
- setHardness(2.0F);
- setResistance(5.0F);
- setBlockName("blockTiny");
- setCreativeTab(CreativeTabs.tabDeco);
- }
- @Override
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int idk, float what, float these, float are) {
- TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
- if (tileEntity == null || player.isSneaking()) {
- return false;
- }
- player.openGui(MechanicTools.instance, 0, world, x, y, z);
- return true;
- }
- @Override
- public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
- dropItems(world, x, y, z);
- super.breakBlock(world, x, y, z, par5, par6);
- }
- private void dropItems(World world, int x, int y, int z) {
- Random rand = new Random();
- TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
- if (!(tileEntity instanceof IInventory)) {
- return;
- }
- IInventory inventory = (IInventory) tileEntity;
- for (int i = 0; i < inventory.getSizeInventory(); i++) {
- ItemStack item = inventory.getStackInSlot(i);
- if (item != null && item.stackSize > 0) {
- float rx = rand.nextFloat() * 0.8F + 0.1F;
- float ry = rand.nextFloat() * 0.8F + 0.1F;
- float rz = rand.nextFloat() * 0.8F + 0.1F;
- EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));
- if (item.hasTagCompound()) {
- entityItem.item.setTagCompound((NBTTagCompound) item.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);
- item.stackSize = 0;
- }
- }
- }
- @Override
- public TileEntity createNewTileEntity(World var1) {
- return new TileEntityTiny();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement