Search in sources :

Example 1 with ISlabBlock

use of stevekung.mods.moreplanets.util.blocks.ISlabBlock in project MorePlanets by SteveKunG.

the class ItemBlockSlabMP method canPlaceBlockOnSide.

@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World world, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack itemStack) {
    if (this.block instanceof ISlabBlock) {
        ISlabBlock singleSlab = (ISlabBlock) this.block;
        BlockPos blockpos1 = pos;
        IProperty<?> iproperty = singleSlab.getHalf().getVariantProperty();
        Comparable object = singleSlab.getHalf().getTypeForItem(itemStack);
        IBlockState state = world.getBlockState(pos);
        if (state.getBlock() == singleSlab.getHalf()) {
            boolean flag = state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
            if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == state.getValue(iproperty)) {
                return true;
            }
        }
        pos = pos.offset(side);
        IBlockState state1 = world.getBlockState(pos);
        return state1.getBlock() == singleSlab.getHalf() && object == state1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(world, blockpos1, side, player, itemStack);
    }
    return super.canPlaceBlockOnSide(world, pos, side, player, itemStack);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ISlabBlock(stevekung.mods.moreplanets.util.blocks.ISlabBlock) BlockPos(net.minecraft.util.math.BlockPos) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with ISlabBlock

use of stevekung.mods.moreplanets.util.blocks.ISlabBlock in project MorePlanets by SteveKunG.

the class ItemBlockSlabMP method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack itemStack = player.getHeldItem(hand);
    if (this.block instanceof ISlabBlock) {
        ISlabBlock singleSlab = (ISlabBlock) this.block;
        if (itemStack.getCount() != 0 && player.canPlayerEdit(pos.offset(facing), facing, itemStack)) {
            Object object = singleSlab.getHalf().getTypeForItem(itemStack);
            IBlockState state = world.getBlockState(pos);
            if (state.getBlock() == singleSlab.getHalf()) {
                IProperty iproperty = singleSlab.getHalf().getVariantProperty();
                Comparable comparable = state.getValue(iproperty);
                EnumBlockHalf enumblockhalf = state.getValue(BlockSlab.HALF);
                if ((facing == EnumFacing.UP && enumblockhalf == EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && enumblockhalf == BlockSlab.EnumBlockHalf.TOP) && comparable == object) {
                    IBlockState state1 = singleSlab.getDouble().getDefaultState().withProperty(iproperty, comparable);
                    AxisAlignedBB axisalignedbb = state1.getCollisionBoundingBox(world, pos);
                    if (axisalignedbb != Block.NULL_AABB && world.checkNoEntityCollision(axisalignedbb.offset(pos)) && world.setBlockState(pos, state1, 11)) {
                        SoundType sound = singleSlab.getDouble().getSoundType(state1, world, pos, player);
                        world.playSound(player, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume() + 1.0F) / 2.0F, sound.getPitch() * 0.8F);
                        itemStack.shrink(1);
                    }
                    return EnumActionResult.SUCCESS;
                }
            }
            return this.tryPlace(player, itemStack, world, pos.offset(facing), object, singleSlab.getHalf(), singleSlab.getDouble()) ? EnumActionResult.SUCCESS : super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
        }
    } else {
        return EnumActionResult.FAIL;
    }
    return EnumActionResult.FAIL;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SoundType(net.minecraft.block.SoundType) EnumBlockHalf(net.minecraft.block.BlockSlab.EnumBlockHalf) IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ISlabBlock(stevekung.mods.moreplanets.util.blocks.ISlabBlock) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)2 ISlabBlock (stevekung.mods.moreplanets.util.blocks.ISlabBlock)2 EnumBlockHalf (net.minecraft.block.BlockSlab.EnumBlockHalf)1 SoundType (net.minecraft.block.SoundType)1 IProperty (net.minecraft.block.properties.IProperty)1 ItemStack (net.minecraft.item.ItemStack)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1