Advertisement
Guest User

Untitled

a guest
Oct 12th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.95 KB | None | 0 0
  1. package com.halestormxv.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.halestormxv.Main.MainRegistry;
  6. import com.halestormxv.lib.RefStrings;
  7. import com.halestormxv.tile_entity.TileEntityCelestialFurnace;
  8.  
  9. import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
  10. import cpw.mods.fml.relauncher.Side;
  11. import cpw.mods.fml.relauncher.SideOnly;
  12. import net.minecraft.block.Block;
  13. import net.minecraft.block.BlockContainer;
  14. import net.minecraft.block.material.Material;
  15. import net.minecraft.client.renderer.texture.IIconRegister;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.item.EntityItem;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.item.Item;
  20. import net.minecraft.item.ItemStack;
  21. import net.minecraft.nbt.NBTTagCompound;
  22. import net.minecraft.tileentity.TileEntity;
  23. import net.minecraft.tileentity.TileEntityFurnace;
  24. import net.minecraft.util.IIcon;
  25. import net.minecraft.util.MathHelper;
  26. import net.minecraft.world.World;
  27.  
  28. public class CelestialFurnace extends BlockContainer{
  29.  
  30.     @SideOnly(Side.CLIENT)
  31.     private IIcon top;
  32.     @SideOnly(Side.CLIENT)
  33.     private IIcon front;
  34.    
  35.     private final boolean isActive;
  36.     private final Random random = new Random();
  37.     private static boolean keepInventory;
  38.    
  39.     public CelestialFurnace(boolean isActive)
  40.     {
  41.         super(Material.iron);
  42.         this.setHardness(12.0F);
  43.         this.setResistance(15.0F);
  44.         this.setHarvestLevel("pickaxe", 3);
  45.         this.isActive = isActive;
  46.     }
  47.    
  48.     @SideOnly(Side.CLIENT)
  49.     public void registerBlockIcons(IIconRegister iconregister){
  50.         this.blockIcon = iconregister.registerIcon(RefStrings.MODID + ":CelestialFurnaceSide");
  51.         this.front = iconregister.registerIcon(this.isActive ? RefStrings.MODID + ":CelestialFurnaceActive" : RefStrings.MODID + ":CelestialFurnaceInactive");
  52.         this.top = iconregister.registerIcon(RefStrings.MODID + ":CelestialFurnaceTop");
  53.     }
  54.    
  55.     //Set Sides
  56.     @SideOnly(Side.CLIENT)
  57.     public IIcon getIcon(int side, int meta){
  58.         return side == 1 ? this.top : (side == 0 ? this.top : (side != meta ? this.blockIcon : this.front));
  59.     }
  60.    
  61.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
  62.         if(!world.isRemote){
  63.             FMLNetworkHandler.openGui(player, MainRegistry.modInstance, CelestialCraft_blocks.guiIDCelestialFurnace, world, x, y, z);
  64.         }
  65.         return true;
  66.     }
  67.    
  68.     //ToDO RandomDisplayTick
  69.    
  70.     public Item getItemDropped(int par1, Random random, int par3){
  71.         return Item.getItemFromBlock(CelestialCraft_blocks.celestialFurnace);
  72.     }
  73.    
  74.     public Item getItem(World world, int par2, int par3, int par4){
  75.         return Item.getItemFromBlock(CelestialCraft_blocks.celestialFurnace);
  76.     }
  77.    
  78.     public TileEntity createNewTileEntity(World world, int par2) {
  79.         return new TileEntityCelestialFurnace();
  80.     }
  81.    
  82.     public void onBlockAdded(World world, int x, int y, int z){
  83.         super.onBlockAdded(world, x, y, z);
  84.         this.defaultDirection(world, x, y, z); //Set Default Direction
  85.     }
  86.  
  87.     private void defaultDirection(World world, int x, int y, int z) {
  88.         if(!world.isRemote){
  89.             Block direction1 = world.getBlock(x, y, z - 1);
  90.             Block direction2 = world.getBlock(x, y, z + 1);
  91.             Block direction3 = world.getBlock(x - 1, y, z);
  92.             Block direction4 = world.getBlock(x + 1, y, z);
  93.             byte byte0 = 3;
  94.            
  95.             if(direction1.func_149730_j() && !direction2.func_149730_j()){
  96.                 byte0 = 3;
  97.             }
  98.             if(direction2.func_149730_j() && !direction1.func_149730_j()){
  99.                 byte0 = 2;
  100.             }
  101.             if(direction3.func_149730_j() && !direction4.func_149730_j()){
  102.                 byte0 = 5;
  103.             }
  104.             if(direction4.func_149730_j() && !direction3.func_149730_j()){
  105.                 byte0 = 4;
  106.             }
  107.            
  108.             world.setBlockMetadataWithNotify(x, y, z, byte0, 2);
  109.         }
  110.     }
  111.    
  112.     //Rotate Furnace
  113.     public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemstack){
  114.         int direction = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  115.        
  116.         if (direction == 0){
  117.             world.setBlockMetadataWithNotify(x, y, z, 2, 2);
  118.         }
  119.         if (direction == 1){
  120.             world.setBlockMetadataWithNotify(x, y, z, 5, 2);
  121.         }
  122.         if (direction == 2){
  123.             world.setBlockMetadataWithNotify(x, y, z, 3, 2);
  124.         }
  125.         if (direction == 3){
  126.             world.setBlockMetadataWithNotify(x, y, z, 4, 2);
  127.         }
  128.        
  129.         if(itemstack.hasDisplayName()){
  130.             ((TileEntityCelestialFurnace) world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
  131.         }
  132.     }
  133.    
  134.     public static void updateCelestialFurnaceBlockState(boolean burning, World world, int x, int y, int z){
  135.         int direction = world.getBlockMetadata(x, y, z);
  136.         TileEntity tileentity = world.getTileEntity(x,  y,  z);
  137.         keepInventory = true;
  138.        
  139.         if(burning){
  140.             world.setBlock(x, y, z, CelestialCraft_blocks.celestialFurnaceActive);
  141.         }else{
  142.             world.setBlock(x, y, z, CelestialCraft_blocks.celestialFurnace);
  143.         }
  144.        
  145.         keepInventory = false;
  146.         world.setBlockMetadataWithNotify(x, y, z, direction, 2);
  147.        
  148.         if(tileentity != null){
  149.             tileentity.validate();
  150.             world.setTileEntity(x, y, z, tileentity);
  151.         }
  152.     }
  153.    
  154.     public void breakBlock(World world, int x, int y, int z, Block block, int meta){
  155.         if(!keepInventory){
  156.             TileEntityCelestialFurnace tileentitycelestialfurnace = (TileEntityCelestialFurnace) world.getTileEntity(x, y, z);
  157.            
  158.             if (tileentitycelestialfurnace != null){
  159.                 for(int i = 0; i < tileentitycelestialfurnace.getSizeInventory(); ++i){
  160.                     ItemStack itemstack = tileentitycelestialfurnace.getStackInSlot(i);
  161.                    
  162.                     if(itemstack != null){
  163.                         float f = this.random.nextFloat() * 0.6F + 0.1F;
  164.                         float f1 = this.random.nextFloat() * 0.6F + 0.1F;
  165.                         float f2 = this.random.nextFloat() * 0.6F + 0.1F;
  166.                        
  167.                         while(itemstack.stackSize > 0){
  168.                             int j = this.random.nextInt(21) + 10;
  169.                            
  170.                             if (j > itemstack.stackSize){
  171.                                 j = itemstack.stackSize;
  172.                             }
  173.                            
  174.                             itemstack.stackSize -= j;
  175.                             EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage()));
  176.                            
  177.                             if(itemstack.hasTagCompound()){
  178.                                 entityitem.getEntityItem().setTagCompound(((NBTTagCompound) itemstack.getTagCompound().copy()));
  179.                             }
  180.                            
  181.                             float f3 = 0.025F;
  182.                             entityitem.motionX = (double) ((float) this.random.nextGaussian() * f3);
  183.                             entityitem.motionY = (double) ((float) this.random.nextGaussian() * f3 + 0.1F);
  184.                             entityitem.motionZ = (double) ((float) this.random.nextGaussian() * f3);
  185.                             world.spawnEntityInWorld(entityitem);
  186.                         }
  187.  
  188.                     }
  189.                 }
  190.                 world.func_147453_f(x, y, z, block);
  191.                
  192.             }
  193.         }
  194.         super.breakBlock(world, x, y, z, block, meta);
  195.     }
  196.    
  197.     @SideOnly(Side.CLIENT)
  198.     public void randomDisplayTick(World world, int x, int y, int z, Random random){
  199.         if(this.isActive){
  200.             int direction = world.getBlockMetadata(x, y, z);
  201.            
  202.             float x1 = (float) x + 0.5F;
  203.             float y1 = (float) y + random.nextFloat();
  204.             float z1 = (float) z + 0.5F;
  205.            
  206.             float f = 0.52F;
  207.             float f1 = random.nextFloat() * 0.6F - 0.3F;
  208.            
  209.             if (direction == 4){
  210.                 world.spawnParticle("smoke", (double) (x1 - f), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
  211.                 world.spawnParticle("portal", (double) (x1 - f), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
  212.             }if(direction == 5){
  213.                 world.spawnParticle("smoke", (double) (x1 + f), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
  214.                 world.spawnParticle("portal", (double) (x1 + f), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
  215.             }if(direction == 2){
  216.             world.spawnParticle("smoke", (double) (x1 + f1), (double) y1, (double) (z1 - f1), 0D, 0D, 0D);
  217.             world.spawnParticle("portal", (double) (x1 + f1), (double) y1, (double) (z1 - f1), 0D, 0D, 0D);
  218.             }if(direction == 3){
  219.                 world.spawnParticle("smoke", (double) (x1 + f1), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
  220.                 world.spawnParticle("portal", (double) (x1 + f1), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
  221.             }
  222.         }
  223.        
  224.     }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement