package imdutch21.oilcraft.block; import imdutch21.oilcraft.OilCraftMain; import imdutch21.oilcraft.proxy.CommonProxy; import imdutch21.oilcraft.tileentity.TileEntityOilGenerator; import net.minecraft.block.SoundType; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockOilGenerator extends OCContainer { public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public BlockOilGenerator() { super(Material.IRON, MapColor.GRAY); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); this.setSoundType(SoundType.METAL); this.setHardness(5.0F); this.setResistance(10.0F); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, FACING); } @SideOnly(Side.CLIENT) public IBlockState getStateForEntityRender(IBlockState state) { return this.getDefaultState().withProperty(FACING, EnumFacing.SOUTH); } @Override public int getMetaFromState(IBlockState state) { return state.getValue(FACING).getIndex(); } @Override public IBlockState getStateFromMeta(int meta) { EnumFacing enumfacing = EnumFacing.getFront(meta); if (enumfacing.getAxis() == EnumFacing.Axis.Y) { enumfacing = EnumFacing.NORTH; } return this.getDefaultState().withProperty(FACING, enumfacing); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { IBlockState blockState = getStateFromMeta(meta); return createTileEntity(worldIn, blockState); } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityOilGenerator(); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) return true; if (checkForBucketClick(worldIn, pos, hand, playerIn, side)) return true; if (worldIn.getTileEntity(pos) instanceof TileEntityOilGenerator) playerIn.openGui(OilCraftMain.instance, CommonProxy.OIL_GENERATOR_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } }