package net.minecraft.block; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.Random; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class BlockFurnace extends BlockContainer { private final Random field_149933_a = new Random(); private final boolean isBurning; private static boolean field_149934_M; @SideOnly(Side.CLIENT) private IIcon iconTop; /** Front face of furnace either on or off */ @SideOnly(Side.CLIENT) private IIcon iconFront; private static final String __OBFID = "CL_00000248"; protected BlockFurnace(boolean p_i45407_1_) { super(Material.rock); this.isBurning = p_i45407_1_; } public Item getItemDropped(int meta, Random random, int fortune) { return Item.getItemFromBlock(Blocks.furnace); } public void onBlockAdded(World worldIn, int x, int y, int z) { super.onBlockAdded(worldIn, x, y, z); this.func_149930_e(worldIn, x, y, z); } private void func_149930_e(World p_149930_1_, int p_149930_2_, int p_149930_3_, int p_149930_4_) { if (!p_149930_1_.isRemote) { Block block = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ - 1); Block block1 = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ + 1); Block block2 = p_149930_1_.getBlock(p_149930_2_ - 1, p_149930_3_, p_149930_4_); Block block3 = p_149930_1_.getBlock(p_149930_2_ + 1, p_149930_3_, p_149930_4_); byte b0 = 3; if (block.isFullBlock() && !block1.isFullBlock()) { b0 = 3; } if (block1.isFullBlock() && !block.isFullBlock()) { b0 = 2; } if (block2.isFullBlock() && !block3.isFullBlock()) { b0 = 5; } if (block3.isFullBlock() && !block2.isFullBlock()) { b0 = 4; } p_149930_1_.setBlockMetadataWithNotify(p_149930_2_, p_149930_3_, p_149930_4_, b0, 2); } } /** * Gets the block's texture. Args: side, meta */ @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int meta) { return side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side != meta ? this.blockIcon : this.iconFront)); } @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister reg) { this.blockIcon = reg.registerIcon("furnace_side"); this.iconFront = reg.registerIcon(this.isBurning ? "furnace_front_on" : "furnace_front_off"); this.iconTop = reg.registerIcon("furnace_top"); } /** * Called upon block activation (right click on the block). Args : world, x, y, z, player, side, hitX, hitY, hitZ. * Return : Swing hand (client), abort the block placement (server) */ public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX, float subY, float subZ) { if (worldIn.isRemote) { return true; } else { TileEntityFurnace tileentityfurnace = (TileEntityFurnace)worldIn.getTileEntity(x, y, z); if (tileentityfurnace != null) { player.func_146101_a(tileentityfurnace); } return true; } } /** * Update which block the furnace is using depending on whether or not it is burning */ public static void updateFurnaceBlockState(boolean p_149931_0_, World p_149931_1_, int p_149931_2_, int p_149931_3_, int p_149931_4_) { int l = p_149931_1_.getBlockMetadata(p_149931_2_, p_149931_3_, p_149931_4_); TileEntity tileentity = p_149931_1_.getTileEntity(p_149931_2_, p_149931_3_, p_149931_4_); field_149934_M = true; if (p_149931_0_) { p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Blocks.lit_furnace); } else { p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Blocks.furnace); } field_149934_M = false; p_149931_1_.setBlockMetadataWithNotify(p_149931_2_, p_149931_3_, p_149931_4_, l, 2); if (tileentity != null) { tileentity.validate(); p_149931_1_.setTileEntity(p_149931_2_, p_149931_3_, p_149931_4_, tileentity); } } /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityFurnace(); } /** * Called when the block is placed in the world. */ public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn) { int l = MathHelper.floor_double((double)(placer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (l == 0) { worldIn.setBlockMetadataWithNotify(x, y, z, 2, 2); } if (l == 1) { worldIn.setBlockMetadataWithNotify(x, y, z, 5, 2); } if (l == 2) { worldIn.setBlockMetadataWithNotify(x, y, z, 3, 2); } if (l == 3) { worldIn.setBlockMetadataWithNotify(x, y, z, 4, 2); } if (itemIn.hasDisplayName()) { ((TileEntityFurnace)worldIn.getTileEntity(x, y, z)).setCustomInventoryName(itemIn.getDisplayName()); } } public void breakBlock(World worldIn, int x, int y, int z, Block blockBroken, int meta) { if (!field_149934_M) { TileEntityFurnace tileentityfurnace = (TileEntityFurnace)worldIn.getTileEntity(x, y, z); if (tileentityfurnace != null) { for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1) { ItemStack itemstack = tileentityfurnace.getStackInSlot(i1); if (itemstack != null) { float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F; float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F; float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F; while (itemstack.stackSize > 0) { int j1 = this.field_149933_a.nextInt(21) + 10; if (j1 > itemstack.stackSize) { j1 = itemstack.stackSize; } itemstack.stackSize -= j1; EntityItem entityitem = new EntityItem(worldIn, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getMetadata())); if (itemstack.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); } float f3 = 0.05F; entityitem.motionX = (double)((float)this.field_149933_a.nextGaussian() * f3); entityitem.motionY = (double)((float)this.field_149933_a.nextGaussian() * f3 + 0.2F); entityitem.motionZ = (double)((float)this.field_149933_a.nextGaussian() * f3); worldIn.spawnEntityInWorld(entityitem); } } } worldIn.updateNeighborsAboutBlockChange(x, y, z, blockBroken); } } super.breakBlock(worldIn, x, y, z, blockBroken, meta); } /** * A randomly called display update to be able to add particles or other items for display */ @SideOnly(Side.CLIENT) public void randomDisplayTick(World worldIn, int x, int y, int z, Random random) { if (this.isBurning) { int l = worldIn.getBlockMetadata(x, y, z); float f = (float)x + 0.5F; float f1 = (float)y + 0.0F + random.nextFloat() * 6.0F / 16.0F; float f2 = (float)z + 0.5F; float f3 = 0.52F; float f4 = random.nextFloat() * 0.6F - 0.3F; if (l == 4) { worldIn.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D); worldIn.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D); } else if (l == 5) { worldIn.spawnParticle("smoke", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D); worldIn.spawnParticle("flame", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D); } else if (l == 2) { worldIn.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D); worldIn.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D); } else if (l == 3) { worldIn.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D); worldIn.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D); } } } public boolean hasComparatorInputOverride() { return true; } public int getComparatorInputOverride(World worldIn, int x, int y, int z, int side) { return Container.calcRedstoneFromInventory((IInventory)worldIn.getTileEntity(x, y, z)); } /** * Gets an item for the block being called on. Args: world, x, y, z */ @SideOnly(Side.CLIENT) public Item getItem(World worldIn, int x, int y, int z) { return Item.getItemFromBlock(Blocks.furnace); } }