Search in sources :

Example 1 with BlockButton

use of net.minecraft.block.BlockButton in project Charset by CharsetMC.

the class ItemChisel method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (hand == EnumHand.OFF_HAND) {
        return EnumActionResult.PASS;
    }
    if (!worldIn.isRemote) {
        IBlockState state = worldIn.getBlockState(pos);
        if (!state.getBlock().isAir(state, worldIn, pos)) {
            ItemStack inputStack = state.getBlock().getPickBlock(state, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), facing, pos), worldIn, pos, playerIn);
            if (!inputStack.isEmpty() && inputStack.getCount() == 1) {
                ItemStack heldItem = playerIn.getHeldItem(EnumHand.MAIN_HAND);
                ItemStack[] inputStacks = new ItemStack[9];
                int inputMask = getBlockMask(heldItem);
                int inputCount = 0;
                for (int i = 0; i < 9; i++) {
                    if ((inputMask & (1 << i)) != 0) {
                        inputStacks[i] = inputStack;
                        inputCount++;
                    }
                }
                ItemStack result = FastRecipeLookup.getCraftingResult(RecipeUtils.getCraftingInventory(3, 3, RecipeUtils.defaultContainer(playerIn), inputStacks), worldIn);
                if (result != null && !result.isEmpty() && !(result.getItem() instanceof ItemBlock && ((ItemBlock) result.getItem()).getBlock() instanceof BlockButton)) {
                    if (result.getItem() instanceof ItemBlock) {
                        Block block = ((ItemBlock) result.getItem()).getBlock();
                        if (block instanceof BlockButton) {
                            return EnumActionResult.FAIL;
                        }
                        if (block instanceof BlockStairs && (inputCount == 6 && result.getCount() >= 4 && result.getCount() <= 8)) {
                            result.setCount(inputCount);
                        }
                    }
                    if ((result.getCount() % inputCount) == 0) {
                        ItemStack resultCopy = result.copy();
                        resultCopy.setCount(1);
                        ActionResult<ItemStack> placeResult = ToolsUtils.placeBlockOrRollback(resultCopy, playerIn, worldIn, pos);
                        if (placeResult.getType() == EnumActionResult.FAIL) {
                            return EnumActionResult.FAIL;
                        }
                        if (result.getCount() > inputCount) {
                            ItemStack resultCopyRemainder = result.copy();
                            resultCopyRemainder.setCount((result.getCount() / inputCount) - 1);
                            Block.spawnAsEntity(worldIn, pos, resultCopyRemainder);
                        }
                    }
                }
            }
        }
    }
    return EnumActionResult.SUCCESS;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockStairs(net.minecraft.block.BlockStairs) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) BlockButton(net.minecraft.block.BlockButton) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with BlockButton

use of net.minecraft.block.BlockButton in project Ceramics by KnightMiner.

the class BlockChannel method addExtra.

private IBlockState addExtra(IBlockState state, IBlockAccess world, BlockPos pos, PropertyEnum<ChannelConnectionState> prop, EnumFacing side) {
    ChannelConnectionState connection = state.getValue(prop);
    IBlockState offsetState = world.getBlockState(pos.offset(side));
    Block block = offsetState.getBlock();
    if (connection == ChannelConnectionState.OUT && block instanceof BlockBarrel) {
        state = state.withProperty(prop, ChannelConnectionState.BARREL);
    } else if (connection == ChannelConnectionState.NONE && (block instanceof BlockLever && offsetState.getValue(BlockLever.FACING).getFacing() == side || block instanceof BlockButton && offsetState.getValue(BlockButton.FACING) == side)) {
        state = state.withProperty(prop, ChannelConnectionState.LEVER);
    }
    return state;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLever(net.minecraft.block.BlockLever) Block(net.minecraft.block.Block) BlockButton(net.minecraft.block.BlockButton)

Aggregations

Block (net.minecraft.block.Block)2 BlockButton (net.minecraft.block.BlockButton)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockLever (net.minecraft.block.BlockLever)1 BlockStairs (net.minecraft.block.BlockStairs)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1