Search in sources :

Example 1 with LeavesBlock

use of net.minecraft.block.LeavesBlock in project SophisticatedBackpacks by P3pp3rF1y.

the class ToolSwapperUpgradeWrapper method tryToSwapTool.

private boolean tryToSwapTool(PlayerEntity player, BlockState state, Block block, ItemStack mainHandItem) {
    AtomicReference<ItemStack> selectedTool = new AtomicReference<>(ItemStack.EMPTY);
    AtomicInteger selectedSlot = new AtomicInteger(-1);
    AtomicBoolean finished = new AtomicBoolean(false);
    IItemHandlerSimpleInserter backpackInventory = backpackWrapper.getInventoryHandler();
    InventoryHelper.iterate(backpackInventory, (slot, stack) -> {
        if (stack.isEmpty()) {
            return;
        }
        if (isAllowedAndGoodAtBreakingBlock(state, block, stack)) {
            selectedSlot.set(slot);
            selectedTool.set(stack);
            if (!(block instanceof LeavesBlock) || !getToolTypes(stack).contains(ToolType.HOE)) {
                finished.set(true);
            }
        }
    }, finished::get);
    ItemStack tool = selectedTool.get();
    if (!tool.isEmpty() && hasSpaceInBackpackOrCanPlaceInTheSlotOfSwappedTool(backpackInventory, mainHandItem, tool, selectedSlot.get())) {
        player.setItemInHand(Hand.MAIN_HAND, backpackInventory.extractItem(selectedSlot.get(), 1, false));
        backpackInventory.insertItem(mainHandItem, false);
        return true;
    }
    return false;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IItemHandlerSimpleInserter(net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter) AtomicReference(java.util.concurrent.atomic.AtomicReference) ItemStack(net.minecraft.item.ItemStack) LeavesBlock(net.minecraft.block.LeavesBlock)

Example 2 with LeavesBlock

use of net.minecraft.block.LeavesBlock in project Structurize by ldtteam.

the class Utils method findTopGround.

/**
 * Finds the highest block in one y coordinate, but ignores leaves etc.
 *
 * @param world world obj.
 * @param x     x coordinate.
 * @param z     z coordinate.
 * @return yCoordinate.
 */
public static int findTopGround(@NotNull final World world, final int x, final int z) {
    int yHolder = 1;
    final BlockPos pos = new BlockPos(x, yHolder, z);
    while (!world.canSeeSkyFromBelowWater(pos)) {
        yHolder++;
    }
    final BlockState state = world.getBlockState(pos);
    while (!state.isSolidRender(world, pos) || state.getBlock() instanceof LeavesBlock || world.isEmptyBlock(pos)) {
        yHolder--;
    }
    return yHolder;
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) LeavesBlock(net.minecraft.block.LeavesBlock)

Example 3 with LeavesBlock

use of net.minecraft.block.LeavesBlock in project BleachHack by BleachDrinker420.

the class WorldUtils method getTopBlockIgnoreLeaves.

public static int getTopBlockIgnoreLeaves(int x, int z) {
    int top = mc.world.getTopY(Heightmap.Type.WORLD_SURFACE, x, z) - 1;
    while (top > mc.world.getBottomY()) {
        BlockState state = mc.world.getBlockState(new BlockPos(x, top, z));
        if (!(state.isAir() || state.getBlock() instanceof LeavesBlock || state.getBlock() instanceof PlantBlock)) {
            break;
        }
        top--;
    }
    return top;
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) PlantBlock(net.minecraft.block.PlantBlock) LeavesBlock(net.minecraft.block.LeavesBlock)

Aggregations

LeavesBlock (net.minecraft.block.LeavesBlock)3 BlockState (net.minecraft.block.BlockState)2 BlockPos (net.minecraft.util.math.BlockPos)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 PlantBlock (net.minecraft.block.PlantBlock)1 ItemStack (net.minecraft.item.ItemStack)1 IItemHandlerSimpleInserter (net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter)1