Guest User

MilkBarrel.java

a guest
Dec 24th, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.83 KB | None | 0 0
  1. package com.chef.mod.blocks;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.client.renderer.texture.IIconRegister;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.item.EntityItem;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.entity.player.EntityPlayerMP;
  13. import net.minecraft.init.Items;
  14. import net.minecraft.item.Item;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.util.AxisAlignedBB;
  17. import net.minecraft.util.IIcon;
  18. import net.minecraft.util.MathHelper;
  19. import net.minecraft.world.World;
  20.  
  21. import com.chef.mod.Chef;
  22. import com.chef.mod.Reference;
  23. import com.chef.mod.init.MyItems;
  24. import com.chef.mod.proxy.ClientProxy;
  25.  
  26. import cpw.mods.fml.relauncher.Side;
  27. import cpw.mods.fml.relauncher.SideOnly;
  28.  
  29. public class MilkBarrel extends Block {
  30.  
  31.     public static int renderId;
  32.  
  33.     @SideOnly(Side.CLIENT)
  34.     public static IIcon iconInner;
  35.     @SideOnly(Side.CLIENT)
  36.     public static IIcon iconTop;
  37.     @SideOnly(Side.CLIENT)
  38.     public static IIcon iconBottom;
  39.     @SideOnly(Side.CLIENT)
  40.     public static IIcon iconMilk;
  41.  
  42.     public MilkBarrel() {
  43.         super(Material.wood);
  44.         this.setStepSound(soundTypeWood);
  45.     }
  46.  
  47.     @SideOnly(Side.CLIENT)
  48.     public IIcon getIcon(int side, int metadata) {
  49.         return side == 1 ? this.iconTop : (side == 0 ? this.iconBottom : this.blockIcon);
  50.     }
  51.  
  52.     @SideOnly(Side.CLIENT)
  53.     public void registerBlockIcons(IIconRegister iconRegister) {
  54.         this.iconInner = iconRegister.registerIcon(this.getTextureName() + "_" + "inner");
  55.         this.iconTop = iconRegister.registerIcon(this.getTextureName() + "_top");
  56.         this.iconBottom = iconRegister.registerIcon(this.getTextureName() + "_" + "bottom");
  57.         this.blockIcon = iconRegister.registerIcon(this.getTextureName() + "_side");
  58.         this.iconMilk = iconRegister.registerIcon(Reference.MOD_ID + ":" + "milk_still");
  59.     }
  60.  
  61.     public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB mask, List list, Entity collidingEntity) {
  62.         this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3125F, 1.0F);
  63.         super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
  64.         float f = 0.125F;
  65.         this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
  66.         super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
  67.         this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
  68.         super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
  69.         this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  70.         super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
  71.         this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
  72.         super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
  73.         this.setBlockBoundsForItemRender();
  74.     }
  75.  
  76.     @SideOnly(Side.CLIENT)
  77.     public static IIcon getMilkBarrelIcon(String s) {
  78.         return s.equals("inner") ? MilkBarrel.iconInner : (s.equals("bottom") ? MilkBarrel.iconBottom : null);
  79.     }
  80.    
  81.     @SideOnly(Side.CLIENT)
  82.     public static IIcon getMilkIcon() {
  83.        
  84.         return MilkBarrel.iconMilk;
  85.        
  86.     }
  87.  
  88.     public void setBlockBoundsForItemRender() {
  89.         this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  90.     }
  91.  
  92.     @Override
  93.     public int getRenderType() {
  94.         return ClientProxy.milkBarrelRenderType;
  95.     }
  96.  
  97.     public boolean renderAsNormalBlock() {
  98.         return false;
  99.     }
  100.    
  101.     public boolean isOpaqueCube() {
  102.         return false;
  103.     }
  104.  
  105.     public void onEntityCollidedWithBlock(World worldIn, int x, int y, int z, Entity entity) {
  106.         int l = worldIn.getBlockMetadata(x, y, z);
  107.         float f = (float) y + (6.0F + (float) (3 * l)) / 16.0F;
  108.  
  109.         if (!worldIn.isRemote && entity.isBurning() && l > 0 && entity.boundingBox.minY <= (double) f) {
  110.             entity.extinguish();
  111.             this.setMilkLevel(worldIn, x, y, z, l - 1);
  112.         }
  113.     }
  114.  
  115.     public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer playerIn, int side, float hitX, float hitY, float hitZ) {
  116.         if (worldIn.isRemote) {
  117.             return true;
  118.         } else {
  119.             ItemStack itemstack = playerIn.inventory.getCurrentItem();
  120.  
  121.             if (itemstack == null) {
  122.                 return true;
  123.             } else {
  124.                 int i = worldIn.getBlockMetadata(x, y, z);
  125.                 Item item = itemstack.getItem();
  126.  
  127.                 if (item == Items.bucket) {
  128.  
  129.                     if (i == 5) {
  130.  
  131.                         if (!playerIn.capabilities.isCreativeMode) {
  132.                             playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, new ItemStack(Items.milk_bucket));
  133.                         }
  134.  
  135.                         this.setMilkLevel(worldIn, x, y, z, 0);
  136.  
  137.                     }
  138.  
  139.                 } else if (item == MyItems.milk_bowl) {
  140.  
  141.                     if (i != 5) {
  142.  
  143.                         if (!playerIn.capabilities.isCreativeMode) {
  144.                             playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, new ItemStack(Items.bowl));
  145.                         }
  146.  
  147.                         this.setMilkLevel(worldIn, x, y, z, i + 1);
  148.  
  149.                     }
  150.  
  151.                 }
  152.  
  153.                 if (item == Items.milk_bucket) {
  154.                     if (i < 5) {
  155.                         if (!playerIn.capabilities.isCreativeMode) {
  156.                             playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, new ItemStack(Items.bucket));
  157.                         }
  158.  
  159.                         this.setMilkLevel(worldIn, x, y, z, 5);
  160.                     }
  161.  
  162.                     return true;
  163.                 } else {
  164.                     ItemStack itemstack1;
  165.  
  166.                     if (item == Items.bowl) {
  167.                         if (i > 0) {
  168.                             if (!playerIn.capabilities.isCreativeMode) {
  169.                                 itemstack1 = new ItemStack(MyItems.milk_bowl, 1, 0);
  170.  
  171.                                 if (!playerIn.inventory.addItemStackToInventory(itemstack1)) {
  172.                                     worldIn.spawnEntityInWorld(new EntityItem(worldIn, (double) x + 0.5D, (double) y + 1.5D, (double) z + 0.5D, itemstack1));
  173.                                 } else if (playerIn instanceof EntityPlayerMP) {
  174.                                     ((EntityPlayerMP) playerIn).sendContainerToPlayer(playerIn.inventoryContainer);
  175.                                 }
  176.  
  177.                                 --itemstack.stackSize;
  178.  
  179.                                 if (itemstack.stackSize <= 0) {
  180.                                     playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, (ItemStack) null);
  181.                                 }
  182.                             }
  183.  
  184.                             this.setMilkLevel(worldIn, x, y, z, i - 1);
  185.                         }
  186.  
  187.                         return true;
  188.                     } else {
  189.  
  190.                         return false;
  191.  
  192.                     }
  193.                 }
  194.             }
  195.         }
  196.     }
  197.  
  198.     public void setMilkLevel(World worldIn, int x, int y, int z, int level) {
  199.         worldIn.setBlockMetadataWithNotify(x, y, z, MathHelper.clamp_int(level, 0, 3), 2);
  200.         worldIn.func_147453_f(x, y, z, this);
  201.     }
  202.  
  203.     public Item getItemDropped(int chance, Random rand, int fortune) {
  204.         return MyItems.milk_barrel_reed;
  205.     }
  206.  
  207.     @SideOnly(Side.CLIENT)
  208.     public Item getItem(World worldIn, int x, int y, int z) {
  209.         return MyItems.milk_barrel_reed;
  210.     }
  211.  
  212.     public boolean hasComparatorInputOverride() {
  213.         return true;
  214.     }
  215.  
  216.     public int getComparatorInputOverride(World worldIn, int x, int y, int z, int p_149736_5_) {
  217.         int i1 = worldIn.getBlockMetadata(x, y, z);
  218.         return i1;
  219.     }
  220.  
  221.     @SideOnly(Side.CLIENT)
  222.     public static float getRenderLiquidLevel(int p_150025_0_) {
  223.         int j = MathHelper.clamp_int(p_150025_0_, 0, 3);
  224.         return (float) (6 + 3 * j) / 16.0F;
  225.     }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment