# Pastebin FCIIwXVi package me.rushmead.stagecraft.blocks; import me.rushmead.stagecraft.util.Names; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; /** * Created by Rushmead for StageCraft 1.8 */ public class StageFlat extends StageCraftBlock { public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public StageFlat() { this.setUnlocalizedName(Names.Blocks.StageFlat); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 0.3F); } @Override public boolean isOpaqueCube() { return false; } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) { this.setBlockBoundsBasedOnState(worldIn, pos); return super.getSelectedBoundingBox(worldIn, pos); } @Override public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) { this.setBlockBoundsBasedOnState(worldIn, pos); return super.getCollisionBoundingBox(worldIn, pos, state); } public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) { this.setBounds(worldIn.getBlockState(pos)); } /** * Sets the block's bounds for rendering it as an item */ public void setBlockBoundsForItemRender() { float f = 0.1875F; this.setBlockBounds(0.0F, 0.40625F, 0.0F, 1.0F, 0.59375F, 1.0F); } public void setBounds(IBlockState state) { if (state.getBlock() == this) { EnumFacing enumfacing = (EnumFacing) state.getValue(FACING); if (enumfacing == EnumFacing.NORTH) { this.setBlockBounds(0.0F, 0.0F, 0.8125F, 1.0F, 1.0F, 1.0F); } if (enumfacing == EnumFacing.SOUTH) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.1875F); } if (enumfacing == EnumFacing.WEST) { this.setBlockBounds(0.8125F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } if (enumfacing == EnumFacing.EAST) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.1875F, 1.0F, 1.0F); } } } @Override public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { IBlockState iblockstate = this.getDefaultState(); iblockstate = iblockstate.withProperty(FACING, facing); return iblockstate; } protected static EnumFacing getFacing(int meta) { switch (meta & 3) { case 0: return EnumFacing.NORTH; case 1: return EnumFacing.SOUTH; case 2: return EnumFacing.WEST; case 3: default: return EnumFacing.EAST; } } protected static int getMetaForFacing(EnumFacing facing) { switch (facing) { case NORTH: return 0; case SOUTH: return 1; case WEST: return 2; case EAST: default: return 3; } } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(FACING, getFacing(meta)); } @Override public int getMetaFromState(IBlockState state) { int i = 0; i = i | getMetaForFacing((EnumFacing) state.getValue(FACING)); return i; } @Override protected BlockState createBlockState() { return new BlockState(this, new IProperty[]{FACING}); } }