Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chef.mod.blocks;
- import java.util.List;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.EntityPlayerMP;
- import net.minecraft.init.Items;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.IIcon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- import com.chef.mod.Chef;
- import com.chef.mod.Reference;
- import com.chef.mod.init.MyItems;
- import com.chef.mod.proxy.ClientProxy;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- public class MilkBarrel extends Block {
- public static int renderId;
- @SideOnly(Side.CLIENT)
- public static IIcon iconInner;
- @SideOnly(Side.CLIENT)
- public static IIcon iconTop;
- @SideOnly(Side.CLIENT)
- public static IIcon iconBottom;
- @SideOnly(Side.CLIENT)
- public static IIcon iconMilk;
- public MilkBarrel() {
- super(Material.wood);
- this.setStepSound(soundTypeWood);
- }
- @SideOnly(Side.CLIENT)
- public IIcon getIcon(int side, int metadata) {
- return side == 1 ? this.iconTop : (side == 0 ? this.iconBottom : this.blockIcon);
- }
- @SideOnly(Side.CLIENT)
- public void registerBlockIcons(IIconRegister iconRegister) {
- this.iconInner = iconRegister.registerIcon(this.getTextureName() + "_" + "inner");
- this.iconTop = iconRegister.registerIcon(this.getTextureName() + "_top");
- this.iconBottom = iconRegister.registerIcon(this.getTextureName() + "_" + "bottom");
- this.blockIcon = iconRegister.registerIcon(this.getTextureName() + "_side");
- this.iconMilk = iconRegister.registerIcon(Reference.MOD_ID + ":" + "milk_still");
- }
- public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB mask, List list, Entity collidingEntity) {
- this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3125F, 1.0F);
- super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
- float f = 0.125F;
- this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
- super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
- this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
- super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
- this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
- super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
- this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
- super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
- this.setBlockBoundsForItemRender();
- }
- @SideOnly(Side.CLIENT)
- public static IIcon getMilkBarrelIcon(String s) {
- return s.equals("inner") ? MilkBarrel.iconInner : (s.equals("bottom") ? MilkBarrel.iconBottom : null);
- }
- @SideOnly(Side.CLIENT)
- public static IIcon getMilkIcon() {
- return MilkBarrel.iconMilk;
- }
- public void setBlockBoundsForItemRender() {
- this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
- }
- @Override
- public int getRenderType() {
- return ClientProxy.milkBarrelRenderType;
- }
- public boolean renderAsNormalBlock() {
- return false;
- }
- public boolean isOpaqueCube() {
- return false;
- }
- public void onEntityCollidedWithBlock(World worldIn, int x, int y, int z, Entity entity) {
- int l = worldIn.getBlockMetadata(x, y, z);
- float f = (float) y + (6.0F + (float) (3 * l)) / 16.0F;
- if (!worldIn.isRemote && entity.isBurning() && l > 0 && entity.boundingBox.minY <= (double) f) {
- entity.extinguish();
- this.setMilkLevel(worldIn, x, y, z, l - 1);
- }
- }
- public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer playerIn, int side, float hitX, float hitY, float hitZ) {
- if (worldIn.isRemote) {
- return true;
- } else {
- ItemStack itemstack = playerIn.inventory.getCurrentItem();
- if (itemstack == null) {
- return true;
- } else {
- int i = worldIn.getBlockMetadata(x, y, z);
- Item item = itemstack.getItem();
- if (item == Items.bucket) {
- if (i == 5) {
- if (!playerIn.capabilities.isCreativeMode) {
- playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, new ItemStack(Items.milk_bucket));
- }
- this.setMilkLevel(worldIn, x, y, z, 0);
- }
- } else if (item == MyItems.milk_bowl) {
- if (i != 5) {
- if (!playerIn.capabilities.isCreativeMode) {
- playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, new ItemStack(Items.bowl));
- }
- this.setMilkLevel(worldIn, x, y, z, i + 1);
- }
- }
- if (item == Items.milk_bucket) {
- if (i < 5) {
- if (!playerIn.capabilities.isCreativeMode) {
- playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, new ItemStack(Items.bucket));
- }
- this.setMilkLevel(worldIn, x, y, z, 5);
- }
- return true;
- } else {
- ItemStack itemstack1;
- if (item == Items.bowl) {
- if (i > 0) {
- if (!playerIn.capabilities.isCreativeMode) {
- itemstack1 = new ItemStack(MyItems.milk_bowl, 1, 0);
- if (!playerIn.inventory.addItemStackToInventory(itemstack1)) {
- worldIn.spawnEntityInWorld(new EntityItem(worldIn, (double) x + 0.5D, (double) y + 1.5D, (double) z + 0.5D, itemstack1));
- } else if (playerIn instanceof EntityPlayerMP) {
- ((EntityPlayerMP) playerIn).sendContainerToPlayer(playerIn.inventoryContainer);
- }
- --itemstack.stackSize;
- if (itemstack.stackSize <= 0) {
- playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, (ItemStack) null);
- }
- }
- this.setMilkLevel(worldIn, x, y, z, i - 1);
- }
- return true;
- } else {
- return false;
- }
- }
- }
- }
- }
- public void setMilkLevel(World worldIn, int x, int y, int z, int level) {
- worldIn.setBlockMetadataWithNotify(x, y, z, MathHelper.clamp_int(level, 0, 3), 2);
- worldIn.func_147453_f(x, y, z, this);
- }
- public Item getItemDropped(int chance, Random rand, int fortune) {
- return MyItems.milk_barrel_reed;
- }
- @SideOnly(Side.CLIENT)
- public Item getItem(World worldIn, int x, int y, int z) {
- return MyItems.milk_barrel_reed;
- }
- public boolean hasComparatorInputOverride() {
- return true;
- }
- public int getComparatorInputOverride(World worldIn, int x, int y, int z, int p_149736_5_) {
- int i1 = worldIn.getBlockMetadata(x, y, z);
- return i1;
- }
- @SideOnly(Side.CLIENT)
- public static float getRenderLiquidLevel(int p_150025_0_) {
- int j = MathHelper.clamp_int(p_150025_0_, 0, 3);
- return (float) (6 + 3 * j) / 16.0F;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment