Search in sources :

Example 1 with GoalComposite

use of baritone.api.pathing.goals.GoalComposite in project baritone by cabaletta.

the class BuilderProcess method assemble.

private Goal assemble(BuilderCalculationContext bcc, List<IBlockState> approxPlaceable, boolean logMissing) {
    List<BetterBlockPos> placeable = new ArrayList<>();
    List<BetterBlockPos> breakable = new ArrayList<>();
    List<BetterBlockPos> sourceLiquids = new ArrayList<>();
    List<BetterBlockPos> flowingLiquids = new ArrayList<>();
    Map<IBlockState, Integer> missing = new HashMap<>();
    incorrectPositions.forEach(pos -> {
        IBlockState state = bcc.bsi.get0(pos);
        if (state.getBlock() instanceof BlockAir) {
            if (approxPlaceable.contains(bcc.getSchematic(pos.x, pos.y, pos.z, state))) {
                placeable.add(pos);
            } else {
                IBlockState desired = bcc.getSchematic(pos.x, pos.y, pos.z, state);
                missing.put(desired, 1 + missing.getOrDefault(desired, 0));
            }
        } else {
            if (state.getBlock() instanceof BlockLiquid) {
                // TODO for 1.13 make sure that this only matches pure water, not waterlogged blocks
                if (!MovementHelper.possiblyFlowing(state)) {
                    // if it's a source block then we want to replace it with a throwaway
                    sourceLiquids.add(pos);
                } else {
                    flowingLiquids.add(pos);
                }
            } else {
                breakable.add(pos);
            }
        }
    });
    List<Goal> toBreak = new ArrayList<>();
    breakable.forEach(pos -> toBreak.add(breakGoal(pos, bcc)));
    List<Goal> toPlace = new ArrayList<>();
    placeable.forEach(pos -> {
        if (!placeable.contains(pos.down()) && !placeable.contains(pos.down(2))) {
            toPlace.add(placementGoal(pos, bcc));
        }
    });
    sourceLiquids.forEach(pos -> toPlace.add(new GoalBlock(pos.up())));
    if (!toPlace.isEmpty()) {
        return new JankyGoalComposite(new GoalComposite(toPlace.toArray(new Goal[0])), new GoalComposite(toBreak.toArray(new Goal[0])));
    }
    if (toBreak.isEmpty()) {
        if (logMissing && !missing.isEmpty()) {
            logDirect("Missing materials for at least:");
            logDirect(missing.entrySet().stream().map(e -> String.format("%sx %s", e.getValue(), e.getKey())).collect(Collectors.joining("\n")));
        }
        if (logMissing && !flowingLiquids.isEmpty()) {
            logDirect("Unreplaceable liquids at at least:");
            logDirect(flowingLiquids.stream().map(p -> String.format("%s %s %s", p.x, p.y, p.z)).collect(Collectors.joining("\n")));
        }
        return null;
    }
    return new GoalComposite(toBreak.toArray(new Goal[0]));
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) GoalBlock(baritone.api.pathing.goals.GoalBlock) GoalComposite(baritone.api.pathing.goals.GoalComposite) Goal(baritone.api.pathing.goals.Goal) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 2 with GoalComposite

use of baritone.api.pathing.goals.GoalComposite in project Spark-Client by Spark-Client-Development.

the class BuilderProcess method assemble.

private Goal assemble(BuilderCalculationContext bcc, List<IBlockState> approxPlaceable, boolean logMissing) {
    List<BetterBlockPos> placeable = new ArrayList<>();
    List<BetterBlockPos> breakable = new ArrayList<>();
    List<BetterBlockPos> sourceLiquids = new ArrayList<>();
    List<BetterBlockPos> flowingLiquids = new ArrayList<>();
    Map<IBlockState, Integer> missing = new HashMap<>();
    incorrectPositions.forEach(pos -> {
        IBlockState state = bcc.bsi.get0(pos);
        if (state.getBlock() instanceof BlockAir) {
            if (approxPlaceable.contains(bcc.getSchematic(pos.x, pos.y, pos.z, state))) {
                placeable.add(pos);
            } else {
                IBlockState desired = bcc.getSchematic(pos.x, pos.y, pos.z, state);
                missing.put(desired, 1 + missing.getOrDefault(desired, 0));
            }
        } else {
            if (state.getBlock() instanceof BlockLiquid) {
                // TODO for 1.13 make sure that this only matches pure water, not waterlogged blocks
                if (!MovementHelper.possiblyFlowing(state)) {
                    // if it's a source block then we want to replace it with a throwaway
                    sourceLiquids.add(pos);
                } else {
                    flowingLiquids.add(pos);
                }
            } else {
                breakable.add(pos);
            }
        }
    });
    List<Goal> toBreak = new ArrayList<>();
    breakable.forEach(pos -> toBreak.add(breakGoal(pos, bcc)));
    List<Goal> toPlace = new ArrayList<>();
    placeable.forEach(pos -> {
        if (!placeable.contains(pos.down()) && !placeable.contains(pos.down(2))) {
            toPlace.add(placementGoal(pos, bcc));
        }
    });
    sourceLiquids.forEach(pos -> toPlace.add(new GoalBlock(pos.up())));
    if (!toPlace.isEmpty()) {
        return new JankyGoalComposite(new GoalComposite(toPlace.toArray(new Goal[0])), new GoalComposite(toBreak.toArray(new Goal[0])));
    }
    if (toBreak.isEmpty()) {
        if (logMissing && !missing.isEmpty()) {
            logDirect("Missing materials for at least:");
            logDirect(missing.entrySet().stream().map(e -> String.format("%sx %s", e.getValue(), e.getKey())).collect(Collectors.joining("\n")));
        }
        if (logMissing && !flowingLiquids.isEmpty()) {
            logDirect("Unreplaceable liquids at at least:");
            logDirect(flowingLiquids.stream().map(p -> String.format("%s %s %s", p.x, p.y, p.z)).collect(Collectors.joining("\n")));
        }
        return null;
    }
    return new GoalComposite(toBreak.toArray(new Goal[0]));
}
Also used : BlockAir(net.minecraft.block.BlockAir) IBlockState(net.minecraft.block.state.IBlockState) GoalBlock(baritone.api.pathing.goals.GoalBlock) GoalComposite(baritone.api.pathing.goals.GoalComposite) Goal(baritone.api.pathing.goals.Goal) BlockLiquid(net.minecraft.block.BlockLiquid) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 3 with GoalComposite

use of baritone.api.pathing.goals.GoalComposite in project Spark-Client by Spark-Client-Development.

the class FollowProcess method onTick.

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
    scanWorld();
    Goal goal = new GoalComposite(cache.stream().map(this::towards).toArray(Goal[]::new));
    return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH);
}
Also used : GoalComposite(baritone.api.pathing.goals.GoalComposite) Goal(baritone.api.pathing.goals.Goal) PathingCommand(baritone.api.process.PathingCommand)

Example 4 with GoalComposite

use of baritone.api.pathing.goals.GoalComposite in project Spark-Client by Spark-Client-Development.

the class ExploreProcess method onTick.

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
    if (calcFailed) {
        logDirect("Failed");
        if (Baritone.settings().desktopNotifications.getValue() && Baritone.settings().notificationOnExploreFinished.getValue()) {
            NotificationHelper.notify("Exploration failed", true);
        }
        onLostControl();
        return null;
    }
    IChunkFilter filter = calcFilter();
    if (!Baritone.settings().disableCompletionCheck.getValue() && filter.countRemain() == 0) {
        logDirect("Explored all chunks");
        if (Baritone.settings().desktopNotifications.getValue() && Baritone.settings().notificationOnExploreFinished.getValue()) {
            NotificationHelper.notify("Explored all chunks", false);
        }
        onLostControl();
        return null;
    }
    Goal[] closestUncached = closestUncachedChunks(explorationOrigin, filter);
    if (closestUncached == null) {
        logDebug("awaiting region load from disk");
        return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
    }
    return new PathingCommand(new GoalComposite(closestUncached), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
}
Also used : GoalComposite(baritone.api.pathing.goals.GoalComposite) Goal(baritone.api.pathing.goals.Goal) PathingCommand(baritone.api.process.PathingCommand)

Example 5 with GoalComposite

use of baritone.api.pathing.goals.GoalComposite in project Spark-Client by Spark-Client-Development.

