Advertisement
Guest User

furnaceBlock

a guest
Apr 23rd, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.40 KB | None | 0 0
  1. package net.codecraft.mod.blocks;
  2.  
  3. import net.codecraft.mod.Codecraft;
  4. import net.codecraft.mod.tileentity.TileEntityCodeOven;
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockContainer;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.client.renderer.texture.IIconRegister;
  9. import net.minecraft.entity.EntityLivingBase;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.tileentity.TileEntity;
  14. import net.minecraft.util.IIcon;
  15. import net.minecraft.util.MathHelper;
  16. import net.minecraft.world.World;
  17. import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
  18. import cpw.mods.fml.relauncher.Side;
  19. import cpw.mods.fml.relauncher.SideOnly;
  20.  
  21. public class CodeOven extends BlockContainer {
  22.  
  23.     private final boolean isActive;
  24.    
  25.     @SideOnly(Side.CLIENT)
  26.     private IIcon iconFront;
  27.    
  28.     @SideOnly(Side.CLIENT)
  29.     private IIcon iconTop;
  30.    
  31.     private static boolean keepInventory;
  32.    
  33.     public CodeOven(boolean isActive) {
  34.         super(Material.iron);
  35.        
  36.         this.isActive = isActive;
  37.     }
  38.    
  39.     @SideOnly(Side.CLIENT)
  40.     public void registerBlockIcons(IIconRegister iconRegister){
  41.         this.blockIcon = iconRegister.registerIcon(Codecraft.MODID + ":" + "CodeOvenSide");
  42.         this.iconFront = iconRegister.registerIcon(Codecraft.MODID + ":" + (this.isActive ? "CodeOvenFrontOn" : "CodeOvenFrontOff"));
  43.         this.iconTop = iconRegister.registerIcon(Codecraft.MODID + ":" + "CodeOvenTop");
  44.     }
  45.    
  46.     @SideOnly(Side.CLIENT)
  47.     public IIcon getIcon(int side, int metadata){
  48.         return side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side != metadata ? this.blockIcon : this.iconFront));
  49.     }
  50.    
  51.     public Item getItemDropped(World world, int x, int y, int z){
  52.         return Item.getItemFromBlock(Codecraft.blockCodeOvenIdle);
  53.     }
  54.    
  55.     public void onBlockAdded(World world, int x, int y, int z){
  56.         super.onBlockAdded(world, x, y, z);
  57.         this.setDefaultDirection(world, x, y, z);
  58.     }
  59.    
  60.    
  61.    
  62.    
  63.     private void setDefaultDirection(World world, int x, int y, int z) {
  64.         if(!world.isRemote){
  65.             Block b1 = world.getBlock(x, y, z - 1);
  66.             Block b2 = world.getBlock(x, y, z + 1);
  67.             Block b3 = world.getBlock(x - 1, y, z);
  68.             Block b4 = world.getBlock(x + 1, y, z);
  69.            
  70.             byte b0 = 3;
  71.            
  72.             if(b1.func_149730_j() && !b2.func_149730_j()){
  73.                 b0 = 3;
  74.             }
  75.            
  76.             if(b2.func_149730_j() && !b1.func_149730_j()){
  77.                 b0 = 2;
  78.             }
  79.            
  80.             if(b3.func_149730_j() && !b4.func_149730_j()){
  81.                 b0 = 5;
  82.             }
  83.            
  84.             if(b4.func_149730_j() && !b3.func_149730_j()){
  85.                 b0 = 4;
  86.             }
  87.            
  88.             world.setBlockMetadataWithNotify(x, y, z, b0, 2);
  89.         }
  90.        
  91.     }
  92.    
  93.    
  94.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
  95.         if(!world.isRemote){
  96.             FMLNetworkHandler.openGui(player, Codecraft.instance, Codecraft.guiIDCodeOven, world, x, y, z);
  97.         }
  98.        
  99.         return true;
  100.     }
  101.  
  102.     @Override
  103.     public TileEntity createNewTileEntity(World var1, int var2) {
  104.         return new TileEntityCodeOven();
  105.     }
  106.  
  107.     //TODO randomDisplayTick
  108.    
  109.     public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityPlayer, ItemStack itemStack){
  110.         int l = MathHelper.floor_double((double)(entityPlayer.rotationYaw * 4.0F / 360.F) + 0.5D) & 3;
  111.        
  112.         if(l == 0){
  113.             world.setBlockMetadataWithNotify(x, y, z, 2, 2);
  114.         }
  115.        
  116.         if(l == 1){
  117.             world.setBlockMetadataWithNotify(x, y, z, 5, 2);
  118.         }
  119.        
  120.         if(l == 2){
  121.             world.setBlockMetadataWithNotify(x, y, z, 3, 2);
  122.         }
  123.        
  124.         if(l == 3){
  125.             world.setBlockMetadataWithNotify(x, y, z, 4, 2);
  126.         }
  127.        
  128.         if(itemStack.hasDisplayName()){
  129.             ((TileEntityCodeOven)world.getTileEntity(x, y, z)).setGuiDisplayName(itemStack.getDisplayName());
  130.         }
  131.     }
  132.  
  133.     public static void updateCodeOvenBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord) {
  134.         int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
  135.        
  136.         TileEntity tileentity = worldObj.getTileEntity(xCoord, yCoord, zCoord);
  137.         keepInventory = true;
  138.        
  139.         if(active){
  140.             worldObj.setBlock(xCoord, yCoord, zCoord, Codecraft.blockCodeOvenActive);
  141.         }else{
  142.             worldObj.setBlock(xCoord, yCoord, zCoord, Codecraft.blockCodeOvenIdle);
  143.         }
  144.        
  145.         keepInventory = false;
  146.        
  147.         worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);
  148.        
  149.         if(tileentity != null){
  150.             tileentity.validate();
  151.             worldObj.setTileEntity(xCoord, yCoord, zCoord, tileentity);
  152.         }
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement