Search in sources :

Example 26 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class PathRenderer method drawPath.

public static void drawPath(IPath path, int startIndex, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0) {
    IRenderer.startLines(color, settings.pathRenderLineWidthPixels.getValue().floatValue(), settings.renderPathIgnoreDepth.getValue());
    int fadeStart = fadeStart0 + startIndex;
    int fadeEnd = fadeEnd0 + startIndex;
    List<BetterBlockPos> positions = path.positions();
    for (int i = startIndex, next; i < positions.size() - 1; i = next) {
        BetterBlockPos start = positions.get(i);
        BetterBlockPos end = positions.get(next = i + 1);
        int dirX = end.x - start.x;
        int dirY = end.y - start.y;
        int dirZ = end.z - start.z;
        while (next + 1 < positions.size() && (!fadeOut || next + 1 < fadeStart) && (dirX == positions.get(next + 1).x - end.x && dirY == positions.get(next + 1).y - end.y && dirZ == positions.get(next + 1).z - end.z)) {
            end = positions.get(++next);
        }
        if (fadeOut) {
            float alpha;
            if (i <= fadeStart) {
                alpha = 0.4F;
            } else {
                if (i > fadeEnd) {
                    break;
                }
                alpha = 0.4F * (1.0F - (float) (i - fadeStart) / (float) (fadeEnd - fadeStart));
            }
            IRenderer.glColor(color, alpha);
        }
        drawLine(start.x, start.y, start.z, end.x, end.y, end.z);
        tessellator.draw();
    }
    IRenderer.endLines(settings.renderPathIgnoreDepth.getValue());
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 27 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class BuilderProcess method toBreakNearPlayer.

private Optional<Tuple<BetterBlockPos, Rotation>> toBreakNearPlayer(BuilderCalculationContext bcc) {
    BetterBlockPos center = ctx.playerFeet();
    BetterBlockPos pathStart = baritone.getPathingBehavior().pathStart();
    for (int dx = -5; dx <= 5; dx++) {
        for (int dy = Baritone.settings().breakFromAbove.getValue() ? -1 : 0; dy <= 5; dy++) {
            for (int dz = -5; dz <= 5; dz++) {
                int x = center.x + dx;
                int y = center.y + dy;
                int z = center.z + dz;
                if (dy == -1 && x == pathStart.x && z == pathStart.z) {
                    // dont mine what we're supported by, but not directly standing on
                    continue;
                }
                IBlockState desired = bcc.getSchematic(x, y, z, bcc.bsi.get0(x, y, z));
                if (desired == null) {
                    // irrelevant
                    continue;
                }
                IBlockState curr = bcc.bsi.get0(x, y, z);
                if (curr.getBlock() != Blocks.AIR && !(curr.getBlock() instanceof BlockLiquid) && !valid(curr, desired, false)) {
                    BetterBlockPos pos = new BetterBlockPos(x, y, z);
                    Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
                    if (rot.isPresent()) {
                        return Optional.of(new Tuple<>(pos, rot.get()));
                    }
                }
            }
        }
    }
    return Optional.empty();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BetterBlockPos(baritone.api.utils.BetterBlockPos) Rotation(baritone.api.utils.Rotation)

Example 28 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class BuilderProcess method recalcNearby.

private void recalcNearby(BuilderCalculationContext bcc) {
    BetterBlockPos center = ctx.playerFeet();
    int radius = Baritone.settings().builderTickScanRadius.getValue();
    for (int dx = -radius; dx <= radius; dx++) {
        for (int dy = -radius; dy <= radius; dy++) {
            for (int dz = -radius; dz <= radius; dz++) {
                int x = center.x + dx;
                int y = center.y + dy;
                int z = center.z + dz;
                IBlockState desired = bcc.getSchematic(x, y, z, bcc.bsi.get0(x, y, z));
                if (desired != null) {
                    // we care about this position
                    BetterBlockPos pos = new BetterBlockPos(x, y, z);
                    if (valid(bcc.bsi.get0(x, y, z), desired, false)) {
                        incorrectPositions.remove(pos);
                        observedCompleted.add(BetterBlockPos.longHash(pos));
                    } else {
                        incorrectPositions.add(pos);
                        observedCompleted.remove(BetterBlockPos.longHash(pos));
                    }
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 29 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class BuilderProcess method fullRecalc.

private void fullRecalc(BuilderCalculationContext bcc) {
    incorrectPositions = new HashSet<>();
    for (int y = 0; y < schematic.heightY(); y++) {
        for (int z = 0; z < schematic.lengthZ(); z++) {
            for (int x = 0; x < schematic.widthX(); x++) {
                int blockX = x + origin.getX();
                int blockY = y + origin.getY();
                int blockZ = z + origin.getZ();
                IBlockState current = bcc.bsi.get0(blockX, blockY, blockZ);
                if (!schematic.inSchematic(x, y, z, current)) {
                    continue;
                }
                if (bcc.bsi.worldContainsLoadedChunk(blockX, blockZ)) {
                    // we can directly observe this block, it is in render distance
                    if (valid(bcc.bsi.get0(blockX, blockY, blockZ), schematic.desiredState(x, y, z, current, this.approxPlaceable), false)) {
                        observedCompleted.add(BetterBlockPos.longHash(blockX, blockY, blockZ));
                    } else {
                        incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ));
                        observedCompleted.remove(BetterBlockPos.longHash(blockX, blockY, blockZ));
                        if (incorrectPositions.size() > Baritone.settings().incorrectSize.getValue()) {
                            return;
                        }
                    }
                    continue;
                }
                // this is not in render distance
                if (!observedCompleted.contains(BetterBlockPos.longHash(blockX, blockY, blockZ)) && !Baritone.settings().buildSkipBlocks.getValue().contains(schematic.desiredState(x, y, z, current, this.approxPlaceable).getBlock())) {
                    // and we've never seen this position be correct
                    // therefore mark as incorrect
                    incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ));
                    if (incorrectPositions.size() > Baritone.settings().incorrectSize.getValue()) {
                        return;
                    }
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 30 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class BuilderProcess method possibleToPlace.

private Optional<Placement> possibleToPlace(IBlockState toPlace, int x, int y, int z, BlockStateInterface bsi) {
    for (EnumFacing against : EnumFacing.values()) {
        BetterBlockPos placeAgainstPos = new BetterBlockPos(x, y, z).offset(against);
        IBlockState placeAgainstState = bsi.get0(placeAgainstPos);
        if (MovementHelper.isReplaceable(placeAgainstPos.x, placeAgainstPos.y, placeAgainstPos.z, placeAgainstState, bsi)) {
            continue;
        }
        if (!ctx.world().mayPlace(toPlace.getBlock(), new BetterBlockPos(x, y, z), false, against, null)) {
            continue;
        }
        AxisAlignedBB aabb = placeAgainstState.getBoundingBox(ctx.world(), placeAgainstPos);
        for (Vec3d placementMultiplier : aabbSideMultipliers(against)) {
            double placeX = placeAgainstPos.x + aabb.minX * placementMultiplier.x + aabb.maxX * (1 - placementMultiplier.x);
            double placeY = placeAgainstPos.y + aabb.minY * placementMultiplier.y + aabb.maxY * (1 - placementMultiplier.y);
            double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z);
            Rotation rot = RotationUtils.calcRotationFromVec3d(RayTraceUtils.inferSneakingEyePosition(ctx.player()), new Vec3d(placeX, placeY, placeZ), ctx.playerRotations());
            RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance(), true);
            if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(placeAgainstPos) && result.sideHit == against.getOpposite()) {
                OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, rot);
                if (hotbar.isPresent()) {
                    return Optional.of(new Placement(hotbar.getAsInt(), placeAgainstPos, against.getOpposite(), rot));
                }
            }
        }
    }
    return Optional.empty();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BetterBlockPos(baritone.api.utils.BetterBlockPos) Rotation(baritone.api.utils.Rotation)

Aggregations

BetterBlockPos (baritone.api.utils.BetterBlockPos)57 IBlockState (net.minecraft.block.state.IBlockState)15 Goal (baritone.api.pathing.goals.Goal)14 BlockPos (net.minecraft.util.math.BlockPos)10 CommandInvalidStateException (baritone.api.command.exception.CommandInvalidStateException)9 IWaypoint (baritone.api.cache.IWaypoint)6 GoalBlock (baritone.api.pathing.goals.GoalBlock)6 Waypoint (baritone.api.cache.Waypoint)5 Rotation (baritone.api.utils.Rotation)5 EnumFacing (net.minecraft.util.EnumFacing)5 IBaritone (baritone.api.IBaritone)4 Command (baritone.api.command.Command)4 IArgConsumer (baritone.api.command.argument.IArgConsumer)4 ForBlockOptionalMeta (baritone.api.command.datatypes.ForBlockOptionalMeta)4 RelativeBlockPos (baritone.api.command.datatypes.RelativeBlockPos)4 RelativeGoal (baritone.api.command.datatypes.RelativeGoal)4 CommandException (baritone.api.command.exception.CommandException)4 CommandInvalidTypeException (baritone.api.command.exception.CommandInvalidTypeException)4 IPath (baritone.api.pathing.calc.IPath)4 PathingCommand (baritone.api.process.PathingCommand)4