# Pastebin jnup5nV1 package me.rushmead.stagecraft.blocks; import me.rushmead.stagecraft.init.ModBlocks; import me.rushmead.stagecraft.items.ItemHammer; import me.rushmead.stagecraft.util.Names; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; 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 StageCraftTesting */ public class StageBlockFrame extends StageCraftBlock { public static final PropertyBool hasTop = PropertyBool.create("top"); public static final PropertyBool isShort = PropertyBool.create("short"); ; public StageBlockFrame() { super(Material.rock); this.setUnlocalizedName(Names.Blocks.StageBlockFrame); } @Override public int getMetaFromState(IBlockState state) { if (((Boolean) state.getValue(hasTop)).booleanValue()) { return 1; } else if (((Boolean) state.getValue(hasTop)).booleanValue() && ((Boolean) state.getValue(isShort)).booleanValue()) { return 3; } else if (((Boolean) state.getValue(isShort)).booleanValue()) { return 2; } return 0; } @Override public IBlockState getStateFromMeta(int meta) { if (meta == 1) { return this.getDefaultState().withProperty(hasTop, true).withProperty(isShort, false); } else if (meta == 2) { return this.getDefaultState().withProperty(isShort, true).withProperty(hasTop, false); } else if (meta == 0) { return this.getDefaultState().withProperty(hasTop, true).withProperty(isShort, true); } else { return this.getDefaultState().withProperty(hasTop, false).withProperty(isShort, false); } } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, state.withProperty(hasTop, false).withProperty(isShort, false)); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityplayer, EnumFacing side, float hitX, float hitY, float hitZ) { if (!world.isRemote) { Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null; if (entityplayer.isSneaking()) { if (equipped instanceof ItemHammer) { if (state.getValue(isShort)) { world.setBlockState(pos, state.withProperty(isShort, false).withProperty(hasTop, state.getValue(hasTop))); world.markBlockForUpdate(pos); } else { world.setBlockState(pos, state.withProperty(isShort, true).withProperty(hasTop, state.getValue(hasTop))); world.markBlockForUpdate(pos); } } else { if (entityplayer.getCurrentEquippedItem() == null) { if (state.getValue(hasTop)) { world.setBlockState(pos, state.withProperty(hasTop, false)); world.markBlockForUpdate(pos); Entity entity = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModBlocks.top)); world.spawnEntityInWorld(entity); } } } } if (Block.getBlockFromItem(equipped) != null && Block.getBlockFromItem(equipped) instanceof StageBlockTop) { if (state.getValue(hasTop)) { return false; } else { world.setBlockState(pos, state.withProperty(hasTop, true).withProperty(isShort, state.getValue(isShort))); world.markBlockForUpdate(pos); System.out.print(state.toString()); return true; } } return true; } else { return false; } } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) { this.setBlockBoundsBasedOnState(worldIn, pos); return super.getSelectedBoundingBox(worldIn, pos); } 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)); } public void setBounds(IBlockState state) { if (state.getBlock() == this) { if (state.getValue(isShort)) { this.setBlockBounds(0, 0, 0, 1, 0.5F, 1); } else { this.setBlockBounds(0, 0, 0, 1, 1F, 1); } } } @Override protected BlockState createBlockState() { return new BlockState(this, hasTop, isShort); } //This tells minecraft to render surrounding blocks. @Override public boolean isOpaqueCube() { return false; } }