package wehavecookies56.kk.block; import java.util.Random; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; 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.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import wehavecookies56.kk.KingdomKeys; import wehavecookies56.kk.entities.tileentities.TileEntitySynthesis; import wehavecookies56.kk.lib.Strings; public class BlockSynthesis extends BlockContainer{ protected Random rand = new Random(); public BlockSynthesis() { super(Material.iron); this.setCreativeTab(KingdomKeys.KKTAB); this.setUnlocalizedName(Strings.Synthesiser); this.setResistance(0.5F); this.setHardness(1.5F); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float a, float b, float c) { if(!world.isRemote){ player.openGui(KingdomKeys.instance, 0, world, pos.getX(), pos.getY(), pos.getZ()); } if(world.isRemote){ Minecraft.getMinecraft().thePlayer.playSound("kk:kupo", 0.3F, 1.1F); } return true; } @Override public TileEntity createNewTileEntity(World world, int i) { return new TileEntitySynthesis(); } @Override public int quantityDropped(Random par1Random) { return 1; } @Override public void breakBlock(World world, BlockPos pos, IBlockState state) { TileEntitySynthesis te = (TileEntitySynthesis)world.getTileEntity(pos); if (te != null) { for (int i1 = 0; i1 < te.getSizeInventory(); ++i1) { ItemStack itemstack = te.getStackInSlot(i1); if (itemstack != null) { float f = this.rand.nextFloat() * 0.8F + 0.1F; float f1 = this.rand.nextFloat() * 0.8F + 0.1F; float f2 = this.rand.nextFloat() * 0.8F + 0.1F; while (itemstack.stackSize > 0) { int j1 = this.rand.nextInt(21) + 10; if (j1 > itemstack.stackSize) { j1 = itemstack.stackSize; } itemstack.stackSize -= j1; EntityItem entityitem = new EntityItem(world, (double)((float)pos.getX() + f), (double)((float)pos.getY() + f1), (double)((float)pos.getZ() + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); if (itemstack.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); } float f3 = 0.05F; entityitem.motionX = (double)((float)this.rand.nextGaussian() * f3); entityitem.motionY = (double)((float)this.rand.nextGaussian() * f3 + 0.2F); entityitem.motionZ = (double)((float)this.rand.nextGaussian() * f3); world.spawnEntityInWorld(entityitem); } } } world.setBlockState(pos, state); } } public int quantityDroppedWithBonus(int fortune, Random random) { if (fortune > 0) { int j = random.nextInt(fortune + 2) - 1; if (j < 0) { j = 0; } return quantityDropped(random) * (j + 1); } else { return quantityDropped(random); } } }