Advertisement
GravityBurger

SmallFryer

Jul 20th, 2014
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.43 KB | None | 0 0
  1. package GravityBurger.FriedChicken.block;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockContainer;
  7. import net.minecraft.block.BlockFurnace;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.client.renderer.texture.IIconRegister;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.item.EntityItem;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.nbt.NBTTagCompound;
  16. import net.minecraft.tileentity.TileEntity;
  17. import net.minecraft.util.IIcon;
  18. import net.minecraft.util.MathHelper;
  19. import net.minecraft.world.World;
  20. import GravityBurger.FriedChicken.common.FriedChicken;
  21. import GravityBurger.FriedChicken.tileentity.TileEntitySmallFryer;
  22. import cpw.mods.fml.relauncher.Side;
  23. import cpw.mods.fml.relauncher.SideOnly;
  24.  
  25. public class SmallFryer extends BlockContainer{
  26.  
  27.     @SideOnly(Side.CLIENT)
  28.     private IIcon top;
  29.     @SideOnly(Side.CLIENT)
  30.     private IIcon front;
  31.    
  32.     private static boolean isBurning;
  33.     private final boolean isBurning2;
  34.     private final Random random = new Random();
  35.    
  36.     public SmallFryer(boolean isActive) {
  37.         super(Material.rock);
  38.         isBurning2 = isActive;
  39.        
  40.     }
  41.     @SideOnly(Side.CLIENT)
  42.     public void registerBlockIcons(IIconRegister iconRegister){
  43.         this.blockIcon = iconRegister.registerIcon("FriedChicken:smallfryer_side");
  44.         this.top = iconRegister.registerIcon(this.isBurning2 ? "FriedChicken:smallfryeractive_top" : "FriedChicken:smallfryerinactive_top");
  45.         this.front = iconRegister.registerIcon("FriedChicken:smallfryer_top");
  46.     }
  47.     public IIcon getIcon(int side, int meta){
  48.         if(side == 1){
  49.             return top;
  50.         }else if(side == 3){
  51.             return front;
  52.         }else
  53.             return this.blockIcon;
  54.    
  55.     }
  56.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
  57.         player.openGui(FriedChicken.instance, 1, world, x, y, z);
  58.         return true;
  59.     }
  60.     public Item getItemDropped(int par1, Random random, int par3){
  61.         return Item.getItemFromBlock(FriedChicken.SmallFryer);
  62.     }
  63.     public Item getItem(World world, int par2, int par3, int par4){
  64.         return Item.getItemFromBlock(FriedChicken.SmallFryer);
  65.     }
  66.     @SideOnly(Side.CLIENT)
  67.     public void onBlockAdded(World world, int x, int y, int z) {
  68.         super.onBlockAdded(world, x, y, z);
  69.         this.direction(world, x, y, z);
  70.     }
  71.     private void direction(World world, int x, int y, int z) {
  72.         if (!world.isRemote) {
  73.             Block direction = world.getBlock(x, y, z - 1);
  74.             Block direction1 = world.getBlock(x, y, z + 1);
  75.             Block direction2 = world.getBlock(x - 1, y, z);
  76.             Block direction3 = world.getBlock(x + 1, y, z);
  77.             byte byte0 = 3;
  78.  
  79.             if (direction.func_149730_j() && direction.func_149730_j()) {
  80.                 byte0 = 3;
  81.             }
  82.  
  83.             if (direction1.func_149730_j() && direction1.func_149730_j()) {
  84.                 byte0 = 2;
  85.             }
  86.  
  87.             if (direction2.func_149730_j() && direction2.func_149730_j()) {
  88.                 byte0 = 5;
  89.             }
  90.  
  91.             if (direction3.func_149730_j() && direction3.func_149730_j()) {
  92.                 byte0 = 4;
  93.             }
  94.  
  95.             world.setBlockMetadataWithNotify(x, y, z, byte0, 2);
  96.         }
  97.     }
  98.     public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemstack) {
  99.         int direction = MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  100.  
  101.         if (direction == 0) {
  102.             world.setBlockMetadataWithNotify(x, y, z, 2, 2);
  103.         }
  104.  
  105.         if (direction == 1) {
  106.             world.setBlockMetadataWithNotify(x, y, z, 5, 2);
  107.         }
  108.  
  109.         if (direction == 2) {
  110.             world.setBlockMetadataWithNotify(x, y, z, 3, 2);
  111.         }
  112.  
  113.         if (direction == 3) {
  114.             world.setBlockMetadataWithNotify(x, y, z, 4, 2);
  115.         }
  116.  
  117.         if (itemstack.hasDisplayName()) {
  118.             ((TileEntitySmallFryer) world.getTileEntity(x, y, z)).furnaceName(itemstack.getDisplayName());
  119.         }
  120.     }
  121.     public static void updateBlockState(boolean burning, World world, int x, int y, int z) {
  122.         int direction = world.getBlockMetadata(x, y, z);
  123.         TileEntity tileentity = world.getTileEntity(x, y, z);
  124.         isBurning = true;
  125.  
  126.         if (burning) {
  127.             world.setBlock(x, y, z, FriedChicken.SmallFryerActive);
  128.         } else {
  129.             world.setBlock(x, y, z, FriedChicken.SmallFryer);
  130.         }
  131.  
  132.         isBurning = false;
  133.         world.setBlockMetadataWithNotify(x, y, z, direction, 2);
  134.  
  135.         if (tileentity != null) {
  136.             tileentity.validate();
  137.             world.setTileEntity(x, y, z, tileentity);
  138.         }
  139.     }
  140.     public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
  141.         if (!isBurning) {
  142.             TileEntitySmallFryer tileentitysmallfryer = (TileEntitySmallFryer) world.getTileEntity(x, y, z);
  143.  
  144.             if (tileentitysmallfryer != null) {
  145.                 for (int i = 0; i < tileentitysmallfryer.getSizeInventory(); ++i) {
  146.                     ItemStack itemstack = tileentitysmallfryer.getStackInSlot(i);
  147.  
  148.                     if (itemstack != null) {
  149.                         float f = this.random.nextFloat() * 0.6F + 0.1F;
  150.                         float f1 = this.random.nextFloat() * 0.6F + 0.1F;
  151.                         float f2 = this.random.nextFloat() * 0.6F + 0.1F;
  152.  
  153.                         while (itemstack.stackSize > 0) {
  154.                             int j = this.random.nextInt(21) + 10;
  155.  
  156.                             if (j > itemstack.stackSize) {
  157.                                 j = itemstack.stackSize;
  158.                             }
  159.  
  160.                             itemstack.stackSize -= j;
  161.                             EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage()));
  162.  
  163.                             if (itemstack.hasTagCompound()) {
  164.                                 entityitem.getEntityItem().setTagCompound(((NBTTagCompound) itemstack.getTagCompound().copy()));
  165.                             }
  166.  
  167.                             float f3 = 0.025F;
  168.                             entityitem.motionX = (double) ((float) this.random.nextGaussian() * f3);
  169.                             entityitem.motionY = (double) ((float) this.random.nextGaussian() * f3 + 0.1F);
  170.                             entityitem.motionZ = (double) ((float) this.random.nextGaussian() * f3);
  171.                             world.spawnEntityInWorld(entityitem);
  172.                         }
  173.                     }
  174.                 }
  175.                 world.func_147453_f(x, y, z, block);
  176.             }
  177.         }
  178.         super.breakBlock(world, x, y, z, block, meta);
  179.     }
  180.     public void randomDisplayTick(World world, int x, int y, int z, Random random) {
  181.         if (this.isBurning2) {
  182.             int direction = world.getBlockMetadata(x, y, z);
  183.  
  184.             float xx = (float) x + 0.5F, yy = (float) y + random.nextFloat() * 6.0F / 16.0F, zz = (float) z + 0.5F, xx2 = random.nextFloat() * 0.3F - 0.2F, zz2 = 0.5F;
  185.            
  186.             if (direction == 4) {
  187.                 world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
  188.                 world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
  189.             } else if (direction == 5) {
  190.                 world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
  191.                 world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
  192.             } else if (direction == 3) {
  193.                 world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
  194.                 world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
  195.             } else if (direction == 2) {
  196.                 world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
  197.                 world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
  198.        
  199.        
  200.        
  201.        
  202.             }
  203.             }
  204. }
  205.  
  206.     @Override
  207.     public TileEntity createNewTileEntity(World var1, int var2) {
  208.         // TODO Auto-generated method stub
  209.         return new TileEntitySmallFryer();
  210.     }
  211.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement