Search in sources :

Example 1 with ISchematic

use of baritone.api.schematic.ISchematic in project Spark-Client by Spark-Client-Development.

the class BuilderProcess method onTick.

public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel, int recursions) {
    if (recursions > 1000) {
        // onTick calls itself, don't crash
        return new PathingCommand(null, PathingCommandType.SET_GOAL_AND_PATH);
    }
    approxPlaceable = approxPlaceable(36);
    if (baritone.getInputOverrideHandler().isInputForcedDown(Input.CLICK_LEFT)) {
        ticks = 5;
    } else {
        ticks--;
    }
    baritone.getInputOverrideHandler().clearAllKeys();
    if (paused) {
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    if (Baritone.settings().buildInLayers.getValue()) {
        if (realSchematic == null) {
            realSchematic = schematic;
        }
        // wrap this properly, dont just have the inner class refer to the builderprocess.this
        ISchematic realSchematic = this.realSchematic;
        int minYInclusive;
        int maxYInclusive;
        // layer = realSchematic.heightY() should be everything
        if (Baritone.settings().layerOrder.getValue()) {
            // top to bottom
            maxYInclusive = realSchematic.heightY() - 1;
            minYInclusive = realSchematic.heightY() - layer;
        } else {
            maxYInclusive = layer - 1;
            minYInclusive = 0;
        }
        schematic = new ISchematic() {

            @Override
            public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
                return realSchematic.desiredState(x, y, z, current, BuilderProcess.this.approxPlaceable);
            }

            @Override
            public boolean inSchematic(int x, int y, int z, IBlockState currentState) {
                return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive && realSchematic.inSchematic(x, y, z, currentState);
            }

            @Override
            public void reset() {
                realSchematic.reset();
            }

            @Override
            public int widthX() {
                return realSchematic.widthX();
            }

            @Override
            public int heightY() {
                return realSchematic.heightY();
            }

            @Override
            public int lengthZ() {
                return realSchematic.lengthZ();
            }
        };
    }
    BuilderCalculationContext bcc = new BuilderCalculationContext();
    if (!recalc(bcc)) {
        if (Baritone.settings().buildInLayers.getValue() && layer < realSchematic.heightY()) {
            logDirect("Starting layer " + layer);
            layer++;
            return onTick(calcFailed, isSafeToCancel, recursions + 1);
        }
        Vec3i repeat = Baritone.settings().buildRepeat.getValue();
        int max = Baritone.settings().buildRepeatCount.getValue();
        numRepeats++;
        if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) {
            logDirect("Done building");
            if (Baritone.settings().desktopNotifications.getValue() && Baritone.settings().notificationOnBuildFinished.getValue()) {
                NotificationHelper.notify("Done building", false);
            }
            onLostControl();
            return null;
        }
        // build repeat time
        layer = 0;
        origin = new BlockPos(origin).add(repeat);
        if (!Baritone.settings().buildRepeatSneaky.getValue()) {
            schematic.reset();
        }
        logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
        return onTick(calcFailed, isSafeToCancel, recursions + 1);
    }
    if (Baritone.settings().distanceTrim.getValue()) {
        trim();
    }
    Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
    if (toBreak.isPresent() && isSafeToCancel && ctx.player().onGround) {
        // we'd like to pause to break this block
        // only change look direction if it's safe (don't want to fuck up an in progress parkour for example
        Rotation rot = toBreak.get().getSecond();
        BetterBlockPos pos = toBreak.get().getFirst();
        baritone.getLookBehavior().updateTarget(rot, true);
        MovementHelper.switchToBestToolFor(ctx, bcc.get(pos));
        if (ctx.player().isSneaking()) {
            // really horrible bug where a block is visible for breaking while sneaking but not otherwise
            // so you can't see it, it goes to place something else, sneaks, then the next tick it tries to break
            // and is unable since it's unsneaked in the intermediary tick
            baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
        }
        if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot)) {
            baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    List<IBlockState> desirableOnHotbar = new ArrayList<>();
    Optional<Placement> toPlace = searchForPlaceables(bcc, desirableOnHotbar);
    if (toPlace.isPresent() && isSafeToCancel && ctx.player().onGround && ticks <= 0) {
        Rotation rot = toPlace.get().rot;
        baritone.getLookBehavior().updateTarget(rot, true);
        ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
        baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
        if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
            baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    if (Baritone.settings().allowInventory.getValue()) {
        ArrayList<Integer> usefulSlots = new ArrayList<>();
        List<IBlockState> noValidHotbarOption = new ArrayList<>();
        outer: for (IBlockState desired : desirableOnHotbar) {
            for (int i = 0; i < 9; i++) {
                if (valid(approxPlaceable.get(i), desired, true)) {
                    usefulSlots.add(i);
                    continue outer;
                }
            }
            noValidHotbarOption.add(desired);
        }
        outer: for (int i = 9; i < 36; i++) {
            for (IBlockState desired : noValidHotbarOption) {
                if (valid(approxPlaceable.get(i), desired, true)) {
                    baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
                    break outer;
                }
            }
        }
    }
    Goal goal = assemble(bcc, approxPlaceable.subList(0, 9));
    if (goal == null) {
        // we're far away, so assume that we have our whole inventory to recalculate placeable properly
        goal = assemble(bcc, approxPlaceable, true);
        if (goal == null) {
            if (Baritone.settings().skipFailedLayers.getValue() && Baritone.settings().buildInLayers.getValue() && layer < realSchematic.heightY()) {
                logDirect("Skipping layer that I cannot construct! Layer #" + layer);
                layer++;
                return onTick(calcFailed, isSafeToCancel, recursions + 1);
            }
            logDirect("Unable to do it. Pausing. resume to resume, cancel to cancel");
            paused = true;
            return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
        }
    }
    return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
}
Also used : ISchematic(baritone.api.schematic.ISchematic) IBlockState(net.minecraft.block.state.IBlockState) Rotation(baritone.api.utils.Rotation) Goal(baritone.api.pathing.goals.Goal) PathingCommand(baritone.api.process.PathingCommand) BetterBlockPos(baritone.api.utils.BetterBlockPos) PathingCommandContext(baritone.utils.PathingCommandContext) BetterBlockPos(baritone.api.utils.BetterBlockPos) Tuple(net.minecraft.util.Tuple)

Example 2 with ISchematic

use of baritone.api.schematic.ISchematic in project Spark-Client by Spark-Client-Development.

the class BuilderProcess method build.

@Override
public boolean build(String name, File schematic, Vec3i origin) {
    Optional<ISchematicFormat> format = SchematicSystem.INSTANCE.getByFile(schematic);
    if (!format.isPresent()) {
        return false;
    }
    ISchematic parsed;
    try {
        parsed = format.get().parse(new FileInputStream(schematic));
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    if (Baritone.settings().mapArtMode.getValue()) {
        parsed = new MapArtSchematic((IStaticSchematic) parsed);
    }
    build(name, parsed, origin);
    return true;
}
Also used : ISchematic(baritone.api.schematic.ISchematic) IStaticSchematic(baritone.api.schematic.IStaticSchematic) ISchematicFormat(baritone.api.schematic.format.ISchematicFormat) FileInputStream(java.io.FileInputStream) MapArtSchematic(baritone.utils.schematic.MapArtSchematic)

Example 3 with ISchematic

use of baritone.api.schematic.ISchematic in project baritone by cabaletta.

the class BuilderProcess method buildOpenSchematic.

@Override
public void buildOpenSchematic() {
    if (SchematicaHelper.isSchematicaPresent()) {
        Optional<Tuple<IStaticSchematic, BlockPos>> schematic = SchematicaHelper.getOpenSchematic();
        if (schematic.isPresent()) {
            IStaticSchematic s = schematic.get().getFirst();
            BlockPos origin = schematic.get().getSecond();
            ISchematic schem = Baritone.settings().mapArtMode.value ? new MapArtSchematic(s) : s;
            if (Baritone.settings().buildOnlySelection.value) {
                schem = new SelectionSchematic(schem, origin, baritone.getSelectionManager().getSelections());
            }
            this.build(schematic.get().getFirst().toString(), schem, origin);
        } else {
            logDirect("No schematic currently open");
        }
    } else {
        logDirect("Schematica is not present");
    }
}
Also used : ISchematic(baritone.api.schematic.ISchematic) IStaticSchematic(baritone.api.schematic.IStaticSchematic) SelectionSchematic(baritone.utils.schematic.SelectionSchematic) BetterBlockPos(baritone.api.utils.BetterBlockPos) Tuple(net.minecraft.util.Tuple) MapArtSchematic(baritone.utils.schematic.MapArtSchematic)

Example 4 with ISchematic

use of baritone.api.schematic.ISchematic in project baritone by cabaletta.

the class BuilderProcess method build.

@Override
public boolean build(String name, File schematic, Vec3i origin) {
    Optional<ISchematicFormat> format = SchematicSystem.INSTANCE.getByFile(schematic);
    if (!format.isPresent()) {
        return false;
    }
    ISchematic parsed;
    try {
        parsed = format.get().parse(new FileInputStream(schematic));
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    if (Baritone.settings().mapArtMode.value) {
        parsed = new MapArtSchematic((IStaticSchematic) parsed);
    }
    if (Baritone.settings().buildOnlySelection.value) {
        parsed = new SelectionSchematic(parsed, origin, baritone.getSelectionManager().getSelections());
    }
    build(name, parsed, origin);
    return true;
}
Also used : ISchematic(baritone.api.schematic.ISchematic) IStaticSchematic(baritone.api.schematic.IStaticSchematic) SelectionSchematic(baritone.utils.schematic.SelectionSchematic) ISchematicFormat(baritone.api.schematic.format.ISchematicFormat) FileInputStream(java.io.FileInputStream) MapArtSchematic(baritone.utils.schematic.MapArtSchematic)

Example 5 with ISchematic

use of baritone.api.schematic.ISchematic in project baritone by cabaletta.

the class BuilderProcess method onTick.

public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel, int recursions) {
    if (recursions > 1000) {
        // onTick calls itself, don't crash
        return new PathingCommand(null, PathingCommandType.SET_GOAL_AND_PATH);
    }
    approxPlaceable = approxPlaceable(36);
    if (baritone.getInputOverrideHandler().isInputForcedDown(Input.CLICK_LEFT)) {
        ticks = 5;
    } else {
        ticks--;
    }
    baritone.getInputOverrideHandler().clearAllKeys();
    if (paused) {
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    if (Baritone.settings().buildInLayers.value) {
        if (realSchematic == null) {
            realSchematic = schematic;
        }
        // wrap this properly, dont just have the inner class refer to the builderprocess.this
        ISchematic realSchematic = this.realSchematic;
        int minYInclusive;
        int maxYInclusive;
        // layer = realSchematic.heightY() should be everything
        if (Baritone.settings().layerOrder.value) {
            // top to bottom
            maxYInclusive = realSchematic.heightY() - 1;
            minYInclusive = realSchematic.heightY() - layer * Baritone.settings().layerHeight.value;
        } else {
            maxYInclusive = layer * Baritone.settings().layerHeight.value - 1;
            minYInclusive = 0;
        }
        schematic = new ISchematic() {

            @Override
            public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
                return realSchematic.desiredState(x, y, z, current, BuilderProcess.this.approxPlaceable);
            }

            @Override
            public boolean inSchematic(int x, int y, int z, IBlockState currentState) {
                return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive && realSchematic.inSchematic(x, y, z, currentState);
            }

            @Override
            public void reset() {
                realSchematic.reset();
            }

            @Override
            public int widthX() {
                return realSchematic.widthX();
            }

            @Override
            public int heightY() {
                return realSchematic.heightY();
            }

            @Override
            public int lengthZ() {
                return realSchematic.lengthZ();
            }
        };
    }
    BuilderCalculationContext bcc = new BuilderCalculationContext();
    if (!recalc(bcc)) {
        if (Baritone.settings().buildInLayers.value && layer * Baritone.settings().layerHeight.value < realSchematic.heightY()) {
            logDirect("Starting layer " + layer);
            layer++;
            return onTick(calcFailed, isSafeToCancel, recursions + 1);
        }
        Vec3i repeat = Baritone.settings().buildRepeat.value;
        int max = Baritone.settings().buildRepeatCount.value;
        numRepeats++;
        if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) {
            logDirect("Done building");
            if (Baritone.settings().notificationOnBuildFinished.value) {
                logNotification("Done building", false);
            }
            onLostControl();
            return null;
        }
        // build repeat time
        layer = 0;
        origin = new BlockPos(origin).add(repeat);
        if (!Baritone.settings().buildRepeatSneaky.value) {
            schematic.reset();
        }
        logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
        return onTick(calcFailed, isSafeToCancel, recursions + 1);
    }
    if (Baritone.settings().distanceTrim.value) {
        trim();
    }
    Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
    if (toBreak.isPresent() && isSafeToCancel && ctx.player().onGround) {
        // we'd like to pause to break this block
        // only change look direction if it's safe (don't want to fuck up an in progress parkour for example
        Rotation rot = toBreak.get().getSecond();
        BetterBlockPos pos = toBreak.get().getFirst();
        baritone.getLookBehavior().updateTarget(rot, true);
        MovementHelper.switchToBestToolFor(ctx, bcc.get(pos));
        if (ctx.player().isSneaking()) {
            // really horrible bug where a block is visible for breaking while sneaking but not otherwise
            // so you can't see it, it goes to place something else, sneaks, then the next tick it tries to break
            // and is unable since it's unsneaked in the intermediary tick
            baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
        }
        if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot)) {
            baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    List<IBlockState> desirableOnHotbar = new ArrayList<>();
    Optional<Placement> toPlace = searchForPlaceables(bcc, desirableOnHotbar);
    if (toPlace.isPresent() && isSafeToCancel && ctx.player().onGround && ticks <= 0) {
        Rotation rot = toPlace.get().rot;
        baritone.getLookBehavior().updateTarget(rot, true);
        ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
        baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
        if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
            baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    if (Baritone.settings().allowInventory.value) {
        ArrayList<Integer> usefulSlots = new ArrayList<>();
        List<IBlockState> noValidHotbarOption = new ArrayList<>();
        outer: for (IBlockState desired : desirableOnHotbar) {
            for (int i = 0; i < 9; i++) {
                if (valid(approxPlaceable.get(i), desired, true)) {
                    usefulSlots.add(i);
                    continue outer;
                }
            }
            noValidHotbarOption.add(desired);
        }
        outer: for (int i = 9; i < 36; i++) {
            for (IBlockState desired : noValidHotbarOption) {
                if (valid(approxPlaceable.get(i), desired, true)) {
                    baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
                    break outer;
                }
            }
        }
    }
    Goal goal = assemble(bcc, approxPlaceable.subList(0, 9));
    if (goal == null) {
        // we're far away, so assume that we have our whole inventory to recalculate placeable properly
        goal = assemble(bcc, approxPlaceable, true);
        if (goal == null) {
            if (Baritone.settings().skipFailedLayers.value && Baritone.settings().buildInLayers.value && layer * Baritone.settings().layerHeight.value < realSchematic.heightY()) {
                logDirect("Skipping layer that I cannot construct! Layer #" + layer);
                layer++;
                return onTick(calcFailed, isSafeToCancel, recursions + 1);
            }
            logDirect("Unable to do it. Pausing. resume to resume, cancel to cancel");
            paused = true;
            return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
        }
    }
    return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
}
Also used : ISchematic(baritone.api.schematic.ISchematic) IBlockState(net.minecraft.block.state.IBlockState) Rotation(baritone.api.utils.Rotation) Goal(baritone.api.pathing.goals.Goal) PathingCommand(baritone.api.process.PathingCommand) BetterBlockPos(baritone.api.utils.BetterBlockPos) PathingCommandContext(baritone.utils.PathingCommandContext) BetterBlockPos(baritone.api.utils.BetterBlockPos) Tuple(net.minecraft.util.Tuple)

Aggregations

ISchematic (baritone.api.schematic.ISchematic)5 IStaticSchematic (baritone.api.schematic.IStaticSchematic)3 BetterBlockPos (baritone.api.utils.BetterBlockPos)3 MapArtSchematic (baritone.utils.schematic.MapArtSchematic)3 Tuple (net.minecraft.util.Tuple)3 Goal (baritone.api.pathing.goals.Goal)2 PathingCommand (baritone.api.process.PathingCommand)2 ISchematicFormat (baritone.api.schematic.format.ISchematicFormat)2 Rotation (baritone.api.utils.Rotation)2 PathingCommandContext (baritone.utils.PathingCommandContext)2 SelectionSchematic (baritone.utils.schematic.SelectionSchematic)2 FileInputStream (java.io.FileInputStream)2 IBlockState (net.minecraft.block.state.IBlockState)2