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;
}
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;
}
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;
}
Aggregations