Advertisement
Guest User

Block FurnaceChest

a guest
Apr 27th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.69 KB | None | 0 0
  1. public class BlockFurnaceChest extends BlockContainer {
  2.    
  3.     Icon iconFrontOff;
  4.     Icon iconFrontOn;
  5.     Icon iconSideOff;
  6.     Icon iconSideOn;
  7.     Icon iconBack;
  8.    
  9.     protected BlockFurnaceChest(int bID, Material material) {
  10.         super(bID, material);
  11.         this.setCreativeTab(CreativeTabs.tabTransport);
  12.         this.setUnlocalizedName("Furnace Chest");
  13.     }
  14.  
  15.     @Override
  16.     public TileEntity createNewTileEntity(World world) {
  17.         return new TileEntityFurnaceChest();
  18.     }
  19.    
  20.     @Override
  21.     public boolean hasTileEntity(int metadata) {
  22.         return true;
  23.     }
  24.    
  25.     @Override
  26.     @SideOnly(Side.CLIENT)
  27.     public Icon getBlockTexture(IBlockAccess w, int x,
  28.             int y, int z, int side) {
  29.         // TODO Auto-generated method stub
  30.         return super.getBlockTexture(w, x, y, z, side);
  31.     }
  32.    
  33.     @Override
  34.     @SideOnly(Side.CLIENT)
  35.     public Icon getIcon(int side, int meta) {
  36.         // 5 first bits of Meta is used for direction
  37.         // 16 8 4 2 1
  38.         int power = meta>>3;
  39.         power = power<<3;
  40.         int direction = meta<<3;
  41.         direction = direction>>3;
  42.        
  43.         // Down, Up, North, South, West, East
  44.        
  45.         if (power == 0){ // OFF
  46.             if (side == direction) // if it's front face.
  47.                 return iconFrontOff;
  48.             else if (side == ForgeDirection.OPPOSITES[direction])
  49.                 return iconBack;
  50.             else
  51.                 return iconSideOff;
  52.         }
  53.         else // ON
  54.         {
  55.             if (side == direction) // if it's front face.
  56.                 return iconFrontOn;
  57.             else if (side == ForgeDirection.OPPOSITES[direction])
  58.                 return iconBack;
  59.             else
  60.                 return iconSideOn;
  61.         }
  62.     }
  63.    
  64.    
  65.     @Override
  66.     @SideOnly(Side.CLIENT)
  67.     public void registerIcons(IconRegister iconRegister) {
  68.         String modId = Reference.MOD_ID.toLowerCase();
  69.         String test = modId + ":BlockFurnaceChestFrontOff";
  70.         iconFrontOff = iconRegister.registerIcon(test);
  71.         iconFrontOn = iconRegister.registerIcon(modId + ":BlockFurnaceChestFrontOn");
  72.         iconSideOff = iconRegister.registerIcon(modId + ":BlockFurnaceChestSideOff");
  73.         iconSideOn = iconRegister.registerIcon(modId + ":BlockFurnaceChestSideOn");
  74.         iconBack = iconRegister.registerIcon(modId + ":BlockFurnaceChestBack");
  75.        
  76.        
  77.     }
  78.    
  79.     /**
  80.      * Sets the direction of the block when placed
  81.      */
  82.     @Override
  83.     public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityLiving, ItemStack itemStack) {
  84.  
  85.         int direction = 0;
  86.         int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
  87.  
  88.         if (facing == 0) {
  89.             direction = ForgeDirection.NORTH.ordinal();
  90.         }
  91.         else if (facing == 1) {
  92.             direction = ForgeDirection.EAST.ordinal();
  93.         }
  94.         else if (facing == 2) {
  95.             direction = ForgeDirection.SOUTH.ordinal();
  96.         }
  97.         else if (facing == 3) {
  98.             direction = ForgeDirection.WEST.ordinal();
  99.         }
  100.  
  101.         world.setBlockMetadataWithNotify(x, y, z, direction, 3);
  102.  
  103.         ((TileEntityFurnaceChest) world.getBlockTileEntity(x, y, z)).setOrientation(direction);
  104.     }
  105.    
  106.     @Override
  107.     public boolean onBlockActivated(World w, int x, int y,
  108.             int z, EntityPlayer player, int par6, float par7,
  109.             float par8, float par9) {
  110.        
  111.         if (!player.isSneaking())
  112.             player.openGui(MazLearnedThis.instance, GuiIds.FURNACE_CHEST_ID, w, x, y, z);
  113.        
  114.         return true;
  115.        
  116.     }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement