approxPlaceable) {
45 | if (bom.matches(current)) {
46 | return current;
47 | }
48 | for (BlockState placeable : approxPlaceable) {
49 | if (bom.matches(placeable)) {
50 | return placeable;
51 | }
52 | }
53 | return bom.getAnyBlockState();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/api/java/baritone/api/command/IBaritoneChatControl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.api.command;
19 |
20 | import baritone.api.Settings;
21 |
22 | import java.util.UUID;
23 |
24 | /**
25 | * @author Brady
26 | * @since 9/26/2019
27 | */
28 | public interface IBaritoneChatControl {
29 |
30 | /**
31 | * In certain cases chat components need to execute commands for you. For example, the paginator automatically runs
32 | * commands when you click the forward and back arrows to show you the previous/next page.
33 | *
34 | * If the prefix is changed in the meantime, then the command will go to chat. That's no good. So here's a permanent
35 | * prefix that forces a command to run, regardless of the current prefix, chat/prefix control being enabled, etc.
36 | *
37 | * If used right (by both developers and users), it should be impossible to expose a command accidentally to the
38 | * server. As a rule of thumb, if you have a clickable chat component, always use this prefix. If you're suggesting
39 | * a command (a component that puts text into your text box, or something else), use {@link Settings#prefix}.
40 | */
41 | String FORCE_COMMAND_PREFIX = String.format("<<%s>>", UUID.randomUUID().toString());
42 | }
43 |
--------------------------------------------------------------------------------
/src/api/java/baritone/api/command/datatypes/IDatatypeFor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.api.command.datatypes;
19 |
20 | import baritone.api.command.exception.CommandException;
21 |
22 | import java.util.function.Supplier;
23 |
24 | /**
25 | * An {@link IDatatype} which acts as a {@link Supplier}, in essence. The only difference
26 | * is that it requires an {@link IDatatypeContext} to be provided due to the expectation that
27 | * implementations of {@link IDatatype} are singletons.
28 | */
29 | public interface IDatatypeFor extends IDatatype {
30 |
31 | /**
32 | * Consumes the desired amount of arguments from the specified {@link IDatatypeContext}, and
33 | * then returns the parsed value. This method will more than likely return a {@link IllegalArgumentException}
34 | * if the expected input does not conform to a parseable value. As far as a {@link CommandException} being
35 | * thrown is concerned, see the note below for specifics.
36 | *
37 | * @param ctx The context
38 | * @return The parsed data-type
39 | * @throws CommandException If there was an issue parsing using another type or arguments could not be polled.
40 | * @see IDatatypeContext
41 | */
42 | T get(IDatatypeContext ctx) throws CommandException;
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/baritone/command/defaults/GcCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.command.defaults;
19 |
20 | import baritone.api.IBaritone;
21 | import baritone.api.command.Command;
22 | import baritone.api.command.argument.IArgConsumer;
23 | import baritone.api.command.exception.CommandException;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 | import java.util.stream.Stream;
28 |
29 | public class GcCommand extends Command {
30 |
31 | public GcCommand(IBaritone baritone) {
32 | super(baritone, "gc");
33 | }
34 |
35 | @Override
36 | public void execute(String label, IArgConsumer args) throws CommandException {
37 | args.requireMax(0);
38 | System.gc();
39 | logDirect("ok called System.gc()");
40 | }
41 |
42 | @Override
43 | public Stream tabComplete(String label, IArgConsumer args) {
44 | return Stream.empty();
45 | }
46 |
47 | @Override
48 | public String getShortDesc() {
49 | return "Call System.gc()";
50 | }
51 |
52 | @Override
53 | public List getLongDesc() {
54 | return Arrays.asList(
55 | "Calls System.gc().",
56 | "",
57 | "Usage:",
58 | "> gc"
59 | );
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/baritone/utils/pathing/BetterWorldBorder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.utils.pathing;
19 |
20 | import net.minecraft.world.level.border.WorldBorder;
21 |
22 | /**
23 | * Essentially, a "rule" for the path finder, prevents proposed movements from attempting to venture
24 | * into the world border, and prevents actual movements from placing blocks in the world border.
25 | */
26 | public class BetterWorldBorder {
27 |
28 | private final double minX;
29 | private final double maxX;
30 | private final double minZ;
31 | private final double maxZ;
32 |
33 | public BetterWorldBorder(WorldBorder border) {
34 | this.minX = border.getMinX();
35 | this.maxX = border.getMaxX();
36 | this.minZ = border.getMinZ();
37 | this.maxZ = border.getMaxZ();
38 | }
39 |
40 | public boolean entirelyContains(int x, int z) {
41 | return x + 1 > minX && x < maxX && z + 1 > minZ && z < maxZ;
42 | }
43 |
44 | public boolean canPlaceAt(int x, int z) {
45 | // move it in 1 block on all sides
46 | // because we can't place a block at the very edge against a block outside the border
47 | // it won't let us right click it
48 | return x > minX && x + 1 < maxX && z > minZ && z + 1 < maxZ;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/baritone/command/defaults/ClickCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.command.defaults;
19 |
20 | import baritone.api.IBaritone;
21 | import baritone.api.command.Command;
22 | import baritone.api.command.argument.IArgConsumer;
23 | import baritone.api.command.exception.CommandException;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 | import java.util.stream.Stream;
28 |
29 | public class ClickCommand extends Command {
30 |
31 | public ClickCommand(IBaritone baritone) {
32 | super(baritone, "click");
33 | }
34 |
35 | @Override
36 | public void execute(String label, IArgConsumer args) throws CommandException {
37 | args.requireMax(0);
38 | baritone.openClick();
39 | logDirect("aight dude");
40 | }
41 |
42 | @Override
43 | public Stream tabComplete(String label, IArgConsumer args) {
44 | return Stream.empty();
45 | }
46 |
47 | @Override
48 | public String getShortDesc() {
49 | return "Open click";
50 | }
51 |
52 | @Override
53 | public List getLongDesc() {
54 | return Arrays.asList(
55 | "Opens click dude",
56 | "",
57 | "Usage:",
58 | "> click"
59 | );
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/api/java/baritone/api/schematic/mask/operator/NotMask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.api.schematic.mask.operator;
19 |
20 | import baritone.api.schematic.mask.AbstractMask;
21 | import baritone.api.schematic.mask.Mask;
22 | import baritone.api.schematic.mask.StaticMask;
23 | import net.minecraft.world.level.block.state.BlockState;
24 |
25 | /**
26 | * @author Brady
27 | */
28 | public final class NotMask extends AbstractMask {
29 |
30 | private final Mask source;
31 |
32 | public NotMask(Mask source) {
33 | super(source.widthX(), source.heightY(), source.lengthZ());
34 | this.source = source;
35 | }
36 |
37 | @Override
38 | public boolean partOfMask(int x, int y, int z, BlockState currentState) {
39 | return !this.source.partOfMask(x, y, z, currentState);
40 | }
41 |
42 | public static final class Static extends AbstractMask implements StaticMask {
43 |
44 | private final StaticMask source;
45 |
46 | public Static(StaticMask source) {
47 | super(source.widthX(), source.heightY(), source.lengthZ());
48 | this.source = source;
49 | }
50 |
51 | @Override
52 | public boolean partOfMask(int x, int y, int z) {
53 | return !this.source.partOfMask(x, y, z);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/api/java/baritone/api/pathing/goals/GoalAxis.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.api.pathing.goals;
19 |
20 | import baritone.api.BaritoneAPI;
21 |
22 | public class GoalAxis implements Goal {
23 |
24 | private static final double SQRT_2_OVER_2 = Math.sqrt(2) / 2;
25 |
26 | @Override
27 | public boolean isInGoal(int x, int y, int z) {
28 | return y == BaritoneAPI.getSettings().axisHeight.value && (x == 0 || z == 0 || Math.abs(x) == Math.abs(z));
29 | }
30 |
31 | @Override
32 | public double heuristic(int x0, int y, int z0) {
33 | int x = Math.abs(x0);
34 | int z = Math.abs(z0);
35 |
36 | int shrt = Math.min(x, z);
37 | int lng = Math.max(x, z);
38 | int diff = lng - shrt;
39 |
40 | double flatAxisDistance = Math.min(x, Math.min(z, diff * SQRT_2_OVER_2));
41 |
42 | return flatAxisDistance * BaritoneAPI.getSettings().costHeuristic.value + GoalYLevel.calculate(BaritoneAPI.getSettings().axisHeight.value, y);
43 | }
44 |
45 | @Override
46 | public boolean equals(Object o) {
47 | return o.getClass() == GoalAxis.class;
48 | }
49 |
50 | @Override
51 | public int hashCode() {
52 | return 201385781;
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return "GoalAxis";
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/api/java/baritone/api/schematic/ReplaceSchematic.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.api.schematic;
19 |
20 | import baritone.api.utils.BlockOptionalMetaLookup;
21 | import net.minecraft.world.level.block.state.BlockState;
22 |
23 | public class ReplaceSchematic extends MaskSchematic {
24 |
25 | private final BlockOptionalMetaLookup filter;
26 | private final Boolean[][][] cache;
27 |
28 | public ReplaceSchematic(ISchematic schematic, BlockOptionalMetaLookup filter) {
29 | super(schematic);
30 | this.filter = filter;
31 | this.cache = new Boolean[widthX()][heightY()][lengthZ()];
32 | }
33 |
34 | @Override
35 | public void reset() {
36 | // it's final, can't use this.cache = new Boolean[widthX()][heightY()][lengthZ()]
37 | for (int x = 0; x < cache.length; x++) {
38 | for (int y = 0; y < cache[0].length; y++) {
39 | for (int z = 0; z < cache[0][0].length; z++) {
40 | cache[x][y][z] = null;
41 | }
42 | }
43 | }
44 | }
45 |
46 | @Override
47 | protected boolean partOfMask(int x, int y, int z, BlockState currentState) {
48 | if (cache[x][y][z] == null) {
49 | cache[x][y][z] = filter.has(currentState);
50 | }
51 | return cache[x][y][z];
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/api/java/baritone/api/command/exception/ICommandException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.api.command.exception;
19 |
20 | import baritone.api.command.ICommand;
21 | import baritone.api.command.argument.ICommandArgument;
22 | import java.util.List;
23 | import net.minecraft.ChatFormatting;
24 |
25 | import static baritone.api.utils.Helper.HELPER;
26 |
27 | /**
28 | * The base for a Baritone Command Exception, checked or unchecked. Provides a
29 | * {@link #handle(ICommand, List)} method that is used to provide useful output
30 | * to the user for diagnosing issues that may have occurred during execution.
31 | *
32 | * Anything implementing this interface should be assignable to {@link Exception}.
33 | *
34 | * @author Brady
35 | * @since 9/20/2019
36 | */
37 | public interface ICommandException {
38 |
39 | /**
40 | * @return The exception details
41 | * @see Exception#getMessage()
42 | */
43 | String getMessage();
44 |
45 | /**
46 | * Called when this exception is thrown, to handle the exception.
47 | *
48 | * @param command The command that threw it.
49 | * @param args The arguments the command was called with.
50 | */
51 | default void handle(ICommand command, List args) {
52 | HELPER.logDirect(this.getMessage(), ChatFormatting.RED);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/baritone/utils/schematic/SchematicSystem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.utils.schematic;
19 |
20 | import baritone.api.command.registry.Registry;
21 | import baritone.api.schematic.ISchematicSystem;
22 | import baritone.api.schematic.format.ISchematicFormat;
23 | import baritone.utils.schematic.format.DefaultSchematicFormats;
24 |
25 | import java.io.File;
26 | import java.util.Arrays;
27 | import java.util.List;
28 | import java.util.Optional;
29 |
30 | /**
31 | * @author Brady
32 | * @since 12/24/2019
33 | */
34 | public enum SchematicSystem implements ISchematicSystem {
35 | INSTANCE;
36 |
37 | private final Registry registry = new Registry<>();
38 |
39 | SchematicSystem() {
40 | Arrays.stream(DefaultSchematicFormats.values()).forEach(this.registry::register);
41 | }
42 |
43 | @Override
44 | public Registry getRegistry() {
45 | return this.registry;
46 | }
47 |
48 | @Override
49 | public Optional getByFile(File file) {
50 | return this.registry.stream().filter(format -> format.isFileType(file)).findFirst();
51 | }
52 |
53 | @Override
54 | public List getFileExtensions() {
55 | return this.registry.stream().map(ISchematicFormat::getFileExtensions).flatMap(List::stream).toList();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/baritone/command/defaults/SchematicaCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.command.defaults;
19 |
20 | import baritone.api.IBaritone;
21 | import baritone.api.command.Command;
22 | import baritone.api.command.argument.IArgConsumer;
23 | import baritone.api.command.exception.CommandException;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 | import java.util.stream.Stream;
28 |
29 | public class SchematicaCommand extends Command {
30 |
31 | public SchematicaCommand(IBaritone baritone) {
32 | super(baritone, "schematica");
33 | }
34 |
35 | @Override
36 | public void execute(String label, IArgConsumer args) throws CommandException {
37 | args.requireMax(0);
38 | baritone.getBuilderProcess().buildOpenSchematic();
39 | }
40 |
41 | @Override
42 | public Stream tabComplete(String label, IArgConsumer args) {
43 | return Stream.empty();
44 | }
45 |
46 | @Override
47 | public String getShortDesc() {
48 | return "Builds the loaded schematic";
49 | }
50 |
51 | @Override
52 | public List getLongDesc() {
53 | return Arrays.asList(
54 | "Builds the schematic currently open in Schematica.",
55 | "",
56 | "Usage:",
57 | "> schematica"
58 | );
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/baritone/utils/PlayerMovementInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.utils;
19 |
20 | import baritone.api.utils.input.Input;
21 |
22 | public class PlayerMovementInput extends net.minecraft.client.player.Input {
23 |
24 | private final InputOverrideHandler handler;
25 |
26 | PlayerMovementInput(InputOverrideHandler handler) {
27 | this.handler = handler;
28 | }
29 |
30 | @Override
31 | public void tick(boolean p_225607_1_, float f) {
32 | this.leftImpulse = 0.0F;
33 | this.forwardImpulse = 0.0F;
34 |
35 | this.jumping = handler.isInputForcedDown(Input.JUMP); // oppa gangnam style
36 |
37 | if (this.up = handler.isInputForcedDown(Input.MOVE_FORWARD)) {
38 | this.forwardImpulse++;
39 | }
40 |
41 | if (this.down = handler.isInputForcedDown(Input.MOVE_BACK)) {
42 | this.forwardImpulse--;
43 | }
44 |
45 | if (this.left = handler.isInputForcedDown(Input.MOVE_LEFT)) {
46 | this.leftImpulse++;
47 | }
48 |
49 | if (this.right = handler.isInputForcedDown(Input.MOVE_RIGHT)) {
50 | this.leftImpulse--;
51 | }
52 |
53 | if (this.shiftKeyDown = handler.isInputForcedDown(Input.SNEAK)) {
54 | this.leftImpulse *= 0.3D;
55 | this.forwardImpulse *= 0.3D;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/baritone/command/defaults/SaveAllCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.command.defaults;
19 |
20 | import baritone.api.IBaritone;
21 | import baritone.api.command.Command;
22 | import baritone.api.command.argument.IArgConsumer;
23 | import baritone.api.command.exception.CommandException;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 | import java.util.stream.Stream;
28 |
29 | public class SaveAllCommand extends Command {
30 |
31 | public SaveAllCommand(IBaritone baritone) {
32 | super(baritone, "saveall");
33 | }
34 |
35 | @Override
36 | public void execute(String label, IArgConsumer args) throws CommandException {
37 | args.requireMax(0);
38 | ctx.worldData().getCachedWorld().save();
39 | logDirect("Saved");
40 | }
41 |
42 | @Override
43 | public Stream tabComplete(String label, IArgConsumer args) {
44 | return Stream.empty();
45 | }
46 |
47 | @Override
48 | public String getShortDesc() {
49 | return "Saves Baritone's cache for this world";
50 | }
51 |
52 | @Override
53 | public List getLongDesc() {
54 | return Arrays.asList(
55 | "The saveall command saves Baritone's world cache.",
56 | "",
57 | "Usage:",
58 | "> saveall"
59 | );
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.utils.schematic.schematica;
19 |
20 | import baritone.api.schematic.IStaticSchematic;
21 | import com.github.lunatrius.schematica.client.world.SchematicWorld;
22 | import java.util.List;
23 | import net.minecraft.core.BlockPos;
24 | import net.minecraft.world.level.block.state.BlockState;
25 |
26 | public final class SchematicAdapter implements IStaticSchematic {
27 |
28 | private final SchematicWorld schematic;
29 |
30 | public SchematicAdapter(SchematicWorld schematicWorld) {
31 | this.schematic = schematicWorld;
32 | }
33 |
34 | @Override
35 | public BlockState desiredState(int x, int y, int z, BlockState current, List approxPlaceable) {
36 | return this.getDirect(x, y, z);
37 | }
38 |
39 | @Override
40 | public BlockState getDirect(int x, int y, int z) {
41 | return this.schematic.getSchematic().getBlockState(new BlockPos(x, y, z));
42 | }
43 |
44 | @Override
45 | public int widthX() {
46 | return schematic.getSchematic().getWidth();
47 | }
48 |
49 | @Override
50 | public int heightY() {
51 | return schematic.getSchematic().getHeight();
52 | }
53 |
54 | @Override
55 | public int lengthZ() {
56 | return schematic.getSchematic().getLength();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.api.command.datatypes;
19 |
20 | import baritone.api.command.argument.IArgConsumer;
21 | import baritone.api.command.exception.CommandException;
22 | import baritone.api.pathing.goals.GoalXZ;
23 | import baritone.api.utils.BetterBlockPos;
24 | import java.util.stream.Stream;
25 | import net.minecraft.util.Mth;
26 |
27 | public enum RelativeGoalXZ implements IDatatypePost {
28 | INSTANCE;
29 |
30 | @Override
31 | public GoalXZ apply(IDatatypeContext ctx, BetterBlockPos origin) throws CommandException {
32 | if (origin == null) {
33 | origin = BetterBlockPos.ORIGIN;
34 | }
35 |
36 | final IArgConsumer consumer = ctx.getConsumer();
37 | return new GoalXZ(
38 | Mth.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.x)),
39 | Mth.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.z))
40 | );
41 | }
42 |
43 | @Override
44 | public Stream tabComplete(IDatatypeContext ctx) {
45 | final IArgConsumer consumer = ctx.getConsumer();
46 | if (consumer.hasAtMost(2)) {
47 | return consumer.tabCompleteDatatype(RelativeCoordinate.INSTANCE);
48 | }
49 | return Stream.empty();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/api/java/baritone/api/command/datatypes/EntityClassById.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.api.command.datatypes;
19 |
20 | import baritone.api.command.exception.CommandException;
21 | import baritone.api.command.helpers.TabCompleteHelper;
22 | import net.minecraft.core.registries.BuiltInRegistries;
23 | import net.minecraft.resources.ResourceLocation;
24 | import net.minecraft.world.entity.EntityType;
25 |
26 | import java.util.stream.Stream;
27 |
28 | public enum EntityClassById implements IDatatypeFor {
29 | INSTANCE;
30 |
31 | @Override
32 | public EntityType get(IDatatypeContext ctx) throws CommandException {
33 | ResourceLocation id = new ResourceLocation(ctx.getConsumer().getString());
34 | EntityType entity;
35 | if ((entity = BuiltInRegistries.ENTITY_TYPE.getOptional(id).orElse(null)) == null) {
36 | throw new IllegalArgumentException("no entity found by that id");
37 | }
38 | return entity;
39 | }
40 |
41 | @Override
42 | public Stream tabComplete(IDatatypeContext ctx) throws CommandException {
43 | return new TabCompleteHelper()
44 | .append(BuiltInRegistries.ENTITY_TYPE.stream().map(Object::toString))
45 | .filterPrefixNamespaced(ctx.getConsumer().getString())
46 | .sortAlphabetically()
47 | .stream();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/baritone/command/defaults/ReloadAllCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.command.defaults;
19 |
20 | import baritone.api.IBaritone;
21 | import baritone.api.command.Command;
22 | import baritone.api.command.argument.IArgConsumer;
23 | import baritone.api.command.exception.CommandException;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 | import java.util.stream.Stream;
28 |
29 | public class ReloadAllCommand extends Command {
30 |
31 | public ReloadAllCommand(IBaritone baritone) {
32 | super(baritone, "reloadall");
33 | }
34 |
35 | @Override
36 | public void execute(String label, IArgConsumer args) throws CommandException {
37 | args.requireMax(0);
38 | ctx.worldData().getCachedWorld().reloadAllFromDisk();
39 | logDirect("Reloaded");
40 | }
41 |
42 | @Override
43 | public Stream tabComplete(String label, IArgConsumer args) {
44 | return Stream.empty();
45 | }
46 |
47 | @Override
48 | public String getShortDesc() {
49 | return "Reloads Baritone's cache for this world";
50 | }
51 |
52 | @Override
53 | public List getLongDesc() {
54 | return Arrays.asList(
55 | "The reloadall command reloads Baritone's world cache.",
56 | "",
57 | "Usage:",
58 | "> reloadall"
59 | );
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/baritone/process/elytra/NetherPath.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.process.elytra;
19 |
20 | import baritone.api.utils.BetterBlockPos;
21 | import net.minecraft.world.phys.Vec3;
22 |
23 | import java.util.AbstractList;
24 | import java.util.Collections;
25 | import java.util.List;
26 |
27 | /**
28 | * @author Brady
29 | */
30 | public final class NetherPath extends AbstractList {
31 |
32 | private static final NetherPath EMPTY_PATH = new NetherPath(Collections.emptyList());
33 |
34 | private final List backing;
35 |
36 | NetherPath(List backing) {
37 | this.backing = backing;
38 | }
39 |
40 | @Override
41 | public BetterBlockPos get(int index) {
42 | return this.backing.get(index);
43 | }
44 |
45 | @Override
46 | public int size() {
47 | return this.backing.size();
48 | }
49 |
50 | /**
51 | * @return The last position in the path, or {@code null} if empty
52 | */
53 | public BetterBlockPos getLast() {
54 | return this.isEmpty() ? null : this.backing.get(this.backing.size() - 1);
55 | }
56 |
57 | public Vec3 getVec(int index) {
58 | final BetterBlockPos pos = this.get(index);
59 | return new Vec3(pos.x, pos.y, pos.z);
60 | }
61 |
62 | public static NetherPath emptyPath() {
63 | return EMPTY_PATH;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.pathing.goals;
19 |
20 | import baritone.api.pathing.goals.GoalGetToBlock;
21 | import org.junit.Test;
22 |
23 | import java.util.ArrayList;
24 | import java.util.Arrays;
25 | import java.util.List;
26 | import net.minecraft.core.BlockPos;
27 |
28 | import static org.junit.Assert.assertTrue;
29 |
30 | public class GoalGetToBlockTest {
31 |
32 | @Test
33 | public void isInGoal() {
34 | List acceptableOffsets = new ArrayList<>(Arrays.asList("0,0,0", "0,0,1", "0,0,-1", "1,0,0", "-1,0,0", "0,-1,1", "0,-1,-1", "1,-1,0", "-1,-1,0", "0,1,0", "0,-1,0", "0,-2,0"));
35 | for (int x = -10; x <= 10; x++) {
36 | for (int y = -10; y <= 10; y++) {
37 | for (int z = -10; z <= 10; z++) {
38 | boolean inGoal = new GoalGetToBlock(new BlockPos(0, 0, 0)).isInGoal(new BlockPos(x, y, z));
39 | String repr = x + "," + y + "," + z;
40 | System.out.println(repr + " " + inGoal);
41 | if (inGoal) {
42 | assertTrue(repr, acceptableOffsets.contains(repr));
43 | acceptableOffsets.remove(repr);
44 | }
45 | }
46 | }
47 | }
48 | assertTrue(acceptableOffsets.toString(), acceptableOffsets.isEmpty());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/api/java/baritone/api/event/events/BlockInteractEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.api.event.events;
19 |
20 | import net.minecraft.core.BlockPos;
21 |
22 | /**
23 | * Called when the local player interacts with a block, can be either {@link Type#START_BREAK} or {@link Type#USE}.
24 | *
25 | * @author Brady
26 | * @since 8/22/2018
27 | */
28 | public final class BlockInteractEvent {
29 |
30 | /**
31 | * The position of the block interacted with
32 | */
33 | private final BlockPos pos;
34 |
35 | /**
36 | * The type of interaction that occurred
37 | */
38 | private final Type type;
39 |
40 | public BlockInteractEvent(BlockPos pos, Type type) {
41 | this.pos = pos;
42 | this.type = type;
43 | }
44 |
45 | /**
46 | * @return The position of the block interacted with
47 | */
48 | public final BlockPos getPos() {
49 | return this.pos;
50 | }
51 |
52 | /**
53 | * @return The type of interaction with the target block
54 | */
55 | public final Type getType() {
56 | return this.type;
57 | }
58 |
59 | public enum Type {
60 |
61 | /**
62 | * We're starting to break the target block.
63 | */
64 | START_BREAK,
65 |
66 | /**
67 | * We're right clicking on the target block. Either placing or interacting with.
68 | */
69 | USE
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/baritone/utils/schematic/StaticSchematic.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Baritone.
3 | *
4 | * Baritone is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Baritone is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with Baritone. If not, see .
16 | */
17 |
18 | package baritone.utils.schematic;
19 |
20 | import baritone.api.schematic.AbstractSchematic;
21 | import baritone.api.schematic.IStaticSchematic;
22 | import java.util.List;
23 | import net.minecraft.world.level.block.state.BlockState;
24 |
25 | /**
26 | * Default implementation of {@link IStaticSchematic}
27 | *
28 | * @author Brady
29 | * @since 12/23/2019
30 | */
31 | public class StaticSchematic extends AbstractSchematic implements IStaticSchematic {
32 |
33 | protected BlockState[][][] states;
34 |
35 | public StaticSchematic() {}
36 |
37 | public StaticSchematic(BlockState[][][] states) {
38 | this.states = states;
39 | boolean empty = states.length == 0 || states[0].length == 0 || states[0][0].length == 0;
40 | this.x = empty ? 0 : states.length;
41 | this.z = empty ? 0 : states[0].length;
42 | this.y = empty ? 0 : states[0][0].length;
43 | }
44 |
45 | @Override
46 | public BlockState desiredState(int x, int y, int z, BlockState current, List approxPlaceable) {
47 | return this.states[x][z][y];
48 | }
49 |
50 | @Override
51 | public BlockState getDirect(int x, int y, int z) {
52 | return this.states[x][z][y];
53 | }
54 |
55 | @Override
56 | public BlockState[] getColumn(int x, int z) {
57 | return this.states[x][z];
58 | }
59 | }
60 |
--------------------------------------------------------------------------------