Advertisement
Guest User

BlockQuartzFurnace

a guest
Feb 1st, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.20 KB | None | 0 0
  1. package net.scratchforfun.mod.block;
  2.  
  3. import java.util.Random;
  4.  
  5. import cpw.mods.fml.common.network.FMLNetworkHandler;
  6. import cpw.mods.fml.relauncher.Side;
  7. import cpw.mods.fml.relauncher.SideOnly;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.BlockContainer;
  10. import net.minecraft.block.material.Material;
  11. import net.minecraft.client.renderer.texture.IconRegister;
  12. import net.minecraft.entity.EntityLivingBase;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.inventory.Container;
  15. import net.minecraft.inventory.IInventory;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.tileentity.TileEntity;
  18. import net.minecraft.util.Icon;
  19. import net.minecraft.util.MathHelper;
  20. import net.minecraft.world.World;
  21. import net.scratchforfun.mod.ScratchForFun;
  22. import net.scratchforfun.mod.tileentity.TileEntityQuartzFurnace;
  23.  
  24. public class BlockQuartzFurnace extends BlockContainer{
  25.  
  26.     private final boolean isActive;
  27.     @SideOnly(Side.CLIENT)
  28.     private Icon iconFront;
  29.    
  30.     private static boolean keepInventory;
  31.    
  32.     public BlockQuartzFurnace(int id, boolean isActive) {
  33.         super(id, Material.rock);
  34.        
  35.         this.isActive = isActive;
  36.  
  37.     }
  38.     @SideOnly(Side.CLIENT)
  39.     public void registerIcons(IconRegister iconRegister){
  40.         this.blockIcon = iconRegister.registerIcon(ScratchForFun.modid + ":" + "furnace_Side");
  41.         this.iconFront = iconRegister.registerIcon(ScratchForFun.modid + ":" + (this.isActive ? "furnace_Front_Active" : "furnace_Front_Idle"));
  42.     }
  43.    
  44.     @SideOnly(Side.CLIENT)
  45.     public Icon getIcon(int side, int metadata){
  46.         return side == metadata ? this.iconFront : this.blockIcon;
  47.     }
  48.    
  49.     public int idDropped(int par1, Random random, int par3){
  50.         return ScratchForFun.blockQuartzFurnaceIdle.blockID;
  51.     }
  52.    
  53.     public void onBlockAdded(World world, int x, int y, int z){
  54.         super.onBlockAdded(world, x, y, z);
  55.         this.setDefaultDirection(world, x, y, z);
  56.     }
  57.    
  58.     private void setDefaultDirection(World world, int x, int y, int z){
  59.        
  60.         if(!world.isRemote){
  61.             int l = world.getBlockId(x, y, z - 1);
  62.             int il = world.getBlockId(x, y, z + 1);
  63.             int jl = world.getBlockId(x - 1, y, z);
  64.             int kl = world.getBlockId(x + 1, y, z);
  65.             byte b0 = 3;
  66.            
  67.             if(Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[il]){
  68.                 b0 = 3;
  69.             }
  70.            
  71.             if(Block.opaqueCubeLookup[il] && !Block.opaqueCubeLookup[l]){
  72.                 b0 = 2;
  73.             }
  74.            
  75.             if(Block.opaqueCubeLookup[jl] && !Block.opaqueCubeLookup[kl]){
  76.                 b0 = 5;
  77.             }
  78.            
  79.             if(Block.opaqueCubeLookup[kl] && !Block.opaqueCubeLookup[jl]){
  80.                 b0 = 4;
  81.             }
  82.        
  83.             world.setBlockMetadataWithNotify(x, y, z, b0, 2);
  84.         }
  85.     }
  86.    
  87.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
  88.         if(!world.isRemote){
  89.             FMLNetworkHandler.openGui(player, ScratchForFun.instance, ScratchForFun.guiIdQuartzFurnace, world, x, y, z);
  90.         }
  91.        
  92.         return true;
  93.     }
  94.    
  95.     public TileEntity createNewTileEntity(World world){
  96.         return new TileEntityQuartzFurnace();
  97.     }
  98.    
  99.     public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack itemStack){
  100.         int l = MathHelper.floor_double((double)(entityLivingBase.rotationYaw * 4.0F /360.0F) + 0.5D) & 3;
  101.        
  102.         if(l == 0){
  103.             world.setBlockMetadataWithNotify(x, y, z, 2, 2);
  104.         }
  105.        
  106.         if(l == 1){
  107.             world.setBlockMetadataWithNotify(x, y, z, 5, 2);
  108.         }
  109.         if(l == 2){
  110.             world.setBlockMetadataWithNotify(x, y, z, 3, 2);
  111.         }
  112.         if(l == 3){
  113.             world.setBlockMetadataWithNotify(x, y, z, 4, 2);
  114.         }
  115.         if(itemStack.hasDisplayName()){
  116.             ((TileEntityQuartzFurnace)world.getBlockTileEntity(x, y, z)).setGuiDisplayName(itemStack.getDisplayName());
  117.            
  118.         }
  119.     }
  120.     public static void updateQuartzFurnaceBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord) {//makes it so when the furnace updates it keeps its inventory
  121.         int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);//sets the metadata to the one we had before
  122.         TileEntity tileentity = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);//sets the title entity to the one we had before
  123.         keepInventory = true;//
  124.        
  125.         if(active){//if the furnace is active its going to set it to a Active block ID else a Idle block ID
  126.             worldObj.setBlock(xCoord, yCoord, zCoord, ScratchForFun.blockQuartzFurnaceActive.blockID);
  127.         }else{
  128.             worldObj.setBlock(xCoord, yCoord, zCoord, ScratchForFun.blockQuartzFurnaceIdle.blockID);
  129.         }
  130.        
  131.         keepInventory = false;
  132.        
  133.         worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2); // 2 is a change to the client
  134.        
  135.         if(tileentity != null){//makes sure there was a tile entity
  136.             tileentity.validate();
  137.             worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, tileentity);
  138.         }
  139.     }
  140.  
  141.     public boolean hasComparatorInputOverride(){//allows for there to be a comparator used on the furnace
  142.         return true;
  143.     }
  144.    
  145.     public int getComparatorInputOverride(World world, int x, int y, int z, int i){
  146.         return Container.calcRedstoneFromInventory((IInventory)world.getBlockTileEntity(x, y, z));
  147.     }
  148.  
  149.     public int idPicked(World world, int x, int y, int z){//when you hit it with the middle mouse button it will allow it to be picked
  150.         return ScratchForFun.blockQuartzFurnaceIdle.blockID;
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement