View difference between Paste ID: v17ESRFy and Dqa1y2Ty
SHOW: | | - or go back to the newest paste.
1
package net.minecraft.src;
2
3
import java.util.Random;
4
5
public class BlockTiny extends BlockContainer {
6
7
	protected BlockTiny(int id) {
8
		super(id, Material.wood);
9
		setHardness(2.0F);
10
		setResistance(5.0F);
11
		setBlockName("blockTiny");
12
		setCreativeTab(CreativeTabs.tabDeco);
13
	}
14
	
15
	@Override
16
	public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int idk, float what, float these, float are) {
17
		TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
18
		if (tileEntity == null || player.isSneaking()) {
19
			return false;
20
		}
21
		
22
		player.openGui(MechanicTools.instance, 0, world, x, y, z);
23
		return true;
24
	}
25
	
26
	@Override
27
	public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
28
		dropItems(world, x, y, z);
29
		super.breakBlock(world, x, y, z, par5, par6);
30
	}
31
	
32
	private void dropItems(World world, int x, int y, int z) {
33
		Random rand = new Random();
34
		
35
		TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
36
		if (!(tileEntity instanceof IInventory)) {
37
			return;
38
		}
39
		IInventory inventory = (IInventory) tileEntity;
40
		
41
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
42
			ItemStack item = inventory.getStackInSlot(i);
43
			
44
			if (item != null && item.stackSize > 0) {
45
				float rx = rand.nextFloat() * 0.8F + 0.1F;
46
				float ry = rand.nextFloat() * 0.8F + 0.1F;
47
				float rz = rand.nextFloat() * 0.8F + 0.1F;
48
				
49
				EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));
50
				
51
				if (item.hasTagCompound()) {
52
					entityItem.item.setTagCompound((NBTTagCompound) item.getTagCompound().copy());
53
				}
54
				
55
				float factor = 0.05F;
56
				entityItem.motionX = rand.nextGaussian() * factor;
57
				entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
58
				entityItem.motionZ = rand.nextGaussian() * factor;
59
				world.spawnEntityInWorld(entityItem);
60
				item.stackSize = 0;
61
			}
62
		}
63
	}
64
	
65
	@Override
66
	public TileEntity createNewTileEntity(World var1) {
67
		return new TileEntityTiny();
68
	}
69
70
}