package org.freeforums.geforce.securitycraft.blocks.mines; import java.util.Random; import org.freeforums.geforce.securitycraft.main.mod_SecurityCraft; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.Explosion; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockFurnaceMine extends Block{ @SideOnly(Side.CLIENT) private IIcon furnaceIconTop; @SideOnly(Side.CLIENT) private IIcon furnaceIconFront; public BlockFurnaceMine(Material par2Material) { super(par2Material); } /** * Called upon the block being destroyed by an explosion */ public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4, Explosion par5Explosion) { if (!par1World.isRemote) { this.explode(par1World, par2, par3, par4); } } public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5){ if (!par1World.isRemote) { this.explode(par1World, par2, par3, par4); } } public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9){ if(par1World.isRemote){ return true; }else{ this.explode(par1World, par2, par3, par4); return true; } } private void explode(World par1World, int par2, int par3, int par4) { par1World.func_147480_a(par2, par3, par4, false); if(mod_SecurityCraft.configHandler.smallerMineExplosion){ par1World.createExplosion((Entity)null, par2, par3, par4, 2.5F, true); }else{ par1World.createExplosion((Entity)null, par2, par3, par4, 5.0F, true); } } /** * Return whether this block can drop from an explosion. */ public boolean canDropFromExplosion(Explosion par1Explosion) { return false; } /** * Returns the quantity of items to drop on block destruction. */ public int quantityDropped(Random par1Random) { return 0; } public Item getItemDropped(int par1, Random par2Random, int par3){ return null; } /** * Called whenever the block is added into the world. Args: world, x, y, z */ public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); this.setDefaultDirection(par1World, par2, par3, par4); } /** * set a blocks direction */ private void setDefaultDirection(World par1World, int par2, int par3, int par4) { if (!par1World.isRemote) { Block block = par1World.getBlock(par2, par3, par4 - 1); Block block1 = par1World.getBlock(par2, par3, par4 + 1); Block block2 = par1World.getBlock(par2 - 1, par3, par4); Block block3 = par1World.getBlock(par2 + 1, par3, par4); byte b0 = 3; if (block.func_149730_j() && !block1.func_149730_j()) { b0 = 3; } if (block1.func_149730_j() && !block.func_149730_j()) { b0 = 2; } if (block2.func_149730_j() && !block3.func_149730_j()) { b0 = 5; } if (block3.func_149730_j() && !block2.func_149730_j()) { b0 = 4; } par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2); } } @SideOnly(Side.CLIENT) /** * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata */ public IIcon getIcon(int par1, int par2) { if(par1 == 3 && par2 == 0){ return this.furnaceIconFront; } return par1 == 1 ? this.furnaceIconTop : (par1 == 0 ? this.furnaceIconTop : (par1 != par2 ? this.blockIcon : this.furnaceIconFront)); } /** * Called when the block is placed in the world. */ public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) { int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (l == 0) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2); } if (l == 1) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2); } if (l == 2) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2); } if (l == 3) { par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2); } } @SideOnly(Side.CLIENT) /** * When this method is called, your block should register all the icons it needs with the given IconRegister. This * is the only chance you get to register icons. */ public void registerBlockIcons(IIconRegister par1IconRegister) { this.blockIcon = par1IconRegister.registerIcon("furnace_side"); this.furnaceIconFront = par1IconRegister.registerIcon("furnace_front_off"); this.furnaceIconTop = par1IconRegister.registerIcon("furnace_top"); } }