Advertisement
Guest User

Untitled

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