Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chef.mod.blocks;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyDirection;
- import net.minecraft.block.properties.PropertyEnum;
- import net.minecraft.block.state.BlockState;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.InventoryHelper;
- 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.IStringSerializable;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import com.chef.mod.Chef;
- import com.chef.mod.init.MyBlocks;
- import com.chef.mod.tileentity.TileEntityIceCreamMaker;
- public class IceCreamMaker extends BlockContainer
- {
- public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
- public static final PropertyEnum ICE = PropertyEnum.create("ice", EnumIce.class);
- private final boolean isActive;
- private static boolean keepInventory;
- public IceCreamMaker(boolean isActive)
- {
- super(Material.iron);
- this.isActive = isActive;
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ICE, EnumIce.ICE0));
- this.setHardness(5.0F);
- this.setResistance(10.0F);
- this.setStepSound(soundTypeMetal);
- }
- public static BlockPos getFurnacePosition(BlockPos pos) {
- return pos;
- }
- public Item getItemDropped(IBlockState state, Random rand, int fortune)
- {
- return Item.getItemFromBlock(MyBlocks.ice_cream_maker);
- }
- public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
- {
- this.setDefaultFacing(worldIn, pos, state);
- }
- private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
- {
- if (!worldIn.isRemote)
- {
- Block block = worldIn.getBlockState(pos.north()).getBlock();
- Block block1 = worldIn.getBlockState(pos.south()).getBlock();
- Block block2 = worldIn.getBlockState(pos.west()).getBlock();
- Block block3 = worldIn.getBlockState(pos.east()).getBlock();
- EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
- EnumIce ice = (EnumIce) state.getValue(ICE);
- if (enumfacing == EnumFacing.NORTH && block.isFullBlock() && !block1.isFullBlock())
- {
- enumfacing = EnumFacing.SOUTH;
- }
- else if (enumfacing == EnumFacing.SOUTH && block1.isFullBlock() && !block.isFullBlock())
- {
- enumfacing = EnumFacing.NORTH;
- }
- else if (enumfacing == EnumFacing.WEST && block2.isFullBlock() && !block3.isFullBlock())
- {
- enumfacing = EnumFacing.EAST;
- }
- else if (enumfacing == EnumFacing.EAST && block3.isFullBlock() && !block2.isFullBlock())
- {
- enumfacing = EnumFacing.WEST;
- }
- worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing).withProperty(ICE, ice), 2);
- }
- }
- 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
- {
- TileEntity tileentity = worldIn.getTileEntity(pos);
- if (tileentity instanceof TileEntityIceCreamMaker)
- {
- playerIn.openGui(Chef.instance, MyBlocks.guiID_ice_cream_maker, worldIn, pos.getX(), pos.getY(), pos.getZ());
- }
- return true;
- }
- }
- public static void setState(int iceAmount, boolean isActive, World worldIn, BlockPos pos)
- {
- IBlockState iblockstate = worldIn.getBlockState(pos);
- TileEntity tileentity = worldIn.getTileEntity(pos);
- keepInventory = true;
- if (isActive) {
- switch (iceAmount) {
- case 1:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE1), 3);
- break;
- case 2:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE2), 3);
- break;
- case 3:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE3), 3);
- break;
- case 4:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE4), 3);
- break;
- case 5:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE5), 3);
- break;
- case 6:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE6), 3);
- break;
- case 7:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE7), 3);
- break;
- case 8:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE8), 3);
- break;
- case 9:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE9), 3);
- break;
- case 10:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker_on.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE10), 3);
- break;
- }
- } else {
- switch (iceAmount) {
- case 1:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE1), 3);
- break;
- case 2:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE2), 3);
- break;
- case 3:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE3), 3);
- break;
- case 4:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE4), 3);
- break;
- case 5:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE5), 3);
- break;
- case 6:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE6), 3);
- break;
- case 7:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE7), 3);
- break;
- case 8:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE8), 3);
- break;
- case 9:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE9), 3);
- break;
- case 10:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE1), 3);
- break;
- default:
- worldIn.setBlockState(pos, MyBlocks.ice_cream_maker.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ICE, EnumIce.ICE0), 3);
- break;
- }
- }
- keepInventory = false;
- if (tileentity != null)
- {
- tileentity.validate();
- worldIn.setTileEntity(pos, tileentity);
- }
- }
- public TileEntity createNewTileEntity(World worldIn, int meta)
- {
- return new TileEntityIceCreamMaker();
- }
- public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
- {
- EnumIce ice = EnumIce.byMetadata(meta);
- EnumFacing enumfacing = (placer == null) ? EnumFacing.NORTH : EnumFacing.fromAngle(placer.rotationYaw);
- return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()).withProperty(ICE, ice);
- }
- public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
- {
- worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()).withProperty(ICE, EnumIce.ICE0), 2);
- if (stack.hasDisplayName())
- {
- TileEntity tileentity = worldIn.getTileEntity(pos);
- if (tileentity instanceof TileEntityIceCreamMaker)
- {
- ((TileEntityIceCreamMaker)tileentity).setCustomInventoryName(stack.getDisplayName());
- }
- }
- }
- /*
- public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
- {
- if (!keepInventory)
- {
- TileEntity tileentity = worldIn.getTileEntity(pos);
- if (tileentity instanceof TileEntityIceCreamMaker)
- {
- InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityIceCreamMaker)tileentity);
- worldIn.updateComparatorOutputLevel(pos, this);
- }
- }
- super.breakBlock(worldIn, pos, state);
- }
- */
- public boolean hasComparatorInputOverride()
- {
- return true;
- }
- public int getComparatorInputOverride(World worldIn, BlockPos pos)
- {
- return Container.calcRedstone(worldIn.getTileEntity(pos));
- }
- @SideOnly(Side.CLIENT)
- public Item getItem(World worldIn, BlockPos pos)
- {
- return Item.getItemFromBlock(MyBlocks.ice_cream_maker);
- }
- public int getRenderType()
- {
- return 3;
- }
- @SideOnly(Side.CLIENT)
- public IBlockState getStateForEntityRender(IBlockState state)
- {
- return this.getDefaultState().withProperty(FACING, EnumFacing.SOUTH).withProperty(ICE, 0);
- }
- public IBlockState getStateFromMeta(int meta)
- {
- EnumFacing facing = EnumFacing.getHorizontal(meta);
- int icebits = (meta & 0x0c) >> 2;
- EnumIce ice = EnumIce.byMetadata(icebits);
- return this.getDefaultState().withProperty(FACING, facing).withProperty(ICE, ice);
- }
- public int getMetaFromState(IBlockState state)
- {
- EnumFacing facing = (EnumFacing) state.getValue(FACING);
- EnumIce ice = (EnumIce) state.getValue(ICE);
- int facingbits = facing.getHorizontalIndex();
- int icebits = ice.getMetadata() << 2;
- return facingbits | icebits;
- }
- protected BlockState createBlockState()
- {
- return new BlockState(this, new IProperty[] {FACING, ICE});
- }
- public static enum EnumIce implements IStringSerializable
- {
- ICE0(0, "ice0"),
- ICE1(1, "ice1"),
- ICE2(2, "ice2"),
- ICE3(3, "ice3"),
- ICE4(4, "ice4"),
- ICE5(5, "ice5"),
- ICE6(6, "ice6"),
- ICE7(7, "ice7"),
- ICE8(8, "ice8"),
- ICE9(9, "ice9"),
- ICE10(10, "ice10");
- public int getMetadata()
- {
- return this.meta;
- }
- @Override
- public String toString()
- {
- return this.name;
- }
- public static EnumIce byMetadata(int meta)
- {
- if (meta < 0 || meta >= META_LOOKUP.length)
- {
- meta = 0;
- }
- return META_LOOKUP[meta];
- }
- public String getName()
- {
- return this.name;
- }
- private final int meta;
- private final String name;
- private static final EnumIce[] META_LOOKUP = new EnumIce[values().length];
- private EnumIce(int i_meta, String i_name)
- {
- this.meta = i_meta;
- this.name = i_name;
- }
- static
- {
- for (EnumIce ice : values()) {
- META_LOOKUP[ice.getMetadata()] = ice;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement