{"body":"package me.rushmead.stagecraft.blocks;\n\n\nimport me.rushmead.stagecraft.init.ModBlocks;\nimport me.rushmead.stagecraft.items.ItemHammer;\nimport me.rushmead.stagecraft.util.Names;\nimport net.minecraft.block.Block;\nimport net.minecraft.block.material.Material;\nimport net.minecraft.block.properties.PropertyBool;\nimport net.minecraft.block.state.BlockState;\nimport net.minecraft.block.state.IBlockState;\nimport net.minecraft.entity.Entity;\nimport net.minecraft.entity.EntityLivingBase;\nimport net.minecraft.entity.item.EntityItem;\nimport net.minecraft.entity.player.EntityPlayer;\nimport net.minecraft.item.Item;\nimport net.minecraft.item.ItemStack;\nimport net.minecraft.util.AxisAlignedBB;\nimport net.minecraft.util.BlockPos;\nimport net.minecraft.util.EnumFacing;\nimport net.minecraft.world.IBlockAccess;\nimport net.minecraft.world.World;\nimport net.minecraftforge.fml.relauncher.Side;\nimport net.minecraftforge.fml.relauncher.SideOnly;\n\n/**\n * Created by Rushmead for StageCraftTesting\n */\npublic class StageBlockFrame extends StageCraftBlock {\n    public static final PropertyBool hasTop = PropertyBool.create(\"top\");\n    public static final PropertyBool isShort = PropertyBool.create(\"short\");\n    ;\n\n    public StageBlockFrame() {\n\n        super(Material.rock);\n        this.setUnlocalizedName(Names.Blocks.StageBlockFrame);\n    }\n\n    @Override\n    public int getMetaFromState(IBlockState state) {\n        if (((Boolean) state.getValue(hasTop)).booleanValue()) {\n            return 1;\n        } else if (((Boolean) state.getValue(hasTop)).booleanValue() && ((Boolean) state.getValue(isShort)).booleanValue()) {\n            return 3;\n        } else if (((Boolean) state.getValue(isShort)).booleanValue()) {\n            return 2;\n        }\n        return 0;\n    }\n\n    @Override\n    public IBlockState getStateFromMeta(int meta) {\n        if (meta == 1) {\n            return this.getDefaultState().withProperty(hasTop, true).withProperty(isShort, false);\n        } else if (meta == 2) {\n            return this.getDefaultState().withProperty(isShort, true).withProperty(hasTop, false);\n        } else if (meta == 0) {\n            return this.getDefaultState().withProperty(hasTop, true).withProperty(isShort, true);\n        } else {\n            return this.getDefaultState().withProperty(hasTop, false).withProperty(isShort, false);\n        }\n    }\n\n    @Override\n    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {\n\n        worldIn.setBlockState(pos, state.withProperty(hasTop, false).withProperty(isShort, false));\n    }\n\n\n    @Override\n    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityplayer, EnumFacing side, float hitX, float hitY, float hitZ) {\n        if (!world.isRemote) {\n            Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;\n\n            if (entityplayer.isSneaking()) {\n\n                if (equipped instanceof ItemHammer) {\n\n                    if (state.getValue(isShort)) {\n\n                        world.setBlockState(pos, state.withProperty(isShort, false).withProperty(hasTop, state.getValue(hasTop)));\n                        world.markBlockForUpdate(pos);\n\n                    } else {\n\n                        world.setBlockState(pos, state.withProperty(isShort, true).withProperty(hasTop, state.getValue(hasTop)));\n                        world.markBlockForUpdate(pos);\n\n                    }\n                } else {\n                    if (entityplayer.getCurrentEquippedItem() == null) {\n                        if (state.getValue(hasTop)) {\n                            world.setBlockState(pos, state.withProperty(hasTop, false));\n                            world.markBlockForUpdate(pos);\n                            Entity entity = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModBlocks.top));\n                            world.spawnEntityInWorld(entity);\n                        }\n\n\n                    }\n                }\n            }\n            if (Block.getBlockFromItem(equipped) != null && Block.getBlockFromItem(equipped) instanceof StageBlockTop) {\n                if (state.getValue(hasTop)) {\n                    return false;\n                } else {\n\n\n                    world.setBlockState(pos, state.withProperty(hasTop, true).withProperty(isShort, state.getValue(isShort)));\n                    world.markBlockForUpdate(pos);\n                    System.out.print(state.toString());\n                    return true;\n                }\n\n            }\n            return true;\n        } else {\n            return false;\n        }\n\n    }\n\n    @SideOnly(Side.CLIENT)\n    public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) {\n        this.setBlockBoundsBasedOnState(worldIn, pos);\n        return super.getSelectedBoundingBox(worldIn, pos);\n    }\n\n    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {\n        this.setBlockBoundsBasedOnState(worldIn, pos);\n        return super.getCollisionBoundingBox(worldIn, pos, state);\n    }\n\n    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {\n        this.setBounds(worldIn.getBlockState(pos));\n    }\n\n    public void setBounds(IBlockState state) {\n        if (state.getBlock() == this) {\n            if (state.getValue(isShort)) {\n                this.setBlockBounds(0, 0, 0, 1, 0.5F, 1);\n            } else {\n                this.setBlockBounds(0, 0, 0, 1, 1F, 1);\n            }\n\n        }\n    }\n\n    @Override\n    protected BlockState createBlockState() {\n        return new BlockState(this, hasTop, isShort);\n    }\n\n    //This tells minecraft to render surrounding blocks.\n    @Override\n    public boolean isOpaqueCube() {\n        return false;\n    }\n\n\n}\n","name":"Block","extension":"txt","url":"https://www.irccloud.com/pastebin/jnup5nV1/Block","modified":1451250560,"id":"jnup5nV1","size":5859,"lines":163,"own_paste":false,"theme":"","date":1451250560}