From 0d14bde5839887990236966bd5f09d46841c373f Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 7 Jun 2023 16:31:52 -0500 Subject: [PATCH 01/35] Working sphere/cylinder build commands for `#sel` --- .../api/schematic/CylinderSchematic.java | 50 ++++++++++++++++ .../api/schematic/SphereSchematic.java | 54 ++++++++++++++++++ .../baritone/command/defaults/SelCommand.java | 57 +++++++++++++++---- 3 files changed, 151 insertions(+), 10 deletions(-) create mode 100644 src/api/java/baritone/api/schematic/CylinderSchematic.java create mode 100644 src/api/java/baritone/api/schematic/SphereSchematic.java diff --git a/src/api/java/baritone/api/schematic/CylinderSchematic.java b/src/api/java/baritone/api/schematic/CylinderSchematic.java new file mode 100644 index 000000000..3ba8bc9b8 --- /dev/null +++ b/src/api/java/baritone/api/schematic/CylinderSchematic.java @@ -0,0 +1,50 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic; + +import net.minecraft.block.state.IBlockState; + +/** + * @author Brady + */ +public class CylinderSchematic extends MaskSchematic { + + private final double cx, cz, rx, rz; + private final boolean filled; + + public CylinderSchematic(ISchematic schematic, boolean filled) { + super(schematic); + this.cx = schematic.widthX() / 2.0; + this.cz = schematic.lengthZ() / 2.0; + this.rx = this.cx * this.cx; + this.rz = this.cz * this.cz; + this.filled = filled; + } + + @Override + protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { + double dx = Math.abs((x + 0.5) - this.cx); + double dz = Math.abs((z + 0.5) - this.cz); + return !this.outside(dx, dz) + && (this.filled || outside(dx + 1, dz) || outside(dx, dz + 1)); + } + + private boolean outside(double dx, double dz) { + return dx * dx / this.rx + dz * dz / this.rz > 1; + } +} diff --git a/src/api/java/baritone/api/schematic/SphereSchematic.java b/src/api/java/baritone/api/schematic/SphereSchematic.java new file mode 100644 index 000000000..0ca987760 --- /dev/null +++ b/src/api/java/baritone/api/schematic/SphereSchematic.java @@ -0,0 +1,54 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.Vec3d; + +/** + * @author Brady + */ +public class SphereSchematic extends MaskSchematic { + + private final double cx, cy, cz, rx, ry, rz; + private final boolean filled; + + public SphereSchematic(ISchematic schematic, boolean filled) { + super(schematic); + this.cx = schematic.widthX() / 2.0; + this.cy = schematic.heightY() / 2.0; + this.cz = schematic.lengthZ() / 2.0; + this.rx = this.cx * this.cx; + this.ry = this.cy * this.cy; + this.rz = this.cz * this.cz; + this.filled = filled; + } + + @Override + protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { + double dx = Math.abs((x + 0.5) - this.cx); + double dy = Math.abs((y + 0.5) - this.cy); + double dz = Math.abs((z + 0.5) - this.cz); + return !this.outside(dx, dy, dz) + && (this.filled || outside(dx + 1, dy, dz) || outside(dx, dy + 1, dz) || outside(dx, dy, dz + 1)); + } + + private boolean outside(double dx,double dy, double dz) { + return dx * dx / this.rx + dy * dy / this.ry + dz * dz / this.rz > 1; + } +} diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index 5677eec3c..dcdd05b74 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -117,7 +117,7 @@ public class SelCommand extends Command { logDirect("Undid pos2"); } } - } else if (action == Action.SET || action == Action.WALLS || action == Action.SHELL || action == Action.CLEARAREA || action == Action.REPLACE) { + } else if (action.isFillAction()) { BlockOptionalMeta type = action == Action.CLEARAREA ? new BlockOptionalMeta(Blocks.AIR) : args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE); @@ -151,14 +151,10 @@ public class SelCommand extends Command { for (ISelection selection : selections) { Vec3i size = selection.size(); BetterBlockPos min = selection.min(); - ISchematic schematic = new FillSchematic(size.getX(), size.getY(), size.getZ(), type); - if (action == Action.WALLS) { - schematic = new WallsSchematic(schematic); - } else if (action == Action.SHELL) { - schematic = new ShellSchematic(schematic); - } else if (action == Action.REPLACE) { - schematic = new ReplaceSchematic(schematic, replaces); - } + ISchematic schematic = action.createFillMask( + new FillSchematic(size.getX(), size.getY(), size.getZ(), type), + replaces + ); composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z); } baritone.getBuilderProcess().build("Fill", composite, origin); @@ -254,7 +250,7 @@ public class SelCommand extends Command { if (args.hasAtMost(3)) { return args.tabCompleteDatatype(RelativeBlockPos.INSTANCE); } - } else if (action == Action.SET || action == Action.WALLS || action == Action.CLEARAREA || action == Action.REPLACE) { + } else if (action.isFillAction()) { if (args.hasExactlyOne() || action == Action.REPLACE) { while (args.has(2)) { args.get(); @@ -305,6 +301,10 @@ public class SelCommand extends Command { "> sel set/fill/s/f [block] - Completely fill all selections with a block.", "> sel walls/w [block] - Fill in the walls of the selection with a specified block.", "> sel shell/shl [block] - The same as walls, but fills in a ceiling and floor too.", + "> sel sphere/sph [block] - Fills the selection with a sphere bounded by the sides.", + "> sel hsphere/hsph [block] - The same as sphere, but hollow.", + "> sel cylinder/cyl [block] - Fills the selection with a cylinder bounded by the sides.", + "> sel hcylinder/hcyl [block] - The same as cylinder, but hollow.", "> sel cleararea/ca - Basically 'set air'.", "> sel replace/r - Replaces blocks with another block.", "> sel copy/cp - Copy the selected area relative to the specified or your position.", @@ -324,6 +324,10 @@ public class SelCommand extends Command { SET("set", "fill", "s", "f"), WALLS("walls", "w"), SHELL("shell", "shl"), + SPHERE("sphere", "sph"), + HSPHERE("hsphere", "hsph"), + CYLINDER("cylinder", "cyl"), + HCYLINDER("hcylinder", "hcyl"), CLEARAREA("cleararea", "ca"), REPLACE("replace", "r"), EXPAND("expand", "ex"), @@ -355,6 +359,39 @@ public class SelCommand extends Command { } return names.toArray(new String[0]); } + + public final boolean isFillAction() { + return this == SET + || this == WALLS + || this == SHELL + || this == SPHERE + || this == HSPHERE + || this == CYLINDER + || this == HCYLINDER + || this == CLEARAREA + || this == REPLACE; + } + + public final ISchematic createFillMask(ISchematic fill, BlockOptionalMetaLookup replaces) { + switch (this) { + case WALLS: + return new WallsSchematic(fill); + case SHELL: + return new ShellSchematic(fill); + case REPLACE: + return new ReplaceSchematic(fill, replaces); + case SPHERE: + return new SphereSchematic(fill, true); + case HSPHERE: + return new SphereSchematic(fill, false); + case CYLINDER: + return new CylinderSchematic(fill, true); + case HCYLINDER: + return new CylinderSchematic(fill, false); + } + // Silent fail + return fill; + } } enum TransformTarget { From 34abbfb5daced3623e9a2a17da8018042980d758 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 7 Jun 2023 17:38:26 -0500 Subject: [PATCH 02/35] appease codacy --- .../api/schematic/CylinderSchematic.java | 19 +++++++------ .../api/schematic/SphereSchematic.java | 28 +++++++++++-------- .../baritone/command/defaults/SelCommand.java | 5 ++-- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/api/java/baritone/api/schematic/CylinderSchematic.java b/src/api/java/baritone/api/schematic/CylinderSchematic.java index 3ba8bc9b8..75726348d 100644 --- a/src/api/java/baritone/api/schematic/CylinderSchematic.java +++ b/src/api/java/baritone/api/schematic/CylinderSchematic.java @@ -24,27 +24,30 @@ import net.minecraft.block.state.IBlockState; */ public class CylinderSchematic extends MaskSchematic { - private final double cx, cz, rx, rz; + private final double centerX; + private final double centerZ; + private final double radiusSqX; + private final double radiusSqZ; private final boolean filled; public CylinderSchematic(ISchematic schematic, boolean filled) { super(schematic); - this.cx = schematic.widthX() / 2.0; - this.cz = schematic.lengthZ() / 2.0; - this.rx = this.cx * this.cx; - this.rz = this.cz * this.cz; + this.centerX = schematic.widthX() / 2.0; + this.centerZ = schematic.lengthZ() / 2.0; + this.radiusSqX = this.centerX * this.centerX; + this.radiusSqZ = this.centerZ * this.centerZ; this.filled = filled; } @Override protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { - double dx = Math.abs((x + 0.5) - this.cx); - double dz = Math.abs((z + 0.5) - this.cz); + double dx = Math.abs((x + 0.5) - this.centerX); + double dz = Math.abs((z + 0.5) - this.centerZ); return !this.outside(dx, dz) && (this.filled || outside(dx + 1, dz) || outside(dx, dz + 1)); } private boolean outside(double dx, double dz) { - return dx * dx / this.rx + dz * dz / this.rz > 1; + return dx * dx / this.radiusSqX + dz * dz / this.radiusSqZ > 1; } } diff --git a/src/api/java/baritone/api/schematic/SphereSchematic.java b/src/api/java/baritone/api/schematic/SphereSchematic.java index 0ca987760..1cf0a579f 100644 --- a/src/api/java/baritone/api/schematic/SphereSchematic.java +++ b/src/api/java/baritone/api/schematic/SphereSchematic.java @@ -18,37 +18,41 @@ package baritone.api.schematic; import net.minecraft.block.state.IBlockState; -import net.minecraft.util.math.Vec3d; /** * @author Brady */ public class SphereSchematic extends MaskSchematic { - private final double cx, cy, cz, rx, ry, rz; + private final double centerX; + private final double centerY; + private final double centerZ; + private final double radiusSqX; + private final double radiusSqY; + private final double radiusSqZ; private final boolean filled; public SphereSchematic(ISchematic schematic, boolean filled) { super(schematic); - this.cx = schematic.widthX() / 2.0; - this.cy = schematic.heightY() / 2.0; - this.cz = schematic.lengthZ() / 2.0; - this.rx = this.cx * this.cx; - this.ry = this.cy * this.cy; - this.rz = this.cz * this.cz; + this.centerX = schematic.widthX() / 2.0; + this.centerY = schematic.heightY() / 2.0; + this.centerZ = schematic.lengthZ() / 2.0; + this.radiusSqX = this.centerX * this.centerX; + this.radiusSqY = this.centerY * this.centerY; + this.radiusSqZ = this.centerZ * this.centerZ; this.filled = filled; } @Override protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { - double dx = Math.abs((x + 0.5) - this.cx); - double dy = Math.abs((y + 0.5) - this.cy); - double dz = Math.abs((z + 0.5) - this.cz); + double dx = Math.abs((x + 0.5) - this.centerX); + double dy = Math.abs((y + 0.5) - this.centerY); + double dz = Math.abs((z + 0.5) - this.centerZ); return !this.outside(dx, dy, dz) && (this.filled || outside(dx + 1, dy, dz) || outside(dx, dy + 1, dz) || outside(dx, dy, dz + 1)); } private boolean outside(double dx,double dy, double dz) { - return dx * dx / this.rx + dy * dy / this.ry + dz * dz / this.rz > 1; + return dx * dx / this.radiusSqX + dy * dy / this.radiusSqY + dz * dz / this.radiusSqZ > 1; } } diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index dcdd05b74..40df5c294 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -388,9 +388,10 @@ public class SelCommand extends Command { return new CylinderSchematic(fill, true); case HCYLINDER: return new CylinderSchematic(fill, false); + default: + // Silent fail + return fill; } - // Silent fail - return fill; } } From b6c52cd8e1fd567afdefe428876f7ed0c2a7a4e4 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 8 Jun 2023 11:52:13 -0500 Subject: [PATCH 03/35] Cache mask in a `boolean[][][]` --- .../api/schematic/CachedMaskSchematic.java | 53 +++++++++++++++++++ .../api/schematic/CylinderSchematic.java | 43 +++++++-------- .../api/schematic/SphereSchematic.java | 51 ++++++++---------- 3 files changed, 92 insertions(+), 55 deletions(-) create mode 100644 src/api/java/baritone/api/schematic/CachedMaskSchematic.java diff --git a/src/api/java/baritone/api/schematic/CachedMaskSchematic.java b/src/api/java/baritone/api/schematic/CachedMaskSchematic.java new file mode 100644 index 000000000..19bcf4e3a --- /dev/null +++ b/src/api/java/baritone/api/schematic/CachedMaskSchematic.java @@ -0,0 +1,53 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic; + +import net.minecraft.block.state.IBlockState; + +/** + * @author Brady + */ +public abstract class CachedMaskSchematic extends MaskSchematic { + + /** + * Mask array with {@code y,z,x} indexing + */ + private final boolean[][][] mask; + + public CachedMaskSchematic(ISchematic schematic, StaticMaskFunction maskFunction) { + super(schematic); + this.mask = new boolean[schematic.heightY()][schematic.lengthZ()][schematic.widthX()]; + for (int y = 0; y < schematic.heightY(); y++) { + for (int z = 0; z < schematic.lengthZ(); z++) { + for (int x = 0; x < schematic.widthX(); x++) { + this.mask[y][z][x] = maskFunction.partOfMask(x, y, z); + } + } + } + } + + @Override + protected final boolean partOfMask(int x, int y, int z, IBlockState currentState) { + return this.mask[y][z][x]; + } + + @FunctionalInterface + public interface StaticMaskFunction { + boolean partOfMask(int x, int y, int z); + } +} diff --git a/src/api/java/baritone/api/schematic/CylinderSchematic.java b/src/api/java/baritone/api/schematic/CylinderSchematic.java index 75726348d..055f12875 100644 --- a/src/api/java/baritone/api/schematic/CylinderSchematic.java +++ b/src/api/java/baritone/api/schematic/CylinderSchematic.java @@ -17,37 +17,30 @@ package baritone.api.schematic; -import net.minecraft.block.state.IBlockState; - /** * @author Brady */ -public class CylinderSchematic extends MaskSchematic { - - private final double centerX; - private final double centerZ; - private final double radiusSqX; - private final double radiusSqZ; - private final boolean filled; +public final class CylinderSchematic extends CachedMaskSchematic { public CylinderSchematic(ISchematic schematic, boolean filled) { - super(schematic); - this.centerX = schematic.widthX() / 2.0; - this.centerZ = schematic.lengthZ() / 2.0; - this.radiusSqX = this.centerX * this.centerX; - this.radiusSqZ = this.centerZ * this.centerZ; - this.filled = filled; - } + super(schematic, new StaticMaskFunction() { - @Override - protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { - double dx = Math.abs((x + 0.5) - this.centerX); - double dz = Math.abs((z + 0.5) - this.centerZ); - return !this.outside(dx, dz) - && (this.filled || outside(dx + 1, dz) || outside(dx, dz + 1)); - } + private final double centerX = schematic.widthX() / 2.0; + private final double centerZ = schematic.lengthZ() / 2.0; + private final double radiusSqX = this.centerX * this.centerX; + private final double radiusSqZ = this.centerZ * this.centerZ; - private boolean outside(double dx, double dz) { - return dx * dx / this.radiusSqX + dz * dz / this.radiusSqZ > 1; + @Override + public boolean partOfMask(int x, int y, int z) { + double dx = Math.abs((x + 0.5) - this.centerX); + double dz = Math.abs((z + 0.5) - this.centerZ); + return !this.outside(dx, dz) + && (filled || outside(dx + 1, dz) || outside(dx, dz + 1)); + } + + private boolean outside(double dx, double dz) { + return dx * dx / this.radiusSqX + dz * dz / this.radiusSqZ > 1; + } + }); } } diff --git a/src/api/java/baritone/api/schematic/SphereSchematic.java b/src/api/java/baritone/api/schematic/SphereSchematic.java index 1cf0a579f..987b87198 100644 --- a/src/api/java/baritone/api/schematic/SphereSchematic.java +++ b/src/api/java/baritone/api/schematic/SphereSchematic.java @@ -17,42 +17,33 @@ package baritone.api.schematic; -import net.minecraft.block.state.IBlockState; - /** * @author Brady */ -public class SphereSchematic extends MaskSchematic { - - private final double centerX; - private final double centerY; - private final double centerZ; - private final double radiusSqX; - private final double radiusSqY; - private final double radiusSqZ; - private final boolean filled; +public final class SphereSchematic extends CachedMaskSchematic { public SphereSchematic(ISchematic schematic, boolean filled) { - super(schematic); - this.centerX = schematic.widthX() / 2.0; - this.centerY = schematic.heightY() / 2.0; - this.centerZ = schematic.lengthZ() / 2.0; - this.radiusSqX = this.centerX * this.centerX; - this.radiusSqY = this.centerY * this.centerY; - this.radiusSqZ = this.centerZ * this.centerZ; - this.filled = filled; - } + super(schematic, new StaticMaskFunction() { - @Override - protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { - double dx = Math.abs((x + 0.5) - this.centerX); - double dy = Math.abs((y + 0.5) - this.centerY); - double dz = Math.abs((z + 0.5) - this.centerZ); - return !this.outside(dx, dy, dz) - && (this.filled || outside(dx + 1, dy, dz) || outside(dx, dy + 1, dz) || outside(dx, dy, dz + 1)); - } + private final double centerX = schematic.widthX() / 2.0; + private final double centerY = schematic.heightY() / 2.0; + private final double centerZ = schematic.lengthZ() / 2.0; + private final double radiusSqX = this.centerX * this.centerX; + private final double radiusSqY = this.centerY * this.centerY; + private final double radiusSqZ = this.centerZ * this.centerZ; - private boolean outside(double dx,double dy, double dz) { - return dx * dx / this.radiusSqX + dy * dy / this.radiusSqY + dz * dz / this.radiusSqZ > 1; + @Override + public boolean partOfMask(int x, int y, int z) { + double dx = Math.abs((x + 0.5) - this.centerX); + double dy = Math.abs((y + 0.5) - this.centerY); + double dz = Math.abs((z + 0.5) - this.centerZ); + return !this.outside(dx, dy, dz) + && (filled || outside(dx + 1, dy, dz) || outside(dx, dy + 1, dz) || outside(dx, dy, dz + 1)); + } + + private boolean outside(double dx,double dy, double dz) { + return dx * dx / this.radiusSqX + dy * dy / this.radiusSqY + dz * dz / this.radiusSqZ > 1; + } + }); } } From a1b1ef88cf4d83ca027e05e589fc46ff148be634 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 8 Jun 2023 15:46:32 -0500 Subject: [PATCH 04/35] Use a Supplier to mimic a switch expression --- .../baritone/command/defaults/SelCommand.java | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index 40df5c294..85b3e4307 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -50,6 +50,7 @@ import java.awt.*; import java.util.List; import java.util.*; import java.util.function.Function; +import java.util.function.UnaryOperator; import java.util.stream.Stream; public class SelCommand extends Command { @@ -121,7 +122,7 @@ public class SelCommand extends Command { BlockOptionalMeta type = action == Action.CLEARAREA ? new BlockOptionalMeta(Blocks.AIR) : args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE); - BlockOptionalMetaLookup replaces = null; + BlockOptionalMetaLookup replaces; if (action == Action.REPLACE) { args.requireMin(1); List replacesList = new ArrayList<>(); @@ -133,6 +134,7 @@ public class SelCommand extends Command { replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0])); } else { args.requireMax(0); + replaces = null; } ISelection[] selections = manager.getSelections(); if (selections.length == 0) { @@ -151,10 +153,31 @@ public class SelCommand extends Command { for (ISelection selection : selections) { Vec3i size = selection.size(); BetterBlockPos min = selection.min(); - ISchematic schematic = action.createFillMask( - new FillSchematic(size.getX(), size.getY(), size.getZ(), type), - replaces - ); + + // Java 8 so no switch expressions 😿 + UnaryOperator create = fill -> { + switch (action) { + case WALLS: + return new WallsSchematic(fill); + case SHELL: + return new ShellSchematic(fill); + case REPLACE: + return new ReplaceSchematic(fill, replaces); + case SPHERE: + return new SphereSchematic(fill, true); + case HSPHERE: + return new SphereSchematic(fill, false); + case CYLINDER: + return new CylinderSchematic(fill, true); + case HCYLINDER: + return new CylinderSchematic(fill, false); + default: + // Silent fail + return fill; + } + }; + + ISchematic schematic = create.apply(new FillSchematic(size.getX(), size.getY(), size.getZ(), type)); composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z); } baritone.getBuilderProcess().build("Fill", composite, origin); @@ -371,28 +394,6 @@ public class SelCommand extends Command { || this == CLEARAREA || this == REPLACE; } - - public final ISchematic createFillMask(ISchematic fill, BlockOptionalMetaLookup replaces) { - switch (this) { - case WALLS: - return new WallsSchematic(fill); - case SHELL: - return new ShellSchematic(fill); - case REPLACE: - return new ReplaceSchematic(fill, replaces); - case SPHERE: - return new SphereSchematic(fill, true); - case HSPHERE: - return new SphereSchematic(fill, false); - case CYLINDER: - return new CylinderSchematic(fill, true); - case HCYLINDER: - return new CylinderSchematic(fill, false); - default: - // Silent fail - return fill; - } - } } enum TransformTarget { From 26574b4a9b23a67d1555b8717a084bcca51503b8 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 8 Jun 2023 16:32:33 -0500 Subject: [PATCH 05/35] Add optional axis parameter for `#sel cyl` --- .../api/command/datatypes/ForAxis.java | 43 +++++++++++++++++++ .../api/schematic/CylinderSchematic.java | 32 +++++++++----- .../baritone/command/defaults/SelCommand.java | 25 ++++++++--- 3 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 src/api/java/baritone/api/command/datatypes/ForAxis.java diff --git a/src/api/java/baritone/api/command/datatypes/ForAxis.java b/src/api/java/baritone/api/command/datatypes/ForAxis.java new file mode 100644 index 000000000..48efb39b7 --- /dev/null +++ b/src/api/java/baritone/api/command/datatypes/ForAxis.java @@ -0,0 +1,43 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.command.datatypes; + +import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.TabCompleteHelper; +import net.minecraft.util.EnumFacing; + +import java.util.Locale; +import java.util.stream.Stream; + +public enum ForAxis implements IDatatypeFor { + INSTANCE; + + @Override + public EnumFacing.Axis get(IDatatypeContext ctx) throws CommandException { + return EnumFacing.Axis.valueOf(ctx.getConsumer().getString().toUpperCase(Locale.US)); + } + + @Override + public Stream tabComplete(IDatatypeContext ctx) throws CommandException { + return new TabCompleteHelper() + .append(Stream.of(EnumFacing.Axis.values()) + .map(EnumFacing.Axis::getName).map(String::toLowerCase)) + .filterPrefix(ctx.getConsumer().getString()) + .stream(); + } +} diff --git a/src/api/java/baritone/api/schematic/CylinderSchematic.java b/src/api/java/baritone/api/schematic/CylinderSchematic.java index 055f12875..342c6e373 100644 --- a/src/api/java/baritone/api/schematic/CylinderSchematic.java +++ b/src/api/java/baritone/api/schematic/CylinderSchematic.java @@ -17,29 +17,39 @@ package baritone.api.schematic; +import net.minecraft.util.EnumFacing; + /** * @author Brady */ public final class CylinderSchematic extends CachedMaskSchematic { - public CylinderSchematic(ISchematic schematic, boolean filled) { + public CylinderSchematic(ISchematic schematic, boolean filled, EnumFacing.Axis alignment) { super(schematic, new StaticMaskFunction() { - private final double centerX = schematic.widthX() / 2.0; - private final double centerZ = schematic.lengthZ() / 2.0; - private final double radiusSqX = this.centerX * this.centerX; - private final double radiusSqZ = this.centerZ * this.centerZ; + private final double centerA = this.getA(schematic.widthX(), schematic.heightY()) / 2.0; + private final double centerB = this.getB(schematic.heightY(), schematic.lengthZ()) / 2.0; + private final double radiusSqA = this.centerA * this.centerA; + private final double radiusSqB = this.centerB * this.centerB; @Override public boolean partOfMask(int x, int y, int z) { - double dx = Math.abs((x + 0.5) - this.centerX); - double dz = Math.abs((z + 0.5) - this.centerZ); - return !this.outside(dx, dz) - && (filled || outside(dx + 1, dz) || outside(dx, dz + 1)); + double da = Math.abs((this.getA(x, y) + 0.5) - this.centerA); + double db = Math.abs((this.getB(y, z) + 0.5) - this.centerB); + return !this.outside(da, db) + && (filled || outside(da + 1, db) || outside(da, db + 1)); } - private boolean outside(double dx, double dz) { - return dx * dx / this.radiusSqX + dz * dz / this.radiusSqZ > 1; + private boolean outside(double da, double db) { + return da * da / this.radiusSqA + db * db / this.radiusSqB > 1; + } + + private int getA(int x, int y) { + return alignment == EnumFacing.Axis.X ? y : x; + } + + private int getB(int y, int z) { + return alignment == EnumFacing.Axis.Z ? y : z; } }); } diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index 85b3e4307..72c5cd1c0 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -21,6 +21,7 @@ import baritone.Baritone; import baritone.api.IBaritone; import baritone.api.command.Command; import baritone.api.command.argument.IArgConsumer; +import baritone.api.command.datatypes.ForAxis; import baritone.api.command.datatypes.ForBlockOptionalMeta; import baritone.api.command.datatypes.ForEnumFacing; import baritone.api.command.datatypes.RelativeBlockPos; @@ -122,7 +123,9 @@ public class SelCommand extends Command { BlockOptionalMeta type = action == Action.CLEARAREA ? new BlockOptionalMeta(Blocks.AIR) : args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE); - BlockOptionalMetaLookup replaces; + + final BlockOptionalMetaLookup replaces; // Action.REPLACE + final EnumFacing.Axis alignment; // Action.(H)CYLINDER if (action == Action.REPLACE) { args.requireMin(1); List replacesList = new ArrayList<>(); @@ -132,9 +135,15 @@ public class SelCommand extends Command { } type = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE); replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0])); + alignment = null; + } else if (action == Action.CYLINDER || action == Action.HCYLINDER) { + args.requireMax(1); + alignment = args.hasAny() ? args.getDatatypeFor(ForAxis.INSTANCE) : EnumFacing.Axis.Y; + replaces = null; } else { args.requireMax(0); replaces = null; + alignment = null; } ISelection[] selections = manager.getSelections(); if (selections.length == 0) { @@ -168,9 +177,9 @@ public class SelCommand extends Command { case HSPHERE: return new SphereSchematic(fill, false); case CYLINDER: - return new CylinderSchematic(fill, true); + return new CylinderSchematic(fill, true, alignment); case HCYLINDER: - return new CylinderSchematic(fill, false); + return new CylinderSchematic(fill, false, alignment); default: // Silent fail return fill; @@ -279,6 +288,12 @@ public class SelCommand extends Command { args.get(); } return args.tabCompleteDatatype(ForBlockOptionalMeta.INSTANCE); + } else if (action == Action.CYLINDER || action == Action.HCYLINDER) { + if (args.hasExactly(2)) { + if (args.getDatatypeForOrNull(ForBlockOptionalMeta.INSTANCE) != null) { + return args.tabCompleteDatatype(ForAxis.INSTANCE); + } + } } } else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) { if (args.hasExactlyOne()) { @@ -326,8 +341,8 @@ public class SelCommand extends Command { "> sel shell/shl [block] - The same as walls, but fills in a ceiling and floor too.", "> sel sphere/sph [block] - Fills the selection with a sphere bounded by the sides.", "> sel hsphere/hsph [block] - The same as sphere, but hollow.", - "> sel cylinder/cyl [block] - Fills the selection with a cylinder bounded by the sides.", - "> sel hcylinder/hcyl [block] - The same as cylinder, but hollow.", + "> sel cylinder/cyl [block] - Fills the selection with a cylinder bounded by the sides, oriented about the given axis. (default=y)", + "> sel hcylinder/hcyl [block] - The same as cylinder, but hollow.", "> sel cleararea/ca - Basically 'set air'.", "> sel replace/r - Replaces blocks with another block.", "> sel copy/cp - Copy the selected area relative to the specified or your position.", From f232bbdb15cb6a07296b1a093a1213794e051e25 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 8 Jun 2023 16:36:32 -0500 Subject: [PATCH 06/35] Clean up formatting --- .../baritone/api/schematic/CylinderSchematic.java | 8 ++++++-- .../java/baritone/api/schematic/SphereSchematic.java | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/api/java/baritone/api/schematic/CylinderSchematic.java b/src/api/java/baritone/api/schematic/CylinderSchematic.java index 342c6e373..29b5aa5b3 100644 --- a/src/api/java/baritone/api/schematic/CylinderSchematic.java +++ b/src/api/java/baritone/api/schematic/CylinderSchematic.java @@ -36,8 +36,12 @@ public final class CylinderSchematic extends CachedMaskSchematic { public boolean partOfMask(int x, int y, int z) { double da = Math.abs((this.getA(x, y) + 0.5) - this.centerA); double db = Math.abs((this.getB(y, z) + 0.5) - this.centerB); - return !this.outside(da, db) - && (filled || outside(da + 1, db) || outside(da, db + 1)); + if (this.outside(da, db)) { + return false; + } + return filled + || this.outside(da + 1, db) + || this.outside(da, db + 1); } private boolean outside(double da, double db) { diff --git a/src/api/java/baritone/api/schematic/SphereSchematic.java b/src/api/java/baritone/api/schematic/SphereSchematic.java index 987b87198..074e6ec51 100644 --- a/src/api/java/baritone/api/schematic/SphereSchematic.java +++ b/src/api/java/baritone/api/schematic/SphereSchematic.java @@ -37,11 +37,16 @@ public final class SphereSchematic extends CachedMaskSchematic { double dx = Math.abs((x + 0.5) - this.centerX); double dy = Math.abs((y + 0.5) - this.centerY); double dz = Math.abs((z + 0.5) - this.centerZ); - return !this.outside(dx, dy, dz) - && (filled || outside(dx + 1, dy, dz) || outside(dx, dy + 1, dz) || outside(dx, dy, dz + 1)); + if (this.outside(dx, dy, dz)) { + return false; + } + return filled + || this.outside(dx + 1, dy, dz) + || this.outside(dx, dy + 1, dz) + || this.outside(dx, dy, dz + 1); } - private boolean outside(double dx,double dy, double dz) { + private boolean outside(double dx, double dy, double dz) { return dx * dx / this.radiusSqX + dy * dy / this.radiusSqY + dz * dz / this.radiusSqZ > 1; } }); From 9729e63d980ace7038f2a79f78805b1fa21cc6c9 Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 9 Jun 2023 17:25:29 -0500 Subject: [PATCH 07/35] Create and utilize new `Mask` type Added factory method to `MaskSchematic` for creation using a `Mask` Sort-of mocks the schematic structure, without the block states ofc --- .../api/schematic/CachedMaskSchematic.java | 53 -------------- .../api/schematic/CylinderSchematic.java | 60 ---------------- .../baritone/api/schematic/MaskSchematic.java | 11 +++ .../api/schematic/SphereSchematic.java | 54 --------------- .../api/schematic/mask/AbstractMask.java | 49 +++++++++++++ .../baritone/api/schematic/mask/Mask.java | 41 +++++++++++ .../api/schematic/mask/PreComputedMask.java | 44 ++++++++++++ .../api/schematic/mask/StaticMask.java | 62 +++++++++++++++++ .../schematic/mask/shape/CylinderMask.java | 69 +++++++++++++++++++ .../api/schematic/mask/shape/SphereMask.java | 64 +++++++++++++++++ .../baritone/command/defaults/SelCommand.java | 10 +-- 11 files changed, 346 insertions(+), 171 deletions(-) delete mode 100644 src/api/java/baritone/api/schematic/CachedMaskSchematic.java delete mode 100644 src/api/java/baritone/api/schematic/CylinderSchematic.java delete mode 100644 src/api/java/baritone/api/schematic/SphereSchematic.java create mode 100644 src/api/java/baritone/api/schematic/mask/AbstractMask.java create mode 100644 src/api/java/baritone/api/schematic/mask/Mask.java create mode 100644 src/api/java/baritone/api/schematic/mask/PreComputedMask.java create mode 100644 src/api/java/baritone/api/schematic/mask/StaticMask.java create mode 100644 src/api/java/baritone/api/schematic/mask/shape/CylinderMask.java create mode 100644 src/api/java/baritone/api/schematic/mask/shape/SphereMask.java diff --git a/src/api/java/baritone/api/schematic/CachedMaskSchematic.java b/src/api/java/baritone/api/schematic/CachedMaskSchematic.java deleted file mode 100644 index 19bcf4e3a..000000000 --- a/src/api/java/baritone/api/schematic/CachedMaskSchematic.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.schematic; - -import net.minecraft.block.state.IBlockState; - -/** - * @author Brady - */ -public abstract class CachedMaskSchematic extends MaskSchematic { - - /** - * Mask array with {@code y,z,x} indexing - */ - private final boolean[][][] mask; - - public CachedMaskSchematic(ISchematic schematic, StaticMaskFunction maskFunction) { - super(schematic); - this.mask = new boolean[schematic.heightY()][schematic.lengthZ()][schematic.widthX()]; - for (int y = 0; y < schematic.heightY(); y++) { - for (int z = 0; z < schematic.lengthZ(); z++) { - for (int x = 0; x < schematic.widthX(); x++) { - this.mask[y][z][x] = maskFunction.partOfMask(x, y, z); - } - } - } - } - - @Override - protected final boolean partOfMask(int x, int y, int z, IBlockState currentState) { - return this.mask[y][z][x]; - } - - @FunctionalInterface - public interface StaticMaskFunction { - boolean partOfMask(int x, int y, int z); - } -} diff --git a/src/api/java/baritone/api/schematic/CylinderSchematic.java b/src/api/java/baritone/api/schematic/CylinderSchematic.java deleted file mode 100644 index 29b5aa5b3..000000000 --- a/src/api/java/baritone/api/schematic/CylinderSchematic.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.schematic; - -import net.minecraft.util.EnumFacing; - -/** - * @author Brady - */ -public final class CylinderSchematic extends CachedMaskSchematic { - - public CylinderSchematic(ISchematic schematic, boolean filled, EnumFacing.Axis alignment) { - super(schematic, new StaticMaskFunction() { - - private final double centerA = this.getA(schematic.widthX(), schematic.heightY()) / 2.0; - private final double centerB = this.getB(schematic.heightY(), schematic.lengthZ()) / 2.0; - private final double radiusSqA = this.centerA * this.centerA; - private final double radiusSqB = this.centerB * this.centerB; - - @Override - public boolean partOfMask(int x, int y, int z) { - double da = Math.abs((this.getA(x, y) + 0.5) - this.centerA); - double db = Math.abs((this.getB(y, z) + 0.5) - this.centerB); - if (this.outside(da, db)) { - return false; - } - return filled - || this.outside(da + 1, db) - || this.outside(da, db + 1); - } - - private boolean outside(double da, double db) { - return da * da / this.radiusSqA + db * db / this.radiusSqB > 1; - } - - private int getA(int x, int y) { - return alignment == EnumFacing.Axis.X ? y : x; - } - - private int getB(int y, int z) { - return alignment == EnumFacing.Axis.Z ? y : z; - } - }); - } -} diff --git a/src/api/java/baritone/api/schematic/MaskSchematic.java b/src/api/java/baritone/api/schematic/MaskSchematic.java index 229f58d5b..2853c6e58 100644 --- a/src/api/java/baritone/api/schematic/MaskSchematic.java +++ b/src/api/java/baritone/api/schematic/MaskSchematic.java @@ -17,6 +17,7 @@ package baritone.api.schematic; +import baritone.api.schematic.mask.Mask; import net.minecraft.block.state.IBlockState; import java.util.List; @@ -41,4 +42,14 @@ public abstract class MaskSchematic extends AbstractSchematic { public IBlockState desiredState(int x, int y, int z, IBlockState current, List approxPlaceable) { return schematic.desiredState(x, y, z, current, approxPlaceable); } + + public static MaskSchematic create(ISchematic schematic, Mask function) { + return new MaskSchematic(schematic) { + + @Override + protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { + return function.partOfMask(x, y, z, currentState); + } + }; + } } diff --git a/src/api/java/baritone/api/schematic/SphereSchematic.java b/src/api/java/baritone/api/schematic/SphereSchematic.java deleted file mode 100644 index 074e6ec51..000000000 --- a/src/api/java/baritone/api/schematic/SphereSchematic.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.schematic; - -/** - * @author Brady - */ -public final class SphereSchematic extends CachedMaskSchematic { - - public SphereSchematic(ISchematic schematic, boolean filled) { - super(schematic, new StaticMaskFunction() { - - private final double centerX = schematic.widthX() / 2.0; - private final double centerY = schematic.heightY() / 2.0; - private final double centerZ = schematic.lengthZ() / 2.0; - private final double radiusSqX = this.centerX * this.centerX; - private final double radiusSqY = this.centerY * this.centerY; - private final double radiusSqZ = this.centerZ * this.centerZ; - - @Override - public boolean partOfMask(int x, int y, int z) { - double dx = Math.abs((x + 0.5) - this.centerX); - double dy = Math.abs((y + 0.5) - this.centerY); - double dz = Math.abs((z + 0.5) - this.centerZ); - if (this.outside(dx, dy, dz)) { - return false; - } - return filled - || this.outside(dx + 1, dy, dz) - || this.outside(dx, dy + 1, dz) - || this.outside(dx, dy, dz + 1); - } - - private boolean outside(double dx, double dy, double dz) { - return dx * dx / this.radiusSqX + dy * dy / this.radiusSqY + dz * dz / this.radiusSqZ > 1; - } - }); - } -} diff --git a/src/api/java/baritone/api/schematic/mask/AbstractMask.java b/src/api/java/baritone/api/schematic/mask/AbstractMask.java new file mode 100644 index 000000000..ce92af0ec --- /dev/null +++ b/src/api/java/baritone/api/schematic/mask/AbstractMask.java @@ -0,0 +1,49 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic.mask; + +/** + * @author Brady + */ +public abstract class AbstractMask implements Mask { + + private final int widthX; + private final int heightY; + private final int lengthZ; + + public AbstractMask(int widthX, int heightY, int lengthZ) { + this.widthX = widthX; + this.heightY = heightY; + this.lengthZ = lengthZ; + } + + @Override + public int widthX() { + return this.widthX; + } + + @Override + public int heightY() { + return this.heightY; + } + + @Override + public int lengthZ() { + return this.lengthZ; + } +} diff --git a/src/api/java/baritone/api/schematic/mask/Mask.java b/src/api/java/baritone/api/schematic/mask/Mask.java new file mode 100644 index 000000000..540c2cee1 --- /dev/null +++ b/src/api/java/baritone/api/schematic/mask/Mask.java @@ -0,0 +1,41 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic.mask; + +import net.minecraft.block.state.IBlockState; + +/** + * @author Brady + */ +public interface Mask { + + /** + * @param x The relative x position of the block + * @param y The relative y position of the block + * @param z The relative z position of the block + * @param currentState The current state of that block in the world, may be {@code null} + * @return Whether the given position is included in this mask + */ + boolean partOfMask(int x, int y, int z, IBlockState currentState); + + int widthX(); + + int heightY(); + + int lengthZ(); +} diff --git a/src/api/java/baritone/api/schematic/mask/PreComputedMask.java b/src/api/java/baritone/api/schematic/mask/PreComputedMask.java new file mode 100644 index 000000000..aed26cc94 --- /dev/null +++ b/src/api/java/baritone/api/schematic/mask/PreComputedMask.java @@ -0,0 +1,44 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic.mask; + +/** + * @author Brady + */ +final class PreComputedMask extends AbstractMask implements StaticMask { + + private final boolean[][][] mask; + + public PreComputedMask(StaticMask mask) { + super(mask.widthX(), mask.heightY(), mask.lengthZ()); + + this.mask = new boolean[this.heightY()][this.lengthZ()][this.widthX()]; + for (int y = 0; y < this.heightY(); y++) { + for (int z = 0; z < this.lengthZ(); z++) { + for (int x = 0; x < this.widthX(); x++) { + this.mask[y][z][x] = mask.partOfMask(x, y, z); + } + } + } + } + + @Override + public boolean partOfMask(int x, int y, int z) { + return this.mask[y][z][x]; + } +} diff --git a/src/api/java/baritone/api/schematic/mask/StaticMask.java b/src/api/java/baritone/api/schematic/mask/StaticMask.java new file mode 100644 index 000000000..ef50a65cc --- /dev/null +++ b/src/api/java/baritone/api/schematic/mask/StaticMask.java @@ -0,0 +1,62 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic.mask; + +import net.minecraft.block.state.IBlockState; + +/** + * A mask that is context-free. In other words, it doesn't require the current block state to determine if a relative + * position is a part of the mask. + * + * @author Brady + */ +public interface StaticMask extends Mask { + + /** + * Determines if a given relative coordinate is included in this mask, without the need for the current block state. + * + * @param x The relative x position of the block + * @param y The relative y position of the block + * @param z The relative z position of the block + * @return Whether the given position is included in this mask + */ + boolean partOfMask(int x, int y, int z); + + /** + * Implements the parent {@link Mask#partOfMask partOfMask function} by calling the static function + * provided in this functional interface without needing the {@link IBlockState} argument. This {@code default} + * implementation should NOT be overriden. + * + * @param x The relative x position of the block + * @param y The relative y position of the block + * @param z The relative z position of the block + * @param currentState The current state of that block in the world, may be {@code null} + * @return Whether the given position is included in this mask + */ + @Override + default boolean partOfMask(int x, int y, int z, IBlockState currentState) { + return this.partOfMask(x, y, z); + } + + /** + * Returns a pre-computed mask using {@code this} function, with the specified size parameters. + */ + default StaticMask compute() { + return new PreComputedMask(this); + } +} diff --git a/src/api/java/baritone/api/schematic/mask/shape/CylinderMask.java b/src/api/java/baritone/api/schematic/mask/shape/CylinderMask.java new file mode 100644 index 000000000..71b0d43c9 --- /dev/null +++ b/src/api/java/baritone/api/schematic/mask/shape/CylinderMask.java @@ -0,0 +1,69 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic.mask.shape; + +import baritone.api.schematic.mask.AbstractMask; +import baritone.api.schematic.mask.StaticMask; +import net.minecraft.util.EnumFacing; + +/** + * @author Brady + */ +public final class CylinderMask extends AbstractMask implements StaticMask { + + private final double centerA; + private final double centerB; + private final double radiusSqA; + private final double radiusSqB; + private final boolean filled; + private final EnumFacing.Axis alignment; + + public CylinderMask(int widthX, int heightY, int lengthZ, boolean filled, EnumFacing.Axis alignment) { + super(widthX, heightY, lengthZ); + this.centerA = this.getA(widthX, heightY) / 2.0; + this.centerB = this.getB(heightY, lengthZ) / 2.0; + this.radiusSqA = (this.centerA - 1) * (this.centerA - 1); + this.radiusSqB = (this.centerB - 1) * (this.centerB - 1); + this.filled = filled; + this.alignment = alignment; + } + + @Override + public boolean partOfMask(int x, int y, int z) { + double da = Math.abs((this.getA(x, y) + 0.5) - this.centerA); + double db = Math.abs((this.getB(y, z) + 0.5) - this.centerB); + if (this.outside(da, db)) { + return false; + } + return this.filled + || this.outside(da + 1, db) + || this.outside(da, db + 1); + } + + private boolean outside(double da, double db) { + return da * da / this.radiusSqA + db * db / this.radiusSqB > 1; + } + + private int getA(int x, int y) { + return this.alignment == EnumFacing.Axis.X ? y : x; + } + + private int getB(int y, int z) { + return this.alignment == EnumFacing.Axis.Z ? y : z; + } +} diff --git a/src/api/java/baritone/api/schematic/mask/shape/SphereMask.java b/src/api/java/baritone/api/schematic/mask/shape/SphereMask.java new file mode 100644 index 000000000..d805c98a8 --- /dev/null +++ b/src/api/java/baritone/api/schematic/mask/shape/SphereMask.java @@ -0,0 +1,64 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic.mask.shape; + +import baritone.api.schematic.mask.AbstractMask; +import baritone.api.schematic.mask.StaticMask; + +/** + * @author Brady + */ +public final class SphereMask extends AbstractMask implements StaticMask { + + private final double centerX; + private final double centerY; + private final double centerZ; + private final double radiusSqX; + private final double radiusSqY; + private final double radiusSqZ; + private final boolean filled; + + public SphereMask(int widthX, int heightY, int lengthZ, boolean filled) { + super(widthX, heightY, lengthZ); + this.centerX = widthX / 2.0; + this.centerY = heightY / 2.0; + this.centerZ = lengthZ / 2.0; + this.radiusSqX = this.centerX * this.centerX; + this.radiusSqY = this.centerY * this.centerY; + this.radiusSqZ = this.centerZ * this.centerZ; + this.filled = filled; + } + + @Override + public boolean partOfMask(int x, int y, int z) { + double dx = Math.abs((x + 0.5) - this.centerX); + double dy = Math.abs((y + 0.5) - this.centerY); + double dz = Math.abs((z + 0.5) - this.centerZ); + if (this.outside(dx, dy, dz)) { + return false; + } + return this.filled + || this.outside(dx + 1, dy, dz) + || this.outside(dx, dy + 1, dz) + || this.outside(dx, dy, dz + 1); + } + + private boolean outside(double dx, double dy, double dz) { + return dx * dx / this.radiusSqX + dy * dy / this.radiusSqY + dz * dz / this.radiusSqZ > 1; + } +} diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index 72c5cd1c0..e1d2082ff 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -32,6 +32,8 @@ import baritone.api.command.helpers.TabCompleteHelper; import baritone.api.event.events.RenderEvent; import baritone.api.event.listener.AbstractGameEventListener; import baritone.api.schematic.*; +import baritone.api.schematic.mask.shape.CylinderMask; +import baritone.api.schematic.mask.shape.SphereMask; import baritone.api.selection.ISelection; import baritone.api.selection.ISelectionManager; import baritone.api.utils.BetterBlockPos; @@ -173,13 +175,13 @@ public class SelCommand extends Command { case REPLACE: return new ReplaceSchematic(fill, replaces); case SPHERE: - return new SphereSchematic(fill, true); + return MaskSchematic.create(fill, new SphereMask(size.getX(), size.getY(), size.getZ(), true).compute()); case HSPHERE: - return new SphereSchematic(fill, false); + return MaskSchematic.create(fill, new SphereMask(size.getX(), size.getY(), size.getZ(), false).compute()); case CYLINDER: - return new CylinderSchematic(fill, true, alignment); + return MaskSchematic.create(fill, new CylinderMask(size.getX(), size.getY(), size.getZ(), true, alignment).compute()); case HCYLINDER: - return new CylinderSchematic(fill, false, alignment); + return MaskSchematic.create(fill, new CylinderMask(size.getX(), size.getY(), size.getZ(), false, alignment).compute()); default: // Silent fail return fill; From 94d757104b027c121ca2bc39f658b09e10ea28a5 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Jun 2023 11:24:31 -0500 Subject: [PATCH 08/35] Clean ups --- .../java/baritone/command/defaults/SelCommand.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index e1d2082ff..0a11c86a8 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -167,6 +167,10 @@ public class SelCommand extends Command { // Java 8 so no switch expressions 😿 UnaryOperator create = fill -> { + final int w = fill.widthX(); + final int h = fill.heightY(); + final int l = fill.lengthZ(); + switch (action) { case WALLS: return new WallsSchematic(fill); @@ -175,13 +179,13 @@ public class SelCommand extends Command { case REPLACE: return new ReplaceSchematic(fill, replaces); case SPHERE: - return MaskSchematic.create(fill, new SphereMask(size.getX(), size.getY(), size.getZ(), true).compute()); + return MaskSchematic.create(fill, new SphereMask(w, h, l, true).compute()); case HSPHERE: - return MaskSchematic.create(fill, new SphereMask(size.getX(), size.getY(), size.getZ(), false).compute()); + return MaskSchematic.create(fill, new SphereMask(w, h, l, false).compute()); case CYLINDER: - return MaskSchematic.create(fill, new CylinderMask(size.getX(), size.getY(), size.getZ(), true, alignment).compute()); + return MaskSchematic.create(fill, new CylinderMask(w, h, l, true, alignment).compute()); case HCYLINDER: - return MaskSchematic.create(fill, new CylinderMask(size.getX(), size.getY(), size.getZ(), false, alignment).compute()); + return MaskSchematic.create(fill, new CylinderMask(w, h, l, false, alignment).compute()); default: // Silent fail return fill; From ffd00080f256e216238c7887c8549fd8bd8ae40f Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Jun 2023 11:27:51 -0500 Subject: [PATCH 09/35] Mask binary operators --- .../baritone/api/schematic/mask/Mask.java | 19 +++++ .../api/schematic/mask/StaticMask.java | 20 ++++++ .../mask/operator/BinaryOperatorMask.java | 71 +++++++++++++++++++ .../api/schematic/mask/operator/NotMask.java | 56 +++++++++++++++ .../api/utils/BooleanBinaryOperator.java | 27 +++++++ .../api/utils/BooleanBinaryOperators.java | 38 ++++++++++ 6 files changed, 231 insertions(+) create mode 100644 src/api/java/baritone/api/schematic/mask/operator/BinaryOperatorMask.java create mode 100644 src/api/java/baritone/api/schematic/mask/operator/NotMask.java create mode 100644 src/api/java/baritone/api/utils/BooleanBinaryOperator.java create mode 100644 src/api/java/baritone/api/utils/BooleanBinaryOperators.java diff --git a/src/api/java/baritone/api/schematic/mask/Mask.java b/src/api/java/baritone/api/schematic/mask/Mask.java index 540c2cee1..7df6f8f04 100644 --- a/src/api/java/baritone/api/schematic/mask/Mask.java +++ b/src/api/java/baritone/api/schematic/mask/Mask.java @@ -17,6 +17,9 @@ package baritone.api.schematic.mask; +import baritone.api.schematic.mask.operator.BinaryOperatorMask; +import baritone.api.schematic.mask.operator.NotMask; +import baritone.api.utils.BooleanBinaryOperators; import net.minecraft.block.state.IBlockState; /** @@ -38,4 +41,20 @@ public interface Mask { int heightY(); int lengthZ(); + + default Mask not() { + return new NotMask(this); + } + + default Mask union(Mask other) { + return new BinaryOperatorMask(this, other, BooleanBinaryOperators.OR); + } + + default Mask intersection(Mask other) { + return new BinaryOperatorMask(this, other, BooleanBinaryOperators.AND); + } + + default Mask xor(Mask other) { + return new BinaryOperatorMask(this, other, BooleanBinaryOperators.XOR); + } } diff --git a/src/api/java/baritone/api/schematic/mask/StaticMask.java b/src/api/java/baritone/api/schematic/mask/StaticMask.java index ef50a65cc..220a94828 100644 --- a/src/api/java/baritone/api/schematic/mask/StaticMask.java +++ b/src/api/java/baritone/api/schematic/mask/StaticMask.java @@ -17,6 +17,9 @@ package baritone.api.schematic.mask; +import baritone.api.schematic.mask.operator.BinaryOperatorMask; +import baritone.api.schematic.mask.operator.NotMask; +import baritone.api.utils.BooleanBinaryOperators; import net.minecraft.block.state.IBlockState; /** @@ -53,6 +56,23 @@ public interface StaticMask extends Mask { return this.partOfMask(x, y, z); } + @Override + default StaticMask not() { + return new NotMask.Static(this); + } + + default StaticMask union(StaticMask other) { + return new BinaryOperatorMask.Static(this, other, BooleanBinaryOperators.OR); + } + + default StaticMask intersection(StaticMask other) { + return new BinaryOperatorMask.Static(this, other, BooleanBinaryOperators.AND); + } + + default StaticMask xor(StaticMask other) { + return new BinaryOperatorMask.Static(this, other, BooleanBinaryOperators.XOR); + } + /** * Returns a pre-computed mask using {@code this} function, with the specified size parameters. */ diff --git a/src/api/java/baritone/api/schematic/mask/operator/BinaryOperatorMask.java b/src/api/java/baritone/api/schematic/mask/operator/BinaryOperatorMask.java new file mode 100644 index 000000000..e591c7873 --- /dev/null +++ b/src/api/java/baritone/api/schematic/mask/operator/BinaryOperatorMask.java @@ -0,0 +1,71 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic.mask.operator; + +import baritone.api.schematic.mask.AbstractMask; +import baritone.api.schematic.mask.Mask; +import baritone.api.schematic.mask.StaticMask; +import baritone.api.utils.BooleanBinaryOperator; +import net.minecraft.block.state.IBlockState; + +/** + * @author Brady + */ +public final class BinaryOperatorMask extends AbstractMask { + + private final Mask a; + private final Mask b; + private final BooleanBinaryOperator operator; + + public BinaryOperatorMask(Mask a, Mask b, BooleanBinaryOperator operator) { + super(a.widthX(), a.heightY(), a.lengthZ()); + this.a = a; + this.b = b; + this.operator = operator; + } + + @Override + public boolean partOfMask(int x, int y, int z, IBlockState currentState) { + return this.operator.applyAsBoolean( + this.a.partOfMask(x, y, z, currentState), + this.b.partOfMask(x, y, z, currentState) + ); + } + + public static final class Static extends AbstractMask implements StaticMask { + + private final StaticMask a; + private final StaticMask b; + private final BooleanBinaryOperator operator; + + public Static(StaticMask a, StaticMask b, BooleanBinaryOperator operator) { + super(a.widthX(), a.heightY(), a.lengthZ()); + this.a = a; + this.b = b; + this.operator = operator; + } + + @Override + public boolean partOfMask(int x, int y, int z) { + return this.operator.applyAsBoolean( + this.a.partOfMask(x, y, z), + this.b.partOfMask(x, y, z) + ); + } + } +} diff --git a/src/api/java/baritone/api/schematic/mask/operator/NotMask.java b/src/api/java/baritone/api/schematic/mask/operator/NotMask.java new file mode 100644 index 000000000..f9f770b82 --- /dev/null +++ b/src/api/java/baritone/api/schematic/mask/operator/NotMask.java @@ -0,0 +1,56 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.schematic.mask.operator; + +import baritone.api.schematic.mask.AbstractMask; +import baritone.api.schematic.mask.Mask; +import baritone.api.schematic.mask.StaticMask; +import net.minecraft.block.state.IBlockState; + +/** + * @author Brady + */ +public final class NotMask extends AbstractMask { + + private final Mask source; + + public NotMask(Mask source) { + super(source.widthX(), source.heightY(), source.lengthZ()); + this.source = source; + } + + @Override + public boolean partOfMask(int x, int y, int z, IBlockState currentState) { + return !this.source.partOfMask(x, y, z, currentState); + } + + public static final class Static extends AbstractMask implements StaticMask { + + private final StaticMask source; + + public Static(StaticMask source) { + super(source.widthX(), source.heightY(), source.lengthZ()); + this.source = source; + } + + @Override + public boolean partOfMask(int x, int y, int z) { + return !this.source.partOfMask(x, y, z); + } + } +} diff --git a/src/api/java/baritone/api/utils/BooleanBinaryOperator.java b/src/api/java/baritone/api/utils/BooleanBinaryOperator.java new file mode 100644 index 000000000..cfb85e644 --- /dev/null +++ b/src/api/java/baritone/api/utils/BooleanBinaryOperator.java @@ -0,0 +1,27 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.utils; + +/** + * @author Brady + */ +@FunctionalInterface +public interface BooleanBinaryOperator { + + boolean applyAsBoolean(boolean a, boolean b); +} diff --git a/src/api/java/baritone/api/utils/BooleanBinaryOperators.java b/src/api/java/baritone/api/utils/BooleanBinaryOperators.java new file mode 100644 index 000000000..11605c965 --- /dev/null +++ b/src/api/java/baritone/api/utils/BooleanBinaryOperators.java @@ -0,0 +1,38 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.utils; + +/** + * @author Brady + */ +public enum BooleanBinaryOperators implements BooleanBinaryOperator { + OR((a, b) -> a || b), + AND((a, b) -> a && b), + XOR((a, b) -> a ^ b); + + private final BooleanBinaryOperator op; + + BooleanBinaryOperators(BooleanBinaryOperator op) { + this.op = op; + } + + @Override + public boolean applyAsBoolean(boolean a, boolean b) { + return this.op.applyAsBoolean(a, b); + } +} From 364ae87ef861dd12570a0db6081ad1d4f5d4a399 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Jun 2023 12:36:53 -0500 Subject: [PATCH 10/35] Add `blockFreeLook` setting --- src/api/java/baritone/api/Settings.java | 5 +++++ src/api/java/baritone/api/utils/Rotation.java | 8 +++++-- .../baritone/api/utils/RotationUtils.java | 6 +++-- .../java/baritone/behavior/LookBehavior.java | 22 ++++++++++++++----- .../pathing/movement/MovementHelper.java | 4 ++-- .../movement/movements/MovementDescend.java | 5 ++--- .../movement/movements/MovementPillar.java | 4 ++-- .../utils/player/PrimaryPlayerContext.java | 16 ++++++++++---- 8 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index b7a4e41a4..b49fce01b 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -723,6 +723,11 @@ public final class Settings { */ public final Setting freeLook = new Setting<>(true); + /** + * Break and place blocks without having to force the client-sided rotations + */ + public final Setting blockFreeLook = new Setting<>(true); + /** * Will cause some minor behavioral differences to ensure that Baritone works on anticheats. *

diff --git a/src/api/java/baritone/api/utils/Rotation.java b/src/api/java/baritone/api/utils/Rotation.java index 54f63ebfa..8dab287de 100644 --- a/src/api/java/baritone/api/utils/Rotation.java +++ b/src/api/java/baritone/api/utils/Rotation.java @@ -26,12 +26,12 @@ public class Rotation { /** * The yaw angle of this Rotation */ - private float yaw; + private final float yaw; /** * The pitch angle of this Rotation */ - private float pitch; + private final float pitch; public Rotation(float yaw, float pitch) { this.yaw = yaw; @@ -110,6 +110,10 @@ public class Rotation { ); } + public Rotation withPitch(float pitch) { + return new Rotation(this.yaw, pitch); + } + /** * Is really close to * diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java index 39e68fd4f..7b30f4abb 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/api/java/baritone/api/utils/RotationUtils.java @@ -162,7 +162,8 @@ public final class RotationUtils { public static Optional reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity); - if (baritone.getPlayerContext().isLookingAt(pos)) { + IPlayerContext ctx = baritone.getPlayerContext(); + if (ctx.isLookingAt(pos)) { /* * why add 0.0001? * to indicate that we actually have a desired pitch @@ -173,7 +174,7 @@ public final class RotationUtils { * * or if you're a normal person literally all this does it ensure that we don't nudge the pitch to a normal level */ - Rotation hypothetical = new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F); + Rotation hypothetical = ctx.playerRotations().add(new Rotation(0, 0.0001F)); if (wouldSneak) { // the concern here is: what if we're looking at it now, but as soon as we start sneaking we no longer are RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, hypothetical, blockReachDistance, true); @@ -217,6 +218,7 @@ public final class RotationUtils { */ public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance, boolean wouldSneak) { Vec3d eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getPositionEyes(1.0F); + // TODO: pr/feature/blockFreeLook - Use playerRotations() here? Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak); //System.out.println(result); diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 32e5c22f5..7db3da562 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -22,6 +22,7 @@ import baritone.api.Settings; import baritone.api.behavior.ILookBehavior; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.RotationMoveEvent; +import baritone.api.event.events.type.EventState; import baritone.api.utils.Rotation; public final class LookBehavior extends Behavior implements ILookBehavior { @@ -34,17 +35,19 @@ public final class LookBehavior extends Behavior implements ILookBehavior { */ private Rotation target; + private Rotation serverAngles; + /** * Whether or not rotations are currently being forced */ private boolean force; /** - * The last player yaw angle. Used when free looking + * The last player angles. Used when free looking * * @see Settings#freeLook */ - private float lastYaw; + private Rotation prevAngles; public LookBehavior(Baritone baritone) { super(baritone); @@ -53,11 +56,14 @@ public final class LookBehavior extends Behavior implements ILookBehavior { @Override public void updateTarget(Rotation target, boolean force) { this.target = target; - this.force = force || !Baritone.settings().freeLook.value; + this.force = !Baritone.settings().blockFreeLook.value && (force || !Baritone.settings().freeLook.value); } @Override public void onPlayerUpdate(PlayerUpdateEvent event) { + if (event.getState() == EventState.POST) { + this.serverAngles = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); + } if (this.target == null) { return; } @@ -80,14 +86,16 @@ public final class LookBehavior extends Behavior implements ILookBehavior { this.target = null; } if (silent) { - this.lastYaw = ctx.player().rotationYaw; + this.prevAngles = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); ctx.player().rotationYaw = this.target.getYaw(); + ctx.player().rotationPitch = this.target.getPitch(); } break; } case POST: { if (silent) { - ctx.player().rotationYaw = this.lastYaw; + ctx.player().rotationYaw = this.prevAngles.getYaw(); + ctx.player().rotationPitch = this.prevAngles.getPitch(); this.target = null; } break; @@ -103,6 +111,10 @@ public final class LookBehavior extends Behavior implements ILookBehavior { } } + public Rotation getEffectiveAngles() { + return this.serverAngles; + } + @Override public void onPlayerRotationMove(RotationMoveEvent event) { if (this.target != null) { diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 575815ea2..b14b2d69c 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -599,9 +599,9 @@ public interface MovementHelper extends ActionCosts, Helper { static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { state.setTarget(new MovementTarget( - new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), + RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(pos), - ctx.playerRotations()).getYaw(), ctx.player().rotationPitch), + ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()), false )).setInput(Input.MOVE_FORWARD, true); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index d36843cdd..2d8180356 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -234,11 +234,10 @@ public class MovementDescend extends Movement { if (safeMode()) { double destX = (src.getX() + 0.5) * 0.17 + (dest.getX() + 0.5) * 0.83; double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83; - EntityPlayerSP player = ctx.player(); state.setTarget(new MovementState.MovementTarget( - new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), + RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(destX, dest.getY(), destZ), - new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch), + ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()), false )).setInput(Input.MOVE_FORWARD, true); return state; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index cfa9d9260..88f1e26ff 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -190,9 +190,9 @@ public class MovementPillar extends Movement { boolean vine = fromDown.getBlock() == Blocks.VINE; Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(positionToPlace), - new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch)); + ctx.playerRotations()); if (!ladder) { - state.setTarget(new MovementState.MovementTarget(new Rotation(ctx.player().rotationYaw, rotation.getPitch()), true)); + state.setTarget(new MovementState.MovementTarget(ctx.playerRotations().withPitch(rotation.getPitch()), true)); } boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder; diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index 3cb498acd..cc35c156c 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -17,12 +17,11 @@ package baritone.utils.player; +import baritone.Baritone; import baritone.api.BaritoneAPI; import baritone.api.cache.IWorldData; -import baritone.api.utils.Helper; -import baritone.api.utils.IPlayerContext; -import baritone.api.utils.IPlayerController; -import baritone.api.utils.RayTraceUtils; +import baritone.api.utils.*; +import baritone.behavior.LookBehavior; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; @@ -57,6 +56,15 @@ public enum PrimaryPlayerContext implements IPlayerContext, Helper { return BaritoneAPI.getProvider().getPrimaryBaritone().getWorldProvider().getCurrentWorld(); } + @Override + public Rotation playerRotations() { + final Rotation lbTarget = ((LookBehavior) BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()).getEffectiveAngles(); + if (lbTarget == null || !Baritone.settings().blockFreeLook.value) { + return IPlayerContext.super.playerRotations(); + } + return lbTarget; + } + @Override public RayTraceResult objectMouseOver() { return RayTraceUtils.rayTraceTowards(player(), playerRotations(), playerController().getBlockReachDistance()); From fbe28e397e880e022c43af81c59dc8f088cd42b6 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Jun 2023 12:38:13 -0500 Subject: [PATCH 11/35] Make setting disabled by default --- src/api/java/baritone/api/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index b49fce01b..bf3cb1bdd 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -726,7 +726,7 @@ public final class Settings { /** * Break and place blocks without having to force the client-sided rotations */ - public final Setting blockFreeLook = new Setting<>(true); + public final Setting blockFreeLook = new Setting<>(false); /** * Will cause some minor behavioral differences to ensure that Baritone works on anticheats. From a09e63d6aa654b85b3dbc75ad1044e1e4d031b45 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Jun 2023 13:14:52 -0500 Subject: [PATCH 12/35] appease codacy --- src/main/java/baritone/command/defaults/SelCommand.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index 0a11c86a8..fb3608e75 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -294,12 +294,9 @@ public class SelCommand extends Command { args.get(); } return args.tabCompleteDatatype(ForBlockOptionalMeta.INSTANCE); - } else if (action == Action.CYLINDER || action == Action.HCYLINDER) { - if (args.hasExactly(2)) { - if (args.getDatatypeForOrNull(ForBlockOptionalMeta.INSTANCE) != null) { - return args.tabCompleteDatatype(ForAxis.INSTANCE); - } - } + } else if (args.hasExactly(2) && (action == Action.CYLINDER || action == Action.HCYLINDER)) { + args.get(); + return args.tabCompleteDatatype(ForAxis.INSTANCE); } } else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) { if (args.hasExactlyOne()) { From 77ca36c7947541faef6e1519823c4b06c913bc88 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Jun 2023 15:49:04 -0500 Subject: [PATCH 13/35] Use `playerRotations` in `reachableOffset` --- src/api/java/baritone/api/utils/RotationUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java index 7b30f4abb..0d5a3ad1f 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/api/java/baritone/api/utils/RotationUtils.java @@ -216,10 +216,10 @@ public final class RotationUtils { * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ - public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance, boolean wouldSneak) { + public static Optional reachableOffset(EntityPlayerSP entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance, boolean wouldSneak) { + IPlayerContext ctx = BaritoneAPI.getProvider().getBaritoneForPlayer(entity).getPlayerContext(); Vec3d eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getPositionEyes(1.0F); - // TODO: pr/feature/blockFreeLook - Use playerRotations() here? - Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); + Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, ctx.playerRotations()); RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak); //System.out.println(result); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { @@ -242,7 +242,7 @@ public final class RotationUtils { * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ - public static Optional reachableCenter(Entity entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { + public static Optional reachableCenter(EntityPlayerSP entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(entity.world, pos), blockReachDistance, wouldSneak); } } From 4317dca024ec0d68b3d402b82777a453f7c121b1 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Jun 2023 18:35:34 -0500 Subject: [PATCH 14/35] Determine target mode (client/server) in `updateTarget` --- src/api/java/baritone/api/Settings.java | 3 +- .../baritone/api/behavior/ILookBehavior.java | 13 +- .../java/baritone/behavior/LookBehavior.java | 125 +++++++++++------- 3 files changed, 87 insertions(+), 54 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index bf3cb1bdd..bcd3eaa63 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -724,7 +724,8 @@ public final class Settings { public final Setting freeLook = new Setting<>(true); /** - * Break and place blocks without having to force the client-sided rotations + * Break and place blocks without having to force the client-sided rotations. Having this setting enabled implies + * {@link #freeLook}. */ public final Setting blockFreeLook = new Setting<>(false); diff --git a/src/api/java/baritone/api/behavior/ILookBehavior.java b/src/api/java/baritone/api/behavior/ILookBehavior.java index 058a5dd88..218e8b59a 100644 --- a/src/api/java/baritone/api/behavior/ILookBehavior.java +++ b/src/api/java/baritone/api/behavior/ILookBehavior.java @@ -26,14 +26,11 @@ import baritone.api.utils.Rotation; public interface ILookBehavior extends IBehavior { /** - * Updates the current {@link ILookBehavior} target to target - * the specified rotations on the next tick. If force is {@code true}, - * then freeLook will be overriden and angles will be set regardless. - * If any sort of block interaction is required, force should be {@code true}, - * otherwise, it should be {@code false}; + * Updates the current {@link ILookBehavior} target to target the specified rotations on the next tick. If any sort + * of block interaction is required, {@code blockInteract} should be {@code true}. * - * @param rotation The target rotations - * @param force Whether or not to "force" the rotations + * @param rotation The target rotations + * @param blockInteract Whether the target rotations are needed for a block interaction */ - void updateTarget(Rotation rotation, boolean force); + void updateTarget(Rotation rotation, boolean blockInteract); } diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 7db3da562..93e0af3bf 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -28,19 +28,11 @@ import baritone.api.utils.Rotation; public final class LookBehavior extends Behavior implements ILookBehavior { /** - * Target's values are as follows: - *

- * getFirst() -> yaw - * getSecond() -> pitch + * The current look target, may be {@code null}. */ - private Rotation target; + private Target target; - private Rotation serverAngles; - - /** - * Whether or not rotations are currently being forced - */ - private boolean force; + private Rotation serverRotation; /** * The last player angles. Used when free looking @@ -54,50 +46,60 @@ public final class LookBehavior extends Behavior implements ILookBehavior { } @Override - public void updateTarget(Rotation target, boolean force) { - this.target = target; - this.force = !Baritone.settings().blockFreeLook.value && (force || !Baritone.settings().freeLook.value); + public void updateTarget(Rotation rotation, boolean blockInteract) { + this.target = new Target(rotation, blockInteract); } @Override public void onPlayerUpdate(PlayerUpdateEvent event) { + // Capture the player rotation before it's reset to determine the rotation the server knows + // Alternatively, this could be done with a packet event... Maybe that's a better idea. if (event.getState() == EventState.POST) { - this.serverAngles = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); + this.serverRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); } + + // There's nothing left to be done if there isn't a set target if (this.target == null) { return; } - // Whether or not we're going to silently set our angles - boolean silent = Baritone.settings().antiCheatCompatibility.value && !this.force; - switch (event.getState()) { case PRE: { - if (this.force) { - ctx.player().rotationYaw = this.target.getYaw(); - float oldPitch = ctx.player().rotationPitch; - float desiredPitch = this.target.getPitch(); - ctx.player().rotationPitch = desiredPitch; - ctx.player().rotationYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; - ctx.player().rotationPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; - if (desiredPitch == oldPitch && !Baritone.settings().freeLook.value) { - nudgeToLevel(); + switch (this.target.mode) { + case CLIENT: { + ctx.player().rotationYaw = this.target.rotation.getYaw(); + float oldPitch = ctx.player().rotationPitch; + float desiredPitch = this.target.rotation.getPitch(); + ctx.player().rotationPitch = desiredPitch; + ctx.player().rotationYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; + ctx.player().rotationPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; + if (desiredPitch == oldPitch && !Baritone.settings().freeLook.value) { + nudgeToLevel(); + } + // The target can be invalidated now since it won't be needed for RotationMoveEvent + this.target = null; + break; } - this.target = null; - } - if (silent) { - this.prevAngles = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); - ctx.player().rotationYaw = this.target.getYaw(); - ctx.player().rotationPitch = this.target.getPitch(); + case SERVER: { + // Copy the player's actual angles + this.prevAngles = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); + ctx.player().rotationYaw = this.target.rotation.getYaw(); + ctx.player().rotationPitch = this.target.rotation.getPitch(); + break; + } + default: + break; } break; } case POST: { - if (silent) { + // Reset the player's rotations back to their original values + if (this.target.mode == Target.Mode.SERVER) { ctx.player().rotationYaw = this.prevAngles.getYaw(); ctx.player().rotationPitch = this.prevAngles.getPitch(); - this.target = null; } + // The target is done being used for this game tick, so it can be invalidated + this.target = null; break; } default: @@ -107,25 +109,18 @@ public final class LookBehavior extends Behavior implements ILookBehavior { public void pig() { if (this.target != null) { - ctx.player().rotationYaw = this.target.getYaw(); + ctx.player().rotationYaw = this.target.rotation.getYaw(); } } public Rotation getEffectiveAngles() { - return this.serverAngles; + return this.serverRotation; } @Override public void onPlayerRotationMove(RotationMoveEvent event) { if (this.target != null) { - - event.setYaw(this.target.getYaw()); - - // If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate() - // Also the type has to be MOTION_UPDATE because that is called after JUMP - if (!Baritone.settings().antiCheatCompatibility.value && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE && !this.force) { - this.target = null; - } + event.setYaw(this.target.rotation.getYaw()); } } @@ -139,4 +134,44 @@ public final class LookBehavior extends Behavior implements ILookBehavior { ctx.player().rotationPitch--; } } + + private static class Target { + + public final Rotation rotation; + public final Mode mode; + + public Target(Rotation rotation, boolean blockInteract) { + this.rotation = rotation; + this.mode = Mode.resolve(blockInteract); + } + + enum Mode { + /** + * Angles will be set client-side and are visual to the player + */ + CLIENT, + + /** + * Angles will be set server-side and are silent to the player + */ + SERVER, + + /** + * Angles will remain unaffected on both the client and server + */ + NONE; + + static Mode resolve(boolean blockInteract) { + final Settings settings = Baritone.settings(); + final boolean antiCheat = settings.antiCheatCompatibility.value; + final boolean blockFreeLook = settings.blockFreeLook.value; + final boolean freeLook = settings.freeLook.value; + + if (!freeLook && !blockFreeLook) return CLIENT; + if (!blockFreeLook && blockInteract) return CLIENT; + if (antiCheat || blockInteract) return SERVER; + return NONE; + } + } + } } From a7d15d1e32a1438bce8223a3483a76dcd5d14444 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Jun 2023 18:43:48 -0500 Subject: [PATCH 15/35] Consistent naming and comments for clarification --- .../java/baritone/behavior/LookBehavior.java | 30 ++++++++++++------- .../utils/player/PrimaryPlayerContext.java | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 93e0af3bf..c38cee6f9 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -23,6 +23,7 @@ import baritone.api.behavior.ILookBehavior; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.RotationMoveEvent; import baritone.api.event.events.type.EventState; +import baritone.api.utils.IPlayerContext; import baritone.api.utils.Rotation; public final class LookBehavior extends Behavior implements ILookBehavior { @@ -32,14 +33,17 @@ public final class LookBehavior extends Behavior implements ILookBehavior { */ private Target target; + /** + * The rotation known to the server. Returned by {@link #getEffectiveRotation()} for use in {@link IPlayerContext}. + */ private Rotation serverRotation; /** - * The last player angles. Used when free looking + * The last player rotation. Used when free looking * * @see Settings#freeLook */ - private Rotation prevAngles; + private Rotation prevRotation; public LookBehavior(Baritone baritone) { super(baritone); @@ -81,8 +85,8 @@ public final class LookBehavior extends Behavior implements ILookBehavior { break; } case SERVER: { - // Copy the player's actual angles - this.prevAngles = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); + // Copy the player's actual rotation + this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); ctx.player().rotationYaw = this.target.rotation.getYaw(); ctx.player().rotationPitch = this.target.rotation.getPitch(); break; @@ -95,8 +99,8 @@ public final class LookBehavior extends Behavior implements ILookBehavior { case POST: { // Reset the player's rotations back to their original values if (this.target.mode == Target.Mode.SERVER) { - ctx.player().rotationYaw = this.prevAngles.getYaw(); - ctx.player().rotationPitch = this.prevAngles.getPitch(); + ctx.player().rotationYaw = this.prevRotation.getYaw(); + ctx.player().rotationPitch = this.prevRotation.getPitch(); } // The target is done being used for this game tick, so it can be invalidated this.target = null; @@ -113,7 +117,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior { } } - public Rotation getEffectiveAngles() { + public Rotation getEffectiveRotation() { return this.serverRotation; } @@ -147,17 +151,17 @@ public final class LookBehavior extends Behavior implements ILookBehavior { enum Mode { /** - * Angles will be set client-side and are visual to the player + * Rotation will be set client-side and is visual to the player */ CLIENT, /** - * Angles will be set server-side and are silent to the player + * Rotation will be set server-side and is silent to the player */ SERVER, /** - * Angles will remain unaffected on both the client and server + * Rotation will remain unaffected on both the client and server */ NONE; @@ -169,7 +173,13 @@ public final class LookBehavior extends Behavior implements ILookBehavior { if (!freeLook && !blockFreeLook) return CLIENT; if (!blockFreeLook && blockInteract) return CLIENT; + + // Regardless of if antiCheatCompatibility is enabled, if a blockInteract is requested then the player + // rotation needs to be set somehow, otherwise Baritone will halt since objectMouseOver() will just be + // whatever the player is mousing over visually. Let's just settle for setting it silently. if (antiCheat || blockInteract) return SERVER; + + // Pathing regularly without antiCheatCompatibility, don't set the player rotation return NONE; } } diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index cc35c156c..e4484f0be 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -58,7 +58,7 @@ public enum PrimaryPlayerContext implements IPlayerContext, Helper { @Override public Rotation playerRotations() { - final Rotation lbTarget = ((LookBehavior) BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()).getEffectiveAngles(); + final Rotation lbTarget = ((LookBehavior) BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()).getEffectiveRotation(); if (lbTarget == null || !Baritone.settings().blockFreeLook.value) { return IPlayerContext.super.playerRotations(); } From bb36ebfc0c7cb39ac24852fef1b28c25c995975d Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Jun 2023 20:09:37 -0500 Subject: [PATCH 16/35] Use `IPlayerContext` for all `RotationUtils` methods Deprecates all old overloads --- .../baritone/api/utils/RotationUtils.java | 87 +++++++++++++------ .../baritone/pathing/movement/Movement.java | 2 +- .../movement/movements/MovementPillar.java | 2 +- .../java/baritone/process/BuilderProcess.java | 2 +- .../java/baritone/process/FarmProcess.java | 4 +- .../baritone/process/GetToBlockProcess.java | 2 +- .../java/baritone/process/MineProcess.java | 2 +- 7 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java index 0d5a3ad1f..1991ab878 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/api/java/baritone/api/utils/RotationUtils.java @@ -134,14 +134,14 @@ public final class RotationUtils { * @param ctx Context for the viewing entity * @param pos The target block position * @return The optional rotation - * @see #reachable(EntityPlayerSP, BlockPos, double) + * @see #reachable(IPlayerContext, BlockPos, double) */ public static Optional reachable(IPlayerContext ctx, BlockPos pos) { - return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); + return reachable(ctx, pos, false); } public static Optional reachable(IPlayerContext ctx, BlockPos pos, boolean wouldSneak) { - return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance(), wouldSneak); + return reachable(ctx, pos, ctx.playerController().getBlockReachDistance(), wouldSneak); } /** @@ -151,18 +151,16 @@ public final class RotationUtils { * side that is reachable. The return type will be {@link Optional#empty()} if the entity is * unable to reach any of the sides of the block. * - * @param entity The viewing entity + * @param ctx Context for the viewing entity * @param pos The target block position * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ - public static Optional reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) { - return reachable(entity, pos, blockReachDistance, false); + public static Optional reachable(IPlayerContext ctx, BlockPos pos, double blockReachDistance) { + return reachable(ctx, pos, blockReachDistance, false); } - public static Optional reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { - IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity); - IPlayerContext ctx = baritone.getPlayerContext(); + public static Optional reachable(IPlayerContext ctx, BlockPos pos, double blockReachDistance, boolean wouldSneak) { if (ctx.isLookingAt(pos)) { /* * why add 0.0001? @@ -177,7 +175,7 @@ public final class RotationUtils { Rotation hypothetical = ctx.playerRotations().add(new Rotation(0, 0.0001F)); if (wouldSneak) { // the concern here is: what if we're looking at it now, but as soon as we start sneaking we no longer are - RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, hypothetical, blockReachDistance, true); + RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), hypothetical, blockReachDistance, true); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(pos)) { return Optional.of(hypothetical); // yes, if we sneaked we would still be looking at the block } @@ -185,19 +183,19 @@ public final class RotationUtils { return Optional.of(hypothetical); } } - Optional possibleRotation = reachableCenter(entity, pos, blockReachDistance, wouldSneak); + Optional possibleRotation = reachableCenter(ctx, pos, blockReachDistance, wouldSneak); //System.out.println("center: " + possibleRotation); if (possibleRotation.isPresent()) { return possibleRotation; } - IBlockState state = entity.world.getBlockState(pos); - AxisAlignedBB aabb = state.getBoundingBox(entity.world, pos); + IBlockState state = ctx.world().getBlockState(pos); + AxisAlignedBB aabb = state.getBoundingBox(ctx.world(), pos); for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) { double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x); double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y); double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z); - possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance, wouldSneak); + possibleRotation = reachableOffset(ctx, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance, wouldSneak); if (possibleRotation.isPresent()) { return possibleRotation; } @@ -210,16 +208,57 @@ public final class RotationUtils { * the given offsetted position. The return type will be {@link Optional#empty()} if * the entity is unable to reach the block with the offset applied. * - * @param entity The viewing entity + * @param ctx Context for the viewing entity * @param pos The target block position * @param offsetPos The position of the block with the offset applied. * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ - public static Optional reachableOffset(EntityPlayerSP entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance, boolean wouldSneak) { - IPlayerContext ctx = BaritoneAPI.getProvider().getBaritoneForPlayer(entity).getPlayerContext(); - Vec3d eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getPositionEyes(1.0F); + public static Optional reachableOffset(IPlayerContext ctx, BlockPos pos, Vec3d offsetPos, double blockReachDistance, boolean wouldSneak) { + Vec3d eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(ctx.player()) : ctx.player().getPositionEyes(1.0F); Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, ctx.playerRotations()); + RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rotation, blockReachDistance, wouldSneak); + //System.out.println(result); + if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { + if (result.getBlockPos().equals(pos)) { + return Optional.of(rotation); + } + if (ctx.world().getBlockState(pos).getBlock() instanceof BlockFire && result.getBlockPos().equals(pos.down())) { + return Optional.of(rotation); + } + } + return Optional.empty(); + } + + /** + * Determines if the specified entity is able to reach the specified block where it is + * looking at the direct center of it's hitbox. + * + * @param ctx Context for the viewing entity + * @param pos The target block position + * @param blockReachDistance The block reach distance of the entity + * @return The optional rotation + */ + public static Optional reachableCenter(IPlayerContext ctx, BlockPos pos, double blockReachDistance, boolean wouldSneak) { + return reachableOffset(ctx, pos, VecUtils.calculateBlockCenter(ctx.world(), pos), blockReachDistance, wouldSneak); + } + + @Deprecated + public static Optional reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) { + return reachable(entity, pos, blockReachDistance, false); + } + + @Deprecated + public static Optional reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { + IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity); + IPlayerContext ctx = baritone.getPlayerContext(); + return reachable(ctx, pos, blockReachDistance, wouldSneak); + } + + @Deprecated + public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance, boolean wouldSneak) { + Vec3d eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getPositionEyes(1.0F); + Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak); //System.out.println(result); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { @@ -233,16 +272,8 @@ public final class RotationUtils { return Optional.empty(); } - /** - * Determines if the specified entity is able to reach the specified block where it is - * looking at the direct center of it's hitbox. - * - * @param entity The viewing entity - * @param pos The target block position - * @param blockReachDistance The block reach distance of the entity - * @return The optional rotation - */ - public static Optional reachableCenter(EntityPlayerSP entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { + @Deprecated + public static Optional reachableCenter(Entity entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(entity.world, pos), blockReachDistance, wouldSneak); } } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index c46b24dea..5a17d26c5 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -164,7 +164,7 @@ public abstract class Movement implements IMovement, MovementHelper { if (!MovementHelper.canWalkThrough(ctx, blockPos) && !(BlockStateInterface.getBlock(ctx, blockPos) instanceof BlockLiquid)) { // can't break liquid, so don't try somethingInTheWay = true; MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos)); - Optional reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance()); + Optional reachable = RotationUtils.reachable(ctx, blockPos, ctx.playerController().getBlockReachDistance()); if (reachable.isPresent()) { Rotation rotTowardsBlock = reachable.get(); state.setTarget(new MovementState.MovementTarget(rotTowardsBlock, true)); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 88f1e26ff..0198b28fe 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -251,7 +251,7 @@ public class MovementPillar extends Movement { Block fr = frState.getBlock(); // TODO: Evaluate usage of getMaterial().isReplaceable() if (!(fr instanceof BlockAir || frState.getMaterial().isReplaceable())) { - RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance()) + RotationUtils.reachable(ctx, src, ctx.playerController().getBlockReachDistance()) .map(rot -> new MovementState.MovementTarget(rot, true)) .ifPresent(state::setTarget); state.setInput(Input.JUMP, false); // breaking is like 5x slower when you're jumping diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index c7868a4a0..6f8582457 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -283,7 +283,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil 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 rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); + Optional rot = RotationUtils.reachable(ctx, pos, ctx.playerController().getBlockReachDistance()); if (rot.isPresent()) { return Optional.of(new Tuple<>(pos, rot.get())); } diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index a9188299c..1536bdb61 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -268,7 +268,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro both.addAll(openSoulsand); for (BlockPos pos : both) { boolean soulsand = openSoulsand.contains(pos); - Optional rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false); + Optional rot = RotationUtils.reachableOffset(ctx, 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) { @@ -286,7 +286,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro continue; } Vec3d faceCenter = new Vec3d(pos).add(0.5, 0.5, 0.5).add(new Vec3d(dir.getDirectionVec()).scale(0.5)); - Optional rot = RotationUtils.reachableOffset(ctx.player(), pos, faceCenter, ctx.playerController().getBlockReachDistance(), false); + Optional rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, ctx.playerController().getBlockReachDistance(), false); if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isCocoa)) { RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance()); if (result.typeOfHit == RayTraceResult.Type.BLOCK && result.sideHit == dir) { diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 16fc3dda5..7f8376b84 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -210,7 +210,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG private boolean rightClick() { for (BlockPos pos : knownLocations) { - Optional reachable = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); + Optional reachable = RotationUtils.reachable(ctx, pos, ctx.playerController().getBlockReachDistance()); if (reachable.isPresent()) { baritone.getLookBehavior().updateTarget(reachable.get(), true); if (knownLocations.contains(ctx.getSelectedBlock().orElse(null))) { diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 6880dd86c..e7d7b3365 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -397,7 +397,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro // is an x-ray and it'll get caught if (filter.has(bsi.get0(x, y, z))) { BlockPos pos = new BlockPos(x, y, z); - if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) { + if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx, pos, fakedBlockReachDistance).isPresent()) { knownOreLocations.add(pos); } } From 1d5ee079b4aea9925041eae05a923da513b1ba5e Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 12:11:50 -0500 Subject: [PATCH 17/35] Read `serverRotation` from packet and invalidate on world load --- .../java/baritone/behavior/LookBehavior.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index c38cee6f9..d1e5d244f 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -20,11 +20,13 @@ package baritone.behavior; import baritone.Baritone; import baritone.api.Settings; import baritone.api.behavior.ILookBehavior; +import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.RotationMoveEvent; -import baritone.api.event.events.type.EventState; +import baritone.api.event.events.WorldEvent; import baritone.api.utils.IPlayerContext; import baritone.api.utils.Rotation; +import net.minecraft.network.play.client.CPacketPlayer; public final class LookBehavior extends Behavior implements ILookBehavior { @@ -56,17 +58,9 @@ public final class LookBehavior extends Behavior implements ILookBehavior { @Override public void onPlayerUpdate(PlayerUpdateEvent event) { - // Capture the player rotation before it's reset to determine the rotation the server knows - // Alternatively, this could be done with a packet event... Maybe that's a better idea. - if (event.getState() == EventState.POST) { - this.serverRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); - } - - // There's nothing left to be done if there isn't a set target if (this.target == null) { return; } - switch (event.getState()) { case PRE: { switch (this.target.mode) { @@ -111,6 +105,24 @@ public final class LookBehavior extends Behavior implements ILookBehavior { } } + @Override + public void onSendPacket(PacketEvent event) { + if (!(event.getPacket() instanceof CPacketPlayer)) { + return; + } + + final CPacketPlayer packet = (CPacketPlayer) event.getPacket(); + if (packet instanceof CPacketPlayer.Rotation || packet instanceof CPacketPlayer.PositionRotation) { + this.serverRotation = new Rotation(packet.getYaw(0.0f), packet.getPitch(0.0f)); + } + } + + @Override + public void onWorldEvent(WorldEvent event) { + this.serverRotation = null; + this.target = null; + } + public void pig() { if (this.target != null) { ctx.player().rotationYaw = this.target.rotation.getYaw(); From 67a085c95fca4be8a6f85d4c2a5dfcc0bb9f3d89 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 13:16:37 -0500 Subject: [PATCH 18/35] Batch together GL_LINES draw calls --- .../baritone/command/defaults/SelCommand.java | 2 +- .../baritone/selection/SelectionRenderer.java | 8 +-- src/main/java/baritone/utils/IRenderer.java | 16 +++-- .../java/baritone/utils/PathRenderer.java | 67 +++++++++++++------ 4 files changed, 61 insertions(+), 32 deletions(-) diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index 5677eec3c..d6c2e890d 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -72,7 +72,7 @@ public class SelCommand extends Command { float lineWidth = Baritone.settings().selectionLineWidth.value; boolean ignoreDepth = Baritone.settings().renderSelectionIgnoreDepth.value; IRenderer.startLines(color, opacity, lineWidth, ignoreDepth); - IRenderer.drawAABB(new AxisAlignedBB(pos1, pos1.add(1, 1, 1))); + IRenderer.emitAABB(new AxisAlignedBB(pos1, pos1.add(1, 1, 1))); IRenderer.endLines(ignoreDepth); } }); diff --git a/src/main/java/baritone/selection/SelectionRenderer.java b/src/main/java/baritone/selection/SelectionRenderer.java index 89104d030..b688e9670 100644 --- a/src/main/java/baritone/selection/SelectionRenderer.java +++ b/src/main/java/baritone/selection/SelectionRenderer.java @@ -23,27 +23,27 @@ public class SelectionRenderer implements IRenderer, AbstractGameEventListener { boolean ignoreDepth = settings.renderSelectionIgnoreDepth.value; float lineWidth = settings.selectionLineWidth.value; - if (!settings.renderSelection.value) { + if (!settings.renderSelection.value || selections.length == 0) { return; } IRenderer.startLines(settings.colorSelection.value, opacity, lineWidth, ignoreDepth); for (ISelection selection : selections) { - IRenderer.drawAABB(selection.aabb(), SELECTION_BOX_EXPANSION); + IRenderer.emitAABB(selection.aabb(), SELECTION_BOX_EXPANSION); } if (settings.renderSelectionCorners.value) { IRenderer.glColor(settings.colorSelectionPos1.value, opacity); for (ISelection selection : selections) { - IRenderer.drawAABB(new AxisAlignedBB(selection.pos1(), selection.pos1().add(1, 1, 1))); + IRenderer.emitAABB(new AxisAlignedBB(selection.pos1(), selection.pos1().add(1, 1, 1))); } IRenderer.glColor(settings.colorSelectionPos2.value, opacity); for (ISelection selection : selections) { - IRenderer.drawAABB(new AxisAlignedBB(selection.pos2(), selection.pos2().add(1, 1, 1))); + IRenderer.emitAABB(new AxisAlignedBB(selection.pos2(), selection.pos2().add(1, 1, 1))); } } diff --git a/src/main/java/baritone/utils/IRenderer.java b/src/main/java/baritone/utils/IRenderer.java index e5a5ee907..3476c0307 100644 --- a/src/main/java/baritone/utils/IRenderer.java +++ b/src/main/java/baritone/utils/IRenderer.java @@ -54,6 +54,7 @@ public interface IRenderer { if (ignoreDepth) { GlStateManager.disableDepth(); } + buffer.begin(GL_LINES, DefaultVertexFormats.POSITION); } static void startLines(Color color, float lineWidth, boolean ignoreDepth) { @@ -61,6 +62,7 @@ public interface IRenderer { } static void endLines(boolean ignoredDepth) { + tessellator.draw(); if (ignoredDepth) { GlStateManager.enableDepth(); } @@ -70,10 +72,9 @@ public interface IRenderer { GlStateManager.disableBlend(); } - static void drawAABB(AxisAlignedBB aabb) { + static void emitAABB(AxisAlignedBB aabb) { AxisAlignedBB toDraw = aabb.offset(-renderManager.viewerPosX, -renderManager.viewerPosY, -renderManager.viewerPosZ); - buffer.begin(GL_LINES, DefaultVertexFormats.POSITION); // bottom buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); @@ -101,10 +102,15 @@ public interface IRenderer { buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); - tessellator.draw(); } - static void drawAABB(AxisAlignedBB aabb, double expand) { - drawAABB(aabb.grow(expand, expand, expand)); + static void emitAABB(AxisAlignedBB aabb, double expand) { + emitAABB(aabb.grow(expand, expand, expand)); + } + + static void drawAABB(AxisAlignedBB aabb) { + buffer.begin(GL_LINES, DefaultVertexFormats.POSITION); + emitAABB(aabb); + tessellator.draw(); } } diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 2fe224706..2aef0ab54 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -29,7 +29,6 @@ import baritone.pathing.path.PathExecutor; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntityBeaconRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; import net.minecraft.util.math.AxisAlignedBB; @@ -37,6 +36,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import java.awt.*; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -76,7 +76,7 @@ public final class PathRenderer implements IRenderer { } if (goal != null && settings.renderGoal.value) { - drawDankLitGoalBox(renderView, goal, partialTicks, settings.colorGoalBox.value); + drawGoal(renderView, goal, partialTicks, settings.colorGoalBox.value); } if (!settings.renderPath.value) { @@ -153,26 +153,28 @@ public final class PathRenderer implements IRenderer { IRenderer.glColor(color, alpha); } - drawLine(start.x, start.y, start.z, end.x, end.y, end.z); - - tessellator.draw(); + emitLine(start.x, start.y, start.z, end.x, end.y, end.z); } IRenderer.endLines(settings.renderPathIgnoreDepth.value); } - public static void drawLine(double x1, double y1, double z1, double x2, double y2, double z2) { + public static void emitLine(double x1, double y1, double z1, double x2, double y2, double z2) { double vpX = renderManager.viewerPosX; double vpY = renderManager.viewerPosY; double vpZ = renderManager.viewerPosZ; boolean renderPathAsFrickinThingy = !settings.renderPathAsLine.value; - buffer.begin(renderPathAsFrickinThingy ? GL_LINE_STRIP : GL_LINES, DefaultVertexFormats.POSITION); buffer.pos(x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ).endVertex(); buffer.pos(x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ).endVertex(); if (renderPathAsFrickinThingy) { + buffer.pos(x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ).endVertex(); buffer.pos(x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ).endVertex(); + + buffer.pos(x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ).endVertex(); + buffer.pos(x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ).endVertex(); + buffer.pos(x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ).endVertex(); buffer.pos(x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ).endVertex(); } @@ -194,13 +196,17 @@ public final class PathRenderer implements IRenderer { toDraw = state.getSelectedBoundingBox(player.world, pos); } - IRenderer.drawAABB(toDraw, .002D); + IRenderer.emitAABB(toDraw, .002D); }); IRenderer.endLines(settings.renderSelectionBoxesIgnoreDepth.value); } - public static void drawDankLitGoalBox(Entity player, Goal goal, float partialTicks, Color color) { + public static void drawGoal(Entity player, Goal goal, float partialTicks, Color color) { + drawGoal(player, goal, partialTicks, color, true); + } + + public static void drawGoal(Entity player, Goal goal, float partialTicks, Color color, boolean setupRender) { double renderPosX = renderManager.viewerPosX; double renderPosY = renderManager.viewerPosY; double renderPosZ = renderManager.viewerPosZ; @@ -232,6 +238,7 @@ public final class PathRenderer implements IRenderer { y2 -= 0.5; maxY--; } + drawDankLitGoalBox(color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender); } else if (goal instanceof GoalXZ) { GoalXZ goalPos = (GoalXZ) goal; @@ -273,14 +280,22 @@ public final class PathRenderer implements IRenderer { y2 = 0; minY = 0 - renderPosY; maxY = 256 - renderPosY; + drawDankLitGoalBox(color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender); } else if (goal instanceof GoalComposite) { - for (Goal g : ((GoalComposite) goal).goals()) { - drawDankLitGoalBox(player, g, partialTicks, color); + // Simple way to determine if goals can be batched, without having some sort of GoalRenderer + boolean batch = Arrays.stream(((GoalComposite) goal).goals()).allMatch(IGoalRenderPos.class::isInstance); + + if (batch) { + IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value); + } + for (Goal g : ((GoalComposite) goal).goals()) { + drawGoal(player, g, partialTicks, color, !batch); + } + if (batch) { + IRenderer.endLines(settings.renderGoalIgnoreDepth.value); } - return; } else if (goal instanceof GoalInverted) { - drawDankLitGoalBox(player, ((GoalInverted) goal).origin, partialTicks, settings.colorInvertedGoalBox.value); - return; + drawGoal(player, ((GoalInverted) goal).origin, partialTicks, settings.colorInvertedGoalBox.value); } else if (goal instanceof GoalYLevel) { GoalYLevel goalpos = (GoalYLevel) goal; minX = player.posX - settings.yLevelBoxSize.value - renderPosX; @@ -291,16 +306,18 @@ public final class PathRenderer implements IRenderer { maxY = minY + 2; y1 = 1 + y + goalpos.level - renderPosY; y2 = 1 - y + goalpos.level - renderPosY; - } else { - return; + drawDankLitGoalBox(color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender); } + } - IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value); + private static void drawDankLitGoalBox(Color color, double minX, double maxX, double minZ, double maxZ, double minY, double maxY, double y1, double y2, boolean setupRender) { + if (setupRender) { + IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value); + } renderHorizontalQuad(minX, maxX, minZ, maxZ, y1); renderHorizontalQuad(minX, maxX, minZ, maxZ, y2); - buffer.begin(GL_LINES, DefaultVertexFormats.POSITION); buffer.pos(minX, minY, minZ).endVertex(); buffer.pos(minX, maxY, minZ).endVertex(); buffer.pos(maxX, minY, minZ).endVertex(); @@ -309,19 +326,25 @@ public final class PathRenderer implements IRenderer { buffer.pos(maxX, maxY, maxZ).endVertex(); buffer.pos(minX, minY, maxZ).endVertex(); buffer.pos(minX, maxY, maxZ).endVertex(); - tessellator.draw(); - IRenderer.endLines(settings.renderGoalIgnoreDepth.value); + if (setupRender) { + IRenderer.endLines(settings.renderGoalIgnoreDepth.value); + } } private static void renderHorizontalQuad(double minX, double maxX, double minZ, double maxZ, double y) { if (y != 0) { - buffer.begin(GL_LINE_LOOP, DefaultVertexFormats.POSITION); buffer.pos(minX, y, minZ).endVertex(); buffer.pos(maxX, y, minZ).endVertex(); + + buffer.pos(maxX, y, minZ).endVertex(); + buffer.pos(maxX, y, maxZ).endVertex(); + buffer.pos(maxX, y, maxZ).endVertex(); buffer.pos(minX, y, maxZ).endVertex(); - tessellator.draw(); + + buffer.pos(minX, y, maxZ).endVertex(); + buffer.pos(minX, y, minZ).endVertex(); } } } From c8a0ae9e102e9f85efba642f8a52744d7dc2d1d1 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 13:44:08 -0500 Subject: [PATCH 19/35] Do `nudgeToLevel` and `randomLooking` when using freeLook --- .../java/baritone/behavior/LookBehavior.java | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index d1e5d244f..0dc56a3e2 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -58,43 +58,37 @@ public final class LookBehavior extends Behavior implements ILookBehavior { @Override public void onPlayerUpdate(PlayerUpdateEvent event) { - if (this.target == null) { + if (this.target == null || this.target.mode == Target.Mode.NONE) { return; } switch (event.getState()) { case PRE: { - switch (this.target.mode) { - case CLIENT: { - ctx.player().rotationYaw = this.target.rotation.getYaw(); - float oldPitch = ctx.player().rotationPitch; - float desiredPitch = this.target.rotation.getPitch(); - ctx.player().rotationPitch = desiredPitch; - ctx.player().rotationYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; - ctx.player().rotationPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; - if (desiredPitch == oldPitch && !Baritone.settings().freeLook.value) { - nudgeToLevel(); - } - // The target can be invalidated now since it won't be needed for RotationMoveEvent - this.target = null; - break; - } - case SERVER: { - // Copy the player's actual rotation - this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); - ctx.player().rotationYaw = this.target.rotation.getYaw(); - ctx.player().rotationPitch = this.target.rotation.getPitch(); - break; - } - default: - break; + if (this.target.mode == Target.Mode.SERVER) { + this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); + } + + ctx.player().rotationYaw = this.target.rotation.getYaw(); + float oldPitch = ctx.playerRotations().getPitch(); + float desiredPitch = this.target.rotation.getPitch(); + ctx.player().rotationPitch = desiredPitch; + ctx.player().rotationYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; + ctx.player().rotationPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; + if (desiredPitch == oldPitch) { + nudgeToLevel(); + } + + if (this.target.mode == Target.Mode.CLIENT) { + // The target can be invalidated now since it won't be needed for RotationMoveEvent + this.target = null; } break; } case POST: { // Reset the player's rotations back to their original values - if (this.target.mode == Target.Mode.SERVER) { + if (this.prevRotation != null) { ctx.player().rotationYaw = this.prevRotation.getYaw(); ctx.player().rotationPitch = this.prevRotation.getPitch(); + this.prevRotation = null; } // The target is done being used for this game tick, so it can be invalidated this.target = null; From ed34ae73c002d5b23e0e6efc36283dfbe4c78fb7 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 13:46:10 -0500 Subject: [PATCH 20/35] Fix `Mode.NONE` target invalidation --- src/main/java/baritone/behavior/LookBehavior.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 0dc56a3e2..1e109482c 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -58,11 +58,14 @@ public final class LookBehavior extends Behavior implements ILookBehavior { @Override public void onPlayerUpdate(PlayerUpdateEvent event) { - if (this.target == null || this.target.mode == Target.Mode.NONE) { + if (this.target == null) { return; } switch (event.getState()) { case PRE: { + if (this.target.mode == Target.Mode.NONE) { + return; + } if (this.target.mode == Target.Mode.SERVER) { this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); } From 7da802a2389b832b79c41b26f6b4bf4025a9a84e Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 16:21:05 -0500 Subject: [PATCH 21/35] Fix `censorCoordinates` recalc bug Adds `equals` and `toString` implementations where needed Replaces `toString` equality check with actual `equals` check in `forceRevalidate` --- .../baritone/api/pathing/goals/GoalAxis.java | 5 ++ .../baritone/api/pathing/goals/GoalBlock.java | 11 ++++ .../api/pathing/goals/GoalComposite.java | 9 +++ .../api/pathing/goals/GoalGetToBlock.java | 11 ++++ .../api/pathing/goals/GoalInverted.java | 11 ++++ .../baritone/api/pathing/goals/GoalNear.java | 12 ++++ .../api/pathing/goals/GoalRunAway.java | 12 ++++ .../pathing/goals/GoalStrictDirection.java | 13 +++++ .../api/pathing/goals/GoalTwoBlocks.java | 11 ++++ .../baritone/api/pathing/goals/GoalXZ.java | 10 ++++ .../api/pathing/goals/GoalYLevel.java | 9 +++ .../java/baritone/process/BuilderProcess.java | 57 +++++++++++++++++-- .../java/baritone/process/MineProcess.java | 15 +++++ .../baritone/utils/PathingControlManager.java | 2 +- 14 files changed, 183 insertions(+), 5 deletions(-) diff --git a/src/api/java/baritone/api/pathing/goals/GoalAxis.java b/src/api/java/baritone/api/pathing/goals/GoalAxis.java index 7c9b26705..ad8fb892e 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalAxis.java +++ b/src/api/java/baritone/api/pathing/goals/GoalAxis.java @@ -42,6 +42,11 @@ public class GoalAxis implements Goal { return flatAxisDistance * BaritoneAPI.getSettings().costHeuristic.value + GoalYLevel.calculate(BaritoneAPI.getSettings().axisHeight.value, y); } + @Override + public boolean equals(Object o) { + return o.getClass() == GoalAxis.class; + } + @Override public String toString() { return "GoalAxis"; diff --git a/src/api/java/baritone/api/pathing/goals/GoalBlock.java b/src/api/java/baritone/api/pathing/goals/GoalBlock.java index bd339549b..ad2c3eadb 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalBlock.java +++ b/src/api/java/baritone/api/pathing/goals/GoalBlock.java @@ -66,6 +66,17 @@ public class GoalBlock implements Goal, IGoalRenderPos { return calculate(xDiff, yDiff, zDiff); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalBlock goal = (GoalBlock) o; + if (x != goal.x) return false; + if (y != goal.y) return false; + return z == goal.z; + } + @Override public String toString() { return String.format( diff --git a/src/api/java/baritone/api/pathing/goals/GoalComposite.java b/src/api/java/baritone/api/pathing/goals/GoalComposite.java index 47522492b..f407fe733 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalComposite.java +++ b/src/api/java/baritone/api/pathing/goals/GoalComposite.java @@ -67,6 +67,15 @@ public class GoalComposite implements Goal { return min; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalComposite goal = (GoalComposite) o; + return Arrays.equals(goals, goal.goals); + } + @Override public String toString() { return "GoalComposite" + Arrays.toString(goals); diff --git a/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java b/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java index 8d6fdcb30..3d2c0713a 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java +++ b/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java @@ -60,6 +60,17 @@ public class GoalGetToBlock implements Goal, IGoalRenderPos { return GoalBlock.calculate(xDiff, yDiff < 0 ? yDiff + 1 : yDiff, zDiff); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalGetToBlock goal = (GoalGetToBlock) o; + if (x != goal.x) return false; + if (y != goal.y) return false; + return z == goal.z; + } + @Override public String toString() { return String.format( diff --git a/src/api/java/baritone/api/pathing/goals/GoalInverted.java b/src/api/java/baritone/api/pathing/goals/GoalInverted.java index 354e2ce39..acfdd68b2 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalInverted.java +++ b/src/api/java/baritone/api/pathing/goals/GoalInverted.java @@ -17,6 +17,8 @@ package baritone.api.pathing.goals; +import java.util.Objects; + /** * Invert any goal. *

@@ -50,6 +52,15 @@ public class GoalInverted implements Goal { return Double.NEGATIVE_INFINITY; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalInverted goal = (GoalInverted) o; + return Objects.equals(origin, goal.origin); + } + @Override public String toString() { return String.format("GoalInverted{%s}", origin.toString()); diff --git a/src/api/java/baritone/api/pathing/goals/GoalNear.java b/src/api/java/baritone/api/pathing/goals/GoalNear.java index 2252446cd..44f0ab040 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalNear.java +++ b/src/api/java/baritone/api/pathing/goals/GoalNear.java @@ -86,6 +86,18 @@ public class GoalNear implements Goal, IGoalRenderPos { return new BlockPos(x, y, z); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalNear goal = (GoalNear) o; + if (x != goal.x) return false; + if (y != goal.y) return false; + if (z != goal.z) return false; + return rangeSq == goal.rangeSq; + } + @Override public String toString() { return String.format( diff --git a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java index b704ae4a6..3d7caa734 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java +++ b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java @@ -23,6 +23,7 @@ import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet; import net.minecraft.util.math.BlockPos; import java.util.Arrays; +import java.util.Objects; /** * Useful for automated combat (retreating specifically) @@ -124,6 +125,17 @@ public class GoalRunAway implements Goal { return maxInside; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalRunAway goal = (GoalRunAway) o; + if (distanceSq != goal.distanceSq) return false; + if (!Arrays.equals(from, goal.from)) return false; + return Objects.equals(maintainY, goal.maintainY); + } + @Override public String toString() { if (maintainY != null) { diff --git a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java index e93f47ac0..86208f0ca 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java +++ b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java @@ -69,6 +69,19 @@ public class GoalStrictDirection implements Goal { return Double.NEGATIVE_INFINITY; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalStrictDirection goal = (GoalStrictDirection) o; + if (x != goal.x) return false; + if (y != goal.y) return false; + if (z != goal.z) return false; + if (dx != goal.dx) return false; + return dz == goal.dz; + } + @Override public String toString() { return String.format( diff --git a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java index 27be981e4..4df65f609 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java +++ b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java @@ -72,6 +72,17 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos { return new BlockPos(x, y, z); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalTwoBlocks goal = (GoalTwoBlocks) o; + if (x != goal.x) return false; + if (y != goal.y) return false; + return z == goal.z; + } + @Override public String toString() { return String.format( diff --git a/src/api/java/baritone/api/pathing/goals/GoalXZ.java b/src/api/java/baritone/api/pathing/goals/GoalXZ.java index 63d39cd78..c77743389 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalXZ.java +++ b/src/api/java/baritone/api/pathing/goals/GoalXZ.java @@ -64,6 +64,16 @@ public class GoalXZ implements Goal { return calculate(xDiff, zDiff); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalXZ goal = (GoalXZ) o; + if (x != goal.x) return false; + return z == goal.z; + } + @Override public String toString() { return String.format( diff --git a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java index 603ef9bd1..8fc7850b9 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java +++ b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java @@ -58,6 +58,15 @@ public class GoalYLevel implements Goal, ActionCosts { return 0; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GoalYLevel goal = (GoalYLevel) o; + return level == goal.level; + } + @Override public String toString() { return String.format( diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index c7868a4a0..f9514fb95 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -30,10 +30,7 @@ import baritone.api.schematic.ISchematic; import baritone.api.schematic.IStaticSchematic; import baritone.api.schematic.SubstituteSchematic; import baritone.api.schematic.format.ISchematicFormat; -import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.RayTraceUtils; -import baritone.api.utils.Rotation; -import baritone.api.utils.RotationUtils; +import baritone.api.utils.*; import baritone.api.utils.input.Input; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; @@ -764,6 +761,16 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return primary.heuristic(x, y, z); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JankyGoalComposite goal = (JankyGoalComposite) o; + if (!Objects.equals(primary, goal.primary)) return false; + return Objects.equals(fallback, goal.fallback); + } + @Override public String toString() { return "JankyComposite Primary: " + primary + " Fallback: " + fallback; @@ -785,6 +792,16 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil // but any other adjacent works for breaking, including inside or below return super.isInGoal(x, y, z); } + + @Override + public String toString() { + return String.format( + "GoalBreak{x=%s,y=%s,z=%s}", + SettingsUtil.maybeCensor(x), + SettingsUtil.maybeCensor(y), + SettingsUtil.maybeCensor(z) + ); + } } private Goal placementGoal(BlockPos pos, BuilderCalculationContext bcc) { @@ -828,6 +845,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil this.allowSameLevel = allowSameLevel; } + @Override public boolean isInGoal(int x, int y, int z) { if (x == this.x && y == this.y && z == this.z) { return false; @@ -844,10 +862,30 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return super.isInGoal(x, y, z); } + @Override public double heuristic(int x, int y, int z) { // prioritize lower y coordinates return this.y * 100 + super.heuristic(x, y, z); } + + @Override + public boolean equals(Object o) { + if (!super.equals(o)) return false; + + GoalAdjacent goal = (GoalAdjacent) o; + if (allowSameLevel != goal.allowSameLevel) return false; + return Objects.equals(no, goal.no); + } + + @Override + public String toString() { + return String.format( + "GoalAdjacent{x=%s,y=%s,z=%s}", + SettingsUtil.maybeCensor(x), + SettingsUtil.maybeCensor(y), + SettingsUtil.maybeCensor(z) + ); + } } public static class GoalPlace extends GoalBlock { @@ -856,10 +894,21 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil super(placeAt.up()); } + @Override public double heuristic(int x, int y, int z) { // prioritize lower y coordinates return this.y * 100 + super.heuristic(x, y, z); } + + @Override + public String toString() { + return String.format( + "GoalPlace{x=%s,y=%s,z=%s}", + SettingsUtil.maybeCensor(x), + SettingsUtil.maybeCensor(y), + SettingsUtil.maybeCensor(z) + ); + } } @Override diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 6880dd86c..866dcc19d 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -319,6 +319,21 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro int zDiff = z - this.z; return GoalBlock.calculate(xDiff, yDiff < -1 ? yDiff + 2 : yDiff == -1 ? 0 : yDiff, zDiff); } + + @Override + public boolean equals(Object o) { + return super.equals(o); + } + + @Override + public String toString() { + return String.format( + "GoalThreeBlocks{x=%s,y=%s,z=%s}", + SettingsUtil.maybeCensor(x), + SettingsUtil.maybeCensor(y), + SettingsUtil.maybeCensor(z) + ); + } } public List droppedItemsScan() { diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index a83e53a1e..236e41cc6 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -160,7 +160,7 @@ public class PathingControlManager implements IPathingControlManager { if (newGoal.isInGoal(current.getPath().getDest())) { return false; } - return !newGoal.toString().equals(current.getPath().getGoal().toString()); + return !newGoal.equals(current.getPath().getGoal()); } return false; } From 5bdd5b0c0d095797021481a8816600c954883335 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 16:50:02 -0500 Subject: [PATCH 22/35] =?UTF-8?q?=F0=9F=91=8C=20appease=20leijurv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baritone/api/pathing/goals/GoalBlock.java | 14 ++++++++----- .../api/pathing/goals/GoalComposite.java | 8 ++++++-- .../api/pathing/goals/GoalGetToBlock.java | 14 ++++++++----- .../api/pathing/goals/GoalInverted.java | 8 ++++++-- .../baritone/api/pathing/goals/GoalNear.java | 16 +++++++++------ .../api/pathing/goals/GoalRunAway.java | 14 ++++++++----- .../pathing/goals/GoalStrictDirection.java | 18 ++++++++++------- .../api/pathing/goals/GoalTwoBlocks.java | 14 ++++++++----- .../baritone/api/pathing/goals/GoalXZ.java | 11 ++++++---- .../api/pathing/goals/GoalYLevel.java | 8 ++++++-- .../java/baritone/process/BuilderProcess.java | 20 ++++++++++++------- 11 files changed, 95 insertions(+), 50 deletions(-) diff --git a/src/api/java/baritone/api/pathing/goals/GoalBlock.java b/src/api/java/baritone/api/pathing/goals/GoalBlock.java index ad2c3eadb..68d783aa3 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalBlock.java +++ b/src/api/java/baritone/api/pathing/goals/GoalBlock.java @@ -68,13 +68,17 @@ public class GoalBlock implements Goal, IGoalRenderPos { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalBlock goal = (GoalBlock) o; - if (x != goal.x) return false; - if (y != goal.y) return false; - return z == goal.z; + return x == goal.x + && y != goal.y + && z == goal.z; } @Override diff --git a/src/api/java/baritone/api/pathing/goals/GoalComposite.java b/src/api/java/baritone/api/pathing/goals/GoalComposite.java index f407fe733..d64f8e33e 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalComposite.java +++ b/src/api/java/baritone/api/pathing/goals/GoalComposite.java @@ -69,8 +69,12 @@ public class GoalComposite implements Goal { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalComposite goal = (GoalComposite) o; return Arrays.equals(goals, goal.goals); diff --git a/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java b/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java index 3d2c0713a..b5caafa48 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java +++ b/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java @@ -62,13 +62,17 @@ public class GoalGetToBlock implements Goal, IGoalRenderPos { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalGetToBlock goal = (GoalGetToBlock) o; - if (x != goal.x) return false; - if (y != goal.y) return false; - return z == goal.z; + return x == goal.x + && y == goal.y + && z == goal.z; } @Override diff --git a/src/api/java/baritone/api/pathing/goals/GoalInverted.java b/src/api/java/baritone/api/pathing/goals/GoalInverted.java index acfdd68b2..e559088ef 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalInverted.java +++ b/src/api/java/baritone/api/pathing/goals/GoalInverted.java @@ -54,8 +54,12 @@ public class GoalInverted implements Goal { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalInverted goal = (GoalInverted) o; return Objects.equals(origin, goal.origin); diff --git a/src/api/java/baritone/api/pathing/goals/GoalNear.java b/src/api/java/baritone/api/pathing/goals/GoalNear.java index 44f0ab040..166138ff4 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalNear.java +++ b/src/api/java/baritone/api/pathing/goals/GoalNear.java @@ -88,14 +88,18 @@ public class GoalNear implements Goal, IGoalRenderPos { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalNear goal = (GoalNear) o; - if (x != goal.x) return false; - if (y != goal.y) return false; - if (z != goal.z) return false; - return rangeSq == goal.rangeSq; + return x == goal.x + && y == goal.y + && z == goal.z + && rangeSq == goal.rangeSq; } @Override diff --git a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java index 3d7caa734..166ad5a98 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java +++ b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java @@ -127,13 +127,17 @@ public class GoalRunAway implements Goal { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalRunAway goal = (GoalRunAway) o; - if (distanceSq != goal.distanceSq) return false; - if (!Arrays.equals(from, goal.from)) return false; - return Objects.equals(maintainY, goal.maintainY); + return distanceSq == goal.distanceSq + && Arrays.equals(from, goal.from) + && Objects.equals(maintainY, goal.maintainY); } @Override diff --git a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java index 86208f0ca..3d9909ad1 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java +++ b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java @@ -71,15 +71,19 @@ public class GoalStrictDirection implements Goal { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalStrictDirection goal = (GoalStrictDirection) o; - if (x != goal.x) return false; - if (y != goal.y) return false; - if (z != goal.z) return false; - if (dx != goal.dx) return false; - return dz == goal.dz; + return x == goal.x + && y != goal.y + && z == goal.z + && dx == goal.dx + && dz == goal.dz; } @Override diff --git a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java index 4df65f609..d6fff33a2 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java +++ b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java @@ -74,13 +74,17 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalTwoBlocks goal = (GoalTwoBlocks) o; - if (x != goal.x) return false; - if (y != goal.y) return false; - return z == goal.z; + return x == goal.x + && y == goal.y + && z == goal.z; } @Override diff --git a/src/api/java/baritone/api/pathing/goals/GoalXZ.java b/src/api/java/baritone/api/pathing/goals/GoalXZ.java index c77743389..2c551d395 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalXZ.java +++ b/src/api/java/baritone/api/pathing/goals/GoalXZ.java @@ -66,12 +66,15 @@ public class GoalXZ implements Goal { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalXZ goal = (GoalXZ) o; - if (x != goal.x) return false; - return z == goal.z; + return x == goal.x && z == goal.z; } @Override diff --git a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java index 8fc7850b9..37745e8de 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java +++ b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java @@ -60,8 +60,12 @@ public class GoalYLevel implements Goal, ActionCosts { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } GoalYLevel goal = (GoalYLevel) o; return level == goal.level; diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index f9514fb95..69368282d 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -763,12 +763,16 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } JankyGoalComposite goal = (JankyGoalComposite) o; - if (!Objects.equals(primary, goal.primary)) return false; - return Objects.equals(fallback, goal.fallback); + return Objects.equals(primary, goal.primary) + && Objects.equals(fallback, goal.fallback); } @Override @@ -870,11 +874,13 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public boolean equals(Object o) { - if (!super.equals(o)) return false; + if (!super.equals(o)) { + return false; + } GoalAdjacent goal = (GoalAdjacent) o; - if (allowSameLevel != goal.allowSameLevel) return false; - return Objects.equals(no, goal.no); + return allowSameLevel == goal.allowSameLevel + && Objects.equals(no, goal.no); } @Override From 8a65a1cfc593be38405bf9420be17988f93959c7 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 16:52:20 -0500 Subject: [PATCH 23/35] =?UTF-8?q?=F0=9F=90=9B=20fix=20incorrect=20comparis?= =?UTF-8?q?on=20operator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/java/baritone/api/pathing/goals/GoalBlock.java | 2 +- .../java/baritone/api/pathing/goals/GoalStrictDirection.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/pathing/goals/GoalBlock.java b/src/api/java/baritone/api/pathing/goals/GoalBlock.java index 68d783aa3..d76fdc7af 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalBlock.java +++ b/src/api/java/baritone/api/pathing/goals/GoalBlock.java @@ -77,7 +77,7 @@ public class GoalBlock implements Goal, IGoalRenderPos { GoalBlock goal = (GoalBlock) o; return x == goal.x - && y != goal.y + && y == goal.y && z == goal.z; } diff --git a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java index 3d9909ad1..b8e4b43b2 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java +++ b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java @@ -80,7 +80,7 @@ public class GoalStrictDirection implements Goal { GoalStrictDirection goal = (GoalStrictDirection) o; return x == goal.x - && y != goal.y + && y == goal.y && z == goal.z && dx == goal.dx && dz == goal.dz; From c217a34f1368bff64bbf8123e9c7eae1a89e3881 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 17:05:56 -0500 Subject: [PATCH 24/35] =?UTF-8?q?=F0=9F=90=9B=20fix=20batch=20render=20col?= =?UTF-8?q?or=20bug=20by=20backporting=201.17+=20render=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/baritone/utils/IRenderer.java | 57 ++++++++++--------- .../java/baritone/utils/PathRenderer.java | 52 ++++++++--------- 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/main/java/baritone/utils/IRenderer.java b/src/main/java/baritone/utils/IRenderer.java index 3476c0307..26a7cf1ad 100644 --- a/src/main/java/baritone/utils/IRenderer.java +++ b/src/main/java/baritone/utils/IRenderer.java @@ -38,9 +38,14 @@ public interface IRenderer { RenderManager renderManager = Helper.mc.getRenderManager(); Settings settings = BaritoneAPI.getSettings(); + float[] color = new float[] {1.0F, 1.0F, 1.0F, 255.0F}; + static void glColor(Color color, float alpha) { float[] colorComponents = color.getColorComponents(null); - GlStateManager.color(colorComponents[0], colorComponents[1], colorComponents[2], alpha); + IRenderer.color[0] = colorComponents[0]; + IRenderer.color[1] = colorComponents[1]; + IRenderer.color[2] = colorComponents[2]; + IRenderer.color[3] = alpha; } static void startLines(Color color, float alpha, float lineWidth, boolean ignoreDepth) { @@ -54,7 +59,7 @@ public interface IRenderer { if (ignoreDepth) { GlStateManager.disableDepth(); } - buffer.begin(GL_LINES, DefaultVertexFormats.POSITION); + buffer.begin(GL_LINES, DefaultVertexFormats.POSITION_COLOR); } static void startLines(Color color, float lineWidth, boolean ignoreDepth) { @@ -76,32 +81,32 @@ public interface IRenderer { AxisAlignedBB toDraw = aabb.offset(-renderManager.viewerPosX, -renderManager.viewerPosY, -renderManager.viewerPosZ); // bottom - buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); + buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); // top - buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); + buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); // corners - buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); - buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); + buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); } static void emitAABB(AxisAlignedBB aabb, double expand) { diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 2aef0ab54..deec261d4 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -165,18 +165,18 @@ public final class PathRenderer implements IRenderer { double vpZ = renderManager.viewerPosZ; boolean renderPathAsFrickinThingy = !settings.renderPathAsLine.value; - buffer.pos(x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ).endVertex(); - buffer.pos(x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ).endVertex(); + buffer.pos(x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ).color(color[0], color[1], color[2], color[3]).endVertex(); if (renderPathAsFrickinThingy) { - buffer.pos(x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ).endVertex(); - buffer.pos(x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ).endVertex(); + buffer.pos(x2 + 0.5D - vpX, y2 + 0.5D - vpY, z2 + 0.5D - vpZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ).color(color[0], color[1], color[2], color[3]).endVertex(); - buffer.pos(x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ).endVertex(); - buffer.pos(x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ).endVertex(); + buffer.pos(x2 + 0.5D - vpX, y2 + 0.53D - vpY, z2 + 0.5D - vpZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ).color(color[0], color[1], color[2], color[3]).endVertex(); - buffer.pos(x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ).endVertex(); - buffer.pos(x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ).endVertex(); + buffer.pos(x1 + 0.5D - vpX, y1 + 0.53D - vpY, z1 + 0.5D - vpZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(x1 + 0.5D - vpX, y1 + 0.5D - vpY, z1 + 0.5D - vpZ).color(color[0], color[1], color[2], color[3]).endVertex(); } } @@ -310,22 +310,22 @@ public final class PathRenderer implements IRenderer { } } - private static void drawDankLitGoalBox(Color color, double minX, double maxX, double minZ, double maxZ, double minY, double maxY, double y1, double y2, boolean setupRender) { + private static void drawDankLitGoalBox(Color colorIn, double minX, double maxX, double minZ, double maxZ, double minY, double maxY, double y1, double y2, boolean setupRender) { if (setupRender) { - IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value); + IRenderer.startLines(colorIn, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value); } renderHorizontalQuad(minX, maxX, minZ, maxZ, y1); renderHorizontalQuad(minX, maxX, minZ, maxZ, y2); - buffer.pos(minX, minY, minZ).endVertex(); - buffer.pos(minX, maxY, minZ).endVertex(); - buffer.pos(maxX, minY, minZ).endVertex(); - buffer.pos(maxX, maxY, minZ).endVertex(); - buffer.pos(maxX, minY, maxZ).endVertex(); - buffer.pos(maxX, maxY, maxZ).endVertex(); - buffer.pos(minX, minY, maxZ).endVertex(); - buffer.pos(minX, maxY, maxZ).endVertex(); + buffer.pos(minX, minY, minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(minX, maxY, minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(maxX, minY, minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(maxX, maxY, minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(maxX, minY, maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(maxX, maxY, maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(minX, minY, maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(minX, maxY, maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); if (setupRender) { IRenderer.endLines(settings.renderGoalIgnoreDepth.value); @@ -334,17 +334,17 @@ public final class PathRenderer implements IRenderer { private static void renderHorizontalQuad(double minX, double maxX, double minZ, double maxZ, double y) { if (y != 0) { - buffer.pos(minX, y, minZ).endVertex(); - buffer.pos(maxX, y, minZ).endVertex(); + buffer.pos(minX, y, minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(maxX, y, minZ).color(color[0], color[1], color[2], color[3]).endVertex(); - buffer.pos(maxX, y, minZ).endVertex(); - buffer.pos(maxX, y, maxZ).endVertex(); + buffer.pos(maxX, y, minZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(maxX, y, maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); - buffer.pos(maxX, y, maxZ).endVertex(); - buffer.pos(minX, y, maxZ).endVertex(); + buffer.pos(maxX, y, maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(minX, y, maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); - buffer.pos(minX, y, maxZ).endVertex(); - buffer.pos(minX, y, minZ).endVertex(); + buffer.pos(minX, y, maxZ).color(color[0], color[1], color[2], color[3]).endVertex(); + buffer.pos(minX, y, minZ).color(color[0], color[1], color[2], color[3]).endVertex(); } } } From 13fc58933d6cf1db497d5303d290f65588b6c652 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 19:03:03 -0500 Subject: [PATCH 25/35] Don't bother returning `serverRotations` if no free look --- src/main/java/baritone/behavior/LookBehavior.java | 12 +++++++++--- .../baritone/utils/player/PrimaryPlayerContext.java | 7 ++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 1e109482c..702c3738d 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -28,6 +28,8 @@ import baritone.api.utils.IPlayerContext; import baritone.api.utils.Rotation; import net.minecraft.network.play.client.CPacketPlayer; +import java.util.Optional; + public final class LookBehavior extends Behavior implements ILookBehavior { /** @@ -70,9 +72,9 @@ public final class LookBehavior extends Behavior implements ILookBehavior { this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); } - ctx.player().rotationYaw = this.target.rotation.getYaw(); float oldPitch = ctx.playerRotations().getPitch(); float desiredPitch = this.target.rotation.getPitch(); + ctx.player().rotationYaw = this.target.rotation.getYaw(); ctx.player().rotationPitch = desiredPitch; ctx.player().rotationYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; ctx.player().rotationPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; @@ -126,8 +128,12 @@ public final class LookBehavior extends Behavior implements ILookBehavior { } } - public Rotation getEffectiveRotation() { - return this.serverRotation; + public Optional getEffectiveRotation() { + if (Baritone.settings().freeLook.value || Baritone.settings().blockFreeLook.value) { + return Optional.of(this.serverRotation); + } + // If neither of the freeLook settings are on, just defer to the player's actual rotations + return Optional.empty(); } @Override diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index e4484f0be..20d82f2bc 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -58,11 +58,8 @@ public enum PrimaryPlayerContext implements IPlayerContext, Helper { @Override public Rotation playerRotations() { - final Rotation lbTarget = ((LookBehavior) BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()).getEffectiveRotation(); - if (lbTarget == null || !Baritone.settings().blockFreeLook.value) { - return IPlayerContext.super.playerRotations(); - } - return lbTarget; + return ((LookBehavior) BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()).getEffectiveRotation() + .orElseGet(IPlayerContext.super::playerRotations); } @Override From 4885d49d20debf7bc4f8328c11e08549e57c5abe Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 20:00:03 -0500 Subject: [PATCH 26/35] Reorganize code --- .../java/baritone/behavior/LookBehavior.java | 32 ++++++++++++------- .../utils/player/PrimaryPlayerContext.java | 1 - 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 702c3738d..db0c255f7 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -72,16 +72,23 @@ public final class LookBehavior extends Behavior implements ILookBehavior { this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); } - float oldPitch = ctx.playerRotations().getPitch(); + final float oldPitch = ctx.playerRotations().getPitch(); + + float desiredYaw = this.target.rotation.getYaw(); float desiredPitch = this.target.rotation.getPitch(); - ctx.player().rotationYaw = this.target.rotation.getYaw(); - ctx.player().rotationPitch = desiredPitch; - ctx.player().rotationYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; - ctx.player().rotationPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; + + // In other words, the target doesn't care about the pitch, so it used playerRotations().getPitch() + // and it's safe to adjust it to a normal level if (desiredPitch == oldPitch) { - nudgeToLevel(); + desiredPitch = nudgeToLevel(desiredPitch); } + desiredYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; + desiredPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; + + ctx.player().rotationYaw = desiredYaw; + ctx.player().rotationPitch = desiredPitch; + if (this.target.mode == Target.Mode.CLIENT) { // The target can be invalidated now since it won't be needed for RotationMoveEvent this.target = null; @@ -130,7 +137,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior { public Optional getEffectiveRotation() { if (Baritone.settings().freeLook.value || Baritone.settings().blockFreeLook.value) { - return Optional.of(this.serverRotation); + return Optional.ofNullable(this.serverRotation); } // If neither of the freeLook settings are on, just defer to the player's actual rotations return Optional.empty(); @@ -146,12 +153,13 @@ public final class LookBehavior extends Behavior implements ILookBehavior { /** * Nudges the player's pitch to a regular level. (Between {@code -20} and {@code 10}, increments are by {@code 1}) */ - private void nudgeToLevel() { - if (ctx.player().rotationPitch < -20) { - ctx.player().rotationPitch++; - } else if (ctx.player().rotationPitch > 10) { - ctx.player().rotationPitch--; + private float nudgeToLevel(float pitch) { + if (pitch < -20) { + return pitch + 1; + } else if (pitch > 10) { + return pitch - 1; } + return pitch; } private static class Target { diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index 20d82f2bc..02db73a5c 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -17,7 +17,6 @@ package baritone.utils.player; -import baritone.Baritone; import baritone.api.BaritoneAPI; import baritone.api.cache.IWorldData; import baritone.api.utils.*; From c8b8deb3d62d5a786054fd1939293cb71673258c Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 21:04:30 -0500 Subject: [PATCH 27/35] Ensure angle delta is producible with mouse movement --- .../java/baritone/behavior/LookBehavior.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index db0c255f7..99e496e6f 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -24,6 +24,7 @@ import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.RotationMoveEvent; import baritone.api.event.events.WorldEvent; +import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; import baritone.api.utils.Rotation; import net.minecraft.network.play.client.CPacketPlayer; @@ -72,6 +73,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior { this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); } + final float oldYaw = ctx.playerRotations().getYaw(); final float oldPitch = ctx.playerRotations().getPitch(); float desiredYaw = this.target.rotation.getYaw(); @@ -86,8 +88,8 @@ public final class LookBehavior extends Behavior implements ILookBehavior { desiredYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; desiredPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; - ctx.player().rotationYaw = desiredYaw; - ctx.player().rotationPitch = desiredPitch; + ctx.player().rotationYaw = calculateMouseMove(oldYaw, desiredYaw); + ctx.player().rotationPitch = calculateMouseMove(oldPitch, desiredPitch); if (this.target.mode == Target.Mode.CLIENT) { // The target can be invalidated now since it won't be needed for RotationMoveEvent @@ -153,7 +155,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior { /** * Nudges the player's pitch to a regular level. (Between {@code -20} and {@code 10}, increments are by {@code 1}) */ - private float nudgeToLevel(float pitch) { + private static float nudgeToLevel(float pitch) { if (pitch < -20) { return pitch + 1; } else if (pitch > 10) { @@ -162,6 +164,22 @@ public final class LookBehavior extends Behavior implements ILookBehavior { return pitch; } + private static float calculateMouseMove(float current, float target) { + final float delta = target - current; + final int deltaPx = angleToMouse(delta); + return current + mouseToAngle(deltaPx); + } + + private static int angleToMouse(float angleDelta) { + final float minAngleChange = mouseToAngle(1); + return Math.round(angleDelta / minAngleChange); + } + + private static float mouseToAngle(int mouseDelta) { + final float f = Helper.mc.gameSettings.mouseSensitivity * 0.6f + 0.2f; + return mouseDelta * f * f * f * 8.0f * 0.15f; + } + private static class Target { public final Rotation rotation; From 2022d33d03296a41689fa4cd186b15ecc2e8a324 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 21:12:49 -0500 Subject: [PATCH 28/35] Fix incorrect references to player and world --- .../java/baritone/command/defaults/SurfaceCommand.java | 8 ++++---- .../java/baritone/process/InventoryPauserProcess.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/command/defaults/SurfaceCommand.java b/src/main/java/baritone/command/defaults/SurfaceCommand.java index 842b8050c..5d914aded 100644 --- a/src/main/java/baritone/command/defaults/SurfaceCommand.java +++ b/src/main/java/baritone/command/defaults/SurfaceCommand.java @@ -38,13 +38,13 @@ public class SurfaceCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { - final BetterBlockPos playerPos = baritone.getPlayerContext().playerFeet(); - final int surfaceLevel = baritone.getPlayerContext().world().getSeaLevel(); - final int worldHeight = baritone.getPlayerContext().world().getActualHeight(); + final BetterBlockPos playerPos = ctx.playerFeet(); + final int surfaceLevel = ctx.world().getSeaLevel(); + final int worldHeight = ctx.world().getActualHeight(); // Ensure this command will not run if you are above the surface level and the block above you is air // As this would imply that your are already on the open surface - if (playerPos.getY() > surfaceLevel && mc.world.getBlockState(playerPos.up()).getBlock() instanceof BlockAir) { + if (playerPos.getY() > surfaceLevel && ctx.world().getBlockState(playerPos.up()).getBlock() instanceof BlockAir) { logDirect("Already at surface"); return; } diff --git a/src/main/java/baritone/process/InventoryPauserProcess.java b/src/main/java/baritone/process/InventoryPauserProcess.java index ab210532b..9752912b9 100644 --- a/src/main/java/baritone/process/InventoryPauserProcess.java +++ b/src/main/java/baritone/process/InventoryPauserProcess.java @@ -34,14 +34,14 @@ public class InventoryPauserProcess extends BaritoneProcessHelper { @Override public boolean isActive() { - if (mc.player == null || mc.world == null) { + if (ctx.player() == null || ctx.world() == null) { return false; } return true; } private double motion() { - return Math.sqrt(mc.player.motionX * mc.player.motionX + mc.player.motionZ * mc.player.motionZ); + return Math.sqrt(ctx.player().motionX * ctx.player().motionX + ctx.player().motionZ * ctx.player().motionZ); } private boolean stationaryNow() { From 76fe0d14d3199cf219d3a67ddada62f0153aa702 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 12 Jun 2023 21:13:10 -0500 Subject: [PATCH 29/35] Simplify some player context references --- src/main/java/baritone/command/defaults/GoalCommand.java | 2 +- src/main/java/baritone/command/defaults/GotoCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/command/defaults/GoalCommand.java b/src/main/java/baritone/command/defaults/GoalCommand.java index 40822e057..a174ecad9 100644 --- a/src/main/java/baritone/command/defaults/GoalCommand.java +++ b/src/main/java/baritone/command/defaults/GoalCommand.java @@ -51,7 +51,7 @@ public class GoalCommand extends Command { } } else { args.requireMax(3); - BetterBlockPos origin = baritone.getPlayerContext().playerFeet(); + BetterBlockPos origin = ctx.playerFeet(); Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin); goalProcess.setGoal(goal); logDirect(String.format("Goal: %s", goal.toString())); diff --git a/src/main/java/baritone/command/defaults/GotoCommand.java b/src/main/java/baritone/command/defaults/GotoCommand.java index 896e3f5f8..333d7fa57 100644 --- a/src/main/java/baritone/command/defaults/GotoCommand.java +++ b/src/main/java/baritone/command/defaults/GotoCommand.java @@ -46,7 +46,7 @@ public class GotoCommand extends Command { // is no need to handle the case of empty arguments. if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { args.requireMax(3); - BetterBlockPos origin = baritone.getPlayerContext().playerFeet(); + BetterBlockPos origin = ctx.playerFeet(); Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin); logDirect(String.format("Going to: %s", goal.toString())); baritone.getCustomGoalProcess().setGoalAndPath(goal); From 88e604426c64951d5f2a1a6818a16aab45b55651 Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 13 Jun 2023 21:30:31 -0700 Subject: [PATCH 30/35] 1.20.1 --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ae8090d7..c135ebdf8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ Minecraft Minecraft Minecraft - Minecraft + Minecraft + Minecraft + Minecraft

@@ -64,6 +66,7 @@ Baritone is the pathfinding system used in [Impact](https://impactclient.net/) s | [1.19.2 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.4/baritone-api-forge-1.9.4.jar) | [1.19.2 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.4/baritone-api-fabric-1.9.4.jar) | | [1.19.3 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.1/baritone-api-forge-1.9.1.jar) | [1.19.3 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.1/baritone-api-fabric-1.9.1.jar) | | [1.19.4 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.3/baritone-api-forge-1.9.3.jar) | [1.19.4 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.3/baritone-api-fabric-1.9.3.jar) | +| [1.20.1 Forge](https://github.com/cabaletta/baritone/releases/download/v1.10.1/baritone-api-forge-1.10.1.jar) | [1.20.1 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.10.1/baritone-api-fabric-1.10.1.jar) | **How to immediately get started:** Type `#goto 1000 500` in chat to go to x=1000 z=500. Type `#mine diamond_ore` to mine diamond ore. Type `#stop` to stop. For more, read [the usage page](USAGE.md) and/or watch this [tutorial playlist](https://www.youtube.com/playlist?list=PLnwnJ1qsS7CoQl9Si-RTluuzCo_4Oulpa) From 5e724c1e3af7e67466664548694fa2bfaac5145a Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 13 Jun 2023 21:31:10 -0700 Subject: [PATCH 31/35] making these clickable was a mistake --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c135ebdf8..5fefcdf47 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,16 @@

- Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft

From 6a80b0d4ffea38131462557e67f56c0d2ca42701 Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 13 Jun 2023 21:31:49 -0700 Subject: [PATCH 32/35] forgot github markdown is stupid --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5fefcdf47..11fed3581 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,16 @@

- Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft

From 54f0a3c14c63cc58f1188daaa329d660c898b6c9 Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 13 Jun 2023 21:32:21 -0700 Subject: [PATCH 33/35] marginally better --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 11fed3581..c6a90ff93 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,16 @@

- Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft

From b03d31e99013be1283f7701c1ced02afcd012105 Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 13 Jun 2023 21:32:57 -0700 Subject: [PATCH 34/35] will github let me do this --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c6a90ff93..bbb386a74 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Baritone is the pathfinding system used in [Impact](https://impactclient.net/) s [**Baritone Discord Server**](http://discord.gg/s6fRBAUpmr) **Quick download links:** - +

| Forge | Fabric | |---------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------| | [1.12.2 Forge](https://github.com/cabaletta/baritone/releases/download/v1.2.17/baritone-api-forge-1.2.17.jar) | | @@ -67,7 +67,7 @@ Baritone is the pathfinding system used in [Impact](https://impactclient.net/) s | [1.19.3 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.1/baritone-api-forge-1.9.1.jar) | [1.19.3 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.1/baritone-api-fabric-1.9.1.jar) | | [1.19.4 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.3/baritone-api-forge-1.9.3.jar) | [1.19.4 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.3/baritone-api-fabric-1.9.3.jar) | | [1.20.1 Forge](https://github.com/cabaletta/baritone/releases/download/v1.10.1/baritone-api-forge-1.10.1.jar) | [1.20.1 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.10.1/baritone-api-fabric-1.10.1.jar) | - +

**How to immediately get started:** Type `#goto 1000 500` in chat to go to x=1000 z=500. Type `#mine diamond_ore` to mine diamond ore. Type `#stop` to stop. For more, read [the usage page](USAGE.md) and/or watch this [tutorial playlist](https://www.youtube.com/playlist?list=PLnwnJ1qsS7CoQl9Si-RTluuzCo_4Oulpa) For other versions of Minecraft or more complicated situations or for development, see [Installation & setup](SETUP.md). Also consider just installing [Impact](https://impactclient.net/), which comes with Baritone and is easier to install than wrangling with version JSONs and zips. For 1.16.5, [click here](https://www.youtube.com/watch?v=_4eVJ9Qz2J8) and see description. Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#6313 on Baritone which I recommend. From 3662b3fdf18e4acba7cf9022f1143367f4737887 Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 13 Jun 2023 21:33:12 -0700 Subject: [PATCH 35/35] nope --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bbb386a74..c6a90ff93 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Baritone is the pathfinding system used in [Impact](https://impactclient.net/) s [**Baritone Discord Server**](http://discord.gg/s6fRBAUpmr) **Quick download links:** -

+ | Forge | Fabric | |---------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------| | [1.12.2 Forge](https://github.com/cabaletta/baritone/releases/download/v1.2.17/baritone-api-forge-1.2.17.jar) | | @@ -67,7 +67,7 @@ Baritone is the pathfinding system used in [Impact](https://impactclient.net/) s | [1.19.3 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.1/baritone-api-forge-1.9.1.jar) | [1.19.3 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.1/baritone-api-fabric-1.9.1.jar) | | [1.19.4 Forge](https://github.com/cabaletta/baritone/releases/download/v1.9.3/baritone-api-forge-1.9.3.jar) | [1.19.4 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.9.3/baritone-api-fabric-1.9.3.jar) | | [1.20.1 Forge](https://github.com/cabaletta/baritone/releases/download/v1.10.1/baritone-api-forge-1.10.1.jar) | [1.20.1 Fabric](https://github.com/cabaletta/baritone/releases/download/v1.10.1/baritone-api-fabric-1.10.1.jar) | -

+ **How to immediately get started:** Type `#goto 1000 500` in chat to go to x=1000 z=500. Type `#mine diamond_ore` to mine diamond ore. Type `#stop` to stop. For more, read [the usage page](USAGE.md) and/or watch this [tutorial playlist](https://www.youtube.com/playlist?list=PLnwnJ1qsS7CoQl9Si-RTluuzCo_4Oulpa) For other versions of Minecraft or more complicated situations or for development, see [Installation & setup](SETUP.md). Also consider just installing [Impact](https://impactclient.net/), which comes with Baritone and is easier to install than wrangling with version JSONs and zips. For 1.16.5, [click here](https://www.youtube.com/watch?v=_4eVJ9Qz2J8) and see description. Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#6313 on Baritone which I recommend.