the class FarmProcess method onTick.

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
    ArrayList<Block> scan = new ArrayList<>();
    for (Harvest harvest : Harvest.values()) {
        scan.add(harvest.block);
    }
    if (Baritone.settings().replantCrops.getValue()) {
        scan.add(Blocks.FARMLAND);
        if (Baritone.settings().replantNetherWart.getValue()) {
            scan.add(Blocks.SOUL_SAND);
        }
    }
    if (Baritone.settings().mineGoalUpdateInterval.getValue() != 0 && tickCount++ % Baritone.settings().mineGoalUpdateInterval.getValue() == 0) {
        Baritone.getExecutor().execute(() -> locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 10));
    }
    if (locations == null) {
        return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
    }
    List<BlockPos> toBreak = new ArrayList<>();
    List<BlockPos> openFarmland = new ArrayList<>();
    List<BlockPos> bonemealable = new ArrayList<>();
    List<BlockPos> openSoulsand = new ArrayList<>();
    for (BlockPos pos : locations) {
        // check if the target block is out of range.
        if (range != 0 && pos.getDistance(center.getX(), center.getY(), center.getZ()) > range) {
            continue;
        }
        IBlockState state = ctx.world().getBlockState(pos);
        boolean airAbove = ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir;
        if (state.getBlock() == Blocks.FARMLAND) {
            if (airAbove) {
                openFarmland.add(pos);
            }
            continue;
        }
        if (state.getBlock() == Blocks.SOUL_SAND) {
            if (airAbove) {
                openSoulsand.add(pos);
            }
            continue;
        }
        if (readyForHarvest(ctx.world(), pos, state)) {
            toBreak.add(pos);
            continue;
        }
        if (state.getBlock() instanceof IGrowable) {
            IGrowable ig = (IGrowable) state.getBlock();
            if (ig.canGrow(ctx.world(), pos, state, true) && ig.canUseBonemeal(ctx.world(), ctx.world().rand, pos, state)) {
                bonemealable.add(pos);
            }
        }
    }
    baritone.getInputOverrideHandler().clearAllKeys();
    for (BlockPos pos : toBreak) {
        Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
        if (rot.isPresent() && isSafeToCancel) {
            baritone.getLookBehavior().updateTarget(rot.get(), true);
            MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos));
            if (ctx.isLookingAt(pos)) {
                baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
            }
            return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
        }
    }
    ArrayList<BlockPos> both = new ArrayList<>(openFarmland);
    both.addAll(openSoulsand);
    for (BlockPos pos : both) {
        boolean soulsand = openSoulsand.contains(pos);
        Optional<Rotation> rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false);
        if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
            RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
            if (result.typeOfHit == RayTraceResult.Type.BLOCK && result.sideHit == EnumFacing.UP) {
                baritone.getLookBehavior().updateTarget(rot.get(), true);
                if (ctx.isLookingAt(pos)) {
                    baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
                }
                return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
            }
        }
    }
    for (BlockPos pos : bonemealable) {
        Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
        if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) {
            baritone.getLookBehavior().updateTarget(rot.get(), true);
            if (ctx.isLookingAt(pos)) {
                baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
            }
            return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
        }
    }
    if (calcFailed) {
        logDirect("Farm failed");
        if (Baritone.settings().desktopNotifications.getValue() && Baritone.settings().notificationOnFarmFail.getValue()) {
            NotificationHelper.notify("Farm failed", true);
        }
        onLostControl();
        return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
    }
    List<Goal> goalz = new ArrayList<>();
    for (BlockPos pos : toBreak) {
        goalz.add(new BuilderProcess.GoalBreak(pos));
    }
    if (baritone.getInventoryBehavior().throwaway(false, this::isPlantable)) {
        for (BlockPos pos : openFarmland) {
            goalz.add(new GoalBlock(pos.up()));
        }
    }
    if (baritone.getInventoryBehavior().throwaway(false, this::isNetherWart)) {
        for (BlockPos pos : openSoulsand) {
            goalz.add(new GoalBlock(pos.up()));
        }
    }
    if (baritone.getInventoryBehavior().throwaway(false, this::isBoneMeal)) {
        for (BlockPos pos : bonemealable) {
            goalz.add(new GoalBlock(pos));
        }
    }
    for (Entity entity : ctx.world().loadedEntityList) {
        if (entity instanceof EntityItem && entity.onGround) {
            EntityItem ei = (EntityItem) entity;
            if (PICKUP_DROPPED.contains(ei.getItem().getItem())) {
                // +0.1 because of farmland's 0.9375 dummy height lol
                goalz.add(new GoalBlock(new BlockPos(entity.posX, entity.posY + 0.1, entity.posZ)));
            }
        }
    }
    return new PathingCommand(new GoalComposite(goalz.toArray(new Goal[0])), PathingCommandType.SET_GOAL_AND_PATH);
}
Also used : Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) GoalBlock(baritone.api.pathing.goals.GoalBlock) ArrayList(java.util.ArrayList) RayTraceResult(net.minecraft.util.math.RayTraceResult) Rotation(baritone.api.utils.Rotation) Vec3d(net.minecraft.util.math.Vec3d) GoalComposite(baritone.api.pathing.goals.GoalComposite) Goal(baritone.api.pathing.goals.Goal) PathingCommand(baritone.api.process.PathingCommand) GoalBlock(baritone.api.pathing.goals.GoalBlock) BlockPos(net.minecraft.util.math.BlockPos) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

Goal (baritone.api.pathing.goals.Goal)8 GoalComposite (baritone.api.pathing.goals.GoalComposite)8 PathingCommand (baritone.api.process.PathingCommand)6 GoalBlock (baritone.api.pathing.goals.GoalBlock)4 IBlockState (net.minecraft.block.state.IBlockState)4 BetterBlockPos (baritone.api.utils.BetterBlockPos)2 Rotation (baritone.api.utils.Rotation)2 ArrayList (java.util.ArrayList)2 Entity (net.minecraft.entity.Entity)2 EntityItem (net.minecraft.entity.item.EntityItem)2 BlockPos (net.minecraft.util.math.BlockPos)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 Vec3d (net.minecraft.util.math.Vec3d)2 BlockAir (net.minecraft.block.BlockAir)1 BlockLiquid (net.minecraft.block.BlockLiquid)1