Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chef.mod.blocks;
- import java.util.Random;
- import com.chef.mod.Chef;
- import com.chef.mod.init.MyBlocks;
- import com.chef.mod.init.MyItems;
- import com.chef.mod.tileentity.TileEntityButterChurn;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyInteger;
- import net.minecraft.block.state.BlockState;
- import net.minecraft.block.state.IBlockState;
- 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.tileentity.TileEntity;
- import net.minecraft.util.BlockPos;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class ButterChurn extends BlockContainer
- {
- public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 6);
- public ButterChurn()
- {
- super(Material.wood);
- this.setDefaultState(this.blockState.getBaseState().withProperty(LEVEL, Integer.valueOf(0)));
- this.setBlockBounds(0.19F, 0.0F, 0.19F, 0.81F, 1.0F, 0.81F);
- this.setCreativeTab(Chef.tabChef);
- }
- @Override
- public TileEntity createNewTileEntity(World world, int meta) {
- return new TileEntityButterChurn();
- }
- @Override
- public int getRenderType() {
- return 3;
- }
- @Override
- public boolean isOpaqueCube()
- {
- return false;
- }
- @Override
- public boolean isFullCube()
- {
- return false;
- }
- public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
- {
- if (worldIn.isRemote)
- {
- return true;
- }
- else
- {
- ItemStack itemstack = playerIn.getCurrentEquippedItem();
- if (itemstack == null)
- {
- return false;
- }
- else
- {
- int level = ((Integer)state.getValue(LEVEL)).intValue();
- Item item = itemstack.getItem();
- if (item == Items.milk_bucket)
- {
- if (level == 0)
- {
- if (!playerIn.capabilities.isCreativeMode)
- {
- playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, new ItemStack(Items.bucket));
- }
- this.setMilkLevel(worldIn, pos, state, 1);
- }
- return true;
- }
- else
- {
- ItemStack itemstack1;
- Random rand = new Random();
- if (item == MyItems.stamper)
- {
- if (level > 0 && level < 5)
- {
- this.setMilkLevel(worldIn, pos, state, level + 1);
- if (!playerIn.capabilities.isCreativeMode)
- {
- itemstack.damageItem(1, playerIn);
- if (itemstack.getItemDamage() >= itemstack.getMaxDamage()) {
- itemstack.stackSize--;
- }
- }
- } else if (level == 6) {
- if (!playerIn.capabilities.isCreativeMode)
- {
- itemstack.damageItem(1, playerIn);
- if (itemstack.getItemDamage() >= itemstack.getMaxDamage()) {
- itemstack.stackSize--;
- }
- itemstack1 = new ItemStack(MyItems.butter, 5 + rand.nextInt(6), 0);
- if (!playerIn.inventory.addItemStackToInventory(itemstack1))
- {
- worldIn.spawnEntityInWorld(new EntityItem(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 1.5D, (double)pos.getZ() + 0.5D, itemstack1));
- }
- else if (playerIn instanceof EntityPlayerMP)
- {
- ((EntityPlayerMP)playerIn).sendContainerToPlayer(playerIn.inventoryContainer);
- }
- }
- this.setMilkLevel(worldIn, pos, state, 0);
- }
- return true;
- } else {
- return false;
- }
- }
- }
- }
- }
- public void setMilkLevel(World worldIn, BlockPos pos, IBlockState state, int level)
- {
- worldIn.setBlockState(pos, state.withProperty(LEVEL, Integer.valueOf(MathHelper.clamp_int(level, 0, 6))), 2);
- worldIn.updateComparatorOutputLevel(pos, this);
- }
- /**
- * Get the Item that this Block should drop when harvested.
- *
- * @param fortune the level of the Fortune enchantment on the player's tool
- */
- @Override
- public Item getItemDropped(IBlockState state, Random rand, int fortune)
- {
- return Item.getItemFromBlock(MyBlocks.butter_churn);
- }
- @SideOnly(Side.CLIENT)
- public Item getItem(World worldIn, BlockPos pos)
- {
- return Item.getItemFromBlock(MyBlocks.butter_churn);
- }
- @Override
- public boolean hasComparatorInputOverride()
- {
- return true;
- }
- @Override
- public int getComparatorInputOverride(World worldIn, BlockPos pos)
- {
- return ((Integer)worldIn.getBlockState(pos).getValue(LEVEL)).intValue();
- }
- /**
- * Convert the given metadata into a BlockState for this Block
- */
- public IBlockState getStateFromMeta(int meta)
- {
- return this.getDefaultState().withProperty(LEVEL, Integer.valueOf(meta));
- }
- /**
- * Convert the BlockState into the correct metadata value
- */
- public int getMetaFromState(IBlockState state)
- {
- return ((Integer)state.getValue(LEVEL)).intValue();
- }
- protected BlockState createBlockState()
- {
- return new BlockState(this, new IProperty[] { LEVEL });
- }
- }
Add Comment
Please, Sign In to add comment