diff --git a/src/launch/java/baritone/launch/mixins/MixinChunkProviderClient.java b/src/launch/java/baritone/launch/mixins/MixinChunkProviderClient.java
new file mode 100644
index 00000000..b4cada6e
--- /dev/null
+++ b/src/launch/java/baritone/launch/mixins/MixinChunkProviderClient.java
@@ -0,0 +1,39 @@
+/*
+ * 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.launch.mixins;
+
+import baritone.utils.accessor.IChunkProviderClient;
+import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
+import net.minecraft.client.multiplayer.ChunkProviderClient;
+import net.minecraft.world.chunk.Chunk;
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+
+@Mixin(ChunkProviderClient.class)
+public class MixinChunkProviderClient implements IChunkProviderClient {
+
+ @Shadow
+ @Final
+ private Long2ObjectMap loadedChunks;
+
+ @Override
+ public Long2ObjectMap loadedChunks() {
+ return this.loadedChunks;
+ }
+}
diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json
index 9ea70330..09ebbafd 100644
--- a/src/launch/resources/mixins.baritone.json
+++ b/src/launch/resources/mixins.baritone.json
@@ -10,6 +10,7 @@
"client": [
"MixinAnvilChunkLoader",
"MixinBlockPos",
+ "MixinChunkProviderClient",
"MixinChunkProviderServer",
"MixinEntity",
"MixinEntityLivingBase",
diff --git a/src/main/java/baritone/pathing/calc/Path.java b/src/main/java/baritone/pathing/calc/Path.java
index ee3b182b..0b5b2cc7 100644
--- a/src/main/java/baritone/pathing/calc/Path.java
+++ b/src/main/java/baritone/pathing/calc/Path.java
@@ -129,7 +129,7 @@ class Path extends PathBase {
private Movement runBackwards(BetterBlockPos src, BetterBlockPos dest, double cost) {
for (Moves moves : Moves.values()) {
- Movement move = moves.apply0(context.getBaritone(), src);
+ Movement move = moves.apply0(context, src);
if (move.getDest().equals(dest)) {
// have to calculate the cost at calculation time so we can accurately judge whether a cost increase happened between cached calculation and real execution
move.override(cost);
diff --git a/src/main/java/baritone/pathing/movement/Moves.java b/src/main/java/baritone/pathing/movement/Moves.java
index ebb97081..c5a6ceb6 100644
--- a/src/main/java/baritone/pathing/movement/Moves.java
+++ b/src/main/java/baritone/pathing/movement/Moves.java
@@ -17,7 +17,6 @@
package baritone.pathing.movement;
-import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos;
import baritone.pathing.movement.movements.*;
import baritone.utils.pathing.MutableMoveResult;
@@ -31,8 +30,8 @@ import net.minecraft.util.EnumFacing;
public enum Moves {
DOWNWARD(0, -1, 0) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementDownward(baritone, src, src.down());
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementDownward(context.getBaritone(), src, src.down());
}
@Override
@@ -43,8 +42,8 @@ public enum Moves {
PILLAR(0, +1, 0) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementPillar(baritone, src, src.up());
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementPillar(context.getBaritone(), src, src.up());
}
@Override
@@ -55,8 +54,8 @@ public enum Moves {
TRAVERSE_NORTH(0, 0, -1) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementTraverse(baritone, src, src.north());
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementTraverse(context.getBaritone(), src, src.north());
}
@Override
@@ -67,8 +66,8 @@ public enum Moves {
TRAVERSE_SOUTH(0, 0, +1) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementTraverse(baritone, src, src.south());
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementTraverse(context.getBaritone(), src, src.south());
}
@Override
@@ -79,8 +78,8 @@ public enum Moves {
TRAVERSE_EAST(+1, 0, 0) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementTraverse(baritone, src, src.east());
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementTraverse(context.getBaritone(), src, src.east());
}
@Override
@@ -91,8 +90,8 @@ public enum Moves {
TRAVERSE_WEST(-1, 0, 0) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementTraverse(baritone, src, src.west());
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementTraverse(context.getBaritone(), src, src.west());
}
@Override
@@ -103,8 +102,8 @@ public enum Moves {
ASCEND_NORTH(0, +1, -1) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementAscend(baritone, src, new BetterBlockPos(src.x, src.y + 1, src.z - 1));
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x, src.y + 1, src.z - 1));
}
@Override
@@ -115,8 +114,8 @@ public enum Moves {
ASCEND_SOUTH(0, +1, +1) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementAscend(baritone, src, new BetterBlockPos(src.x, src.y + 1, src.z + 1));
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x, src.y + 1, src.z + 1));
}
@Override
@@ -127,8 +126,8 @@ public enum Moves {
ASCEND_EAST(+1, +1, 0) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementAscend(baritone, src, new BetterBlockPos(src.x + 1, src.y + 1, src.z));
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x + 1, src.y + 1, src.z));
}
@Override
@@ -139,8 +138,8 @@ public enum Moves {
ASCEND_WEST(-1, +1, 0) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementAscend(baritone, src, new BetterBlockPos(src.x - 1, src.y + 1, src.z));
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementAscend(context.getBaritone(), src, new BetterBlockPos(src.x - 1, src.y + 1, src.z));
}
@Override
@@ -151,13 +150,13 @@ public enum Moves {
DESCEND_EAST(+1, -1, 0, false, true) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
- apply(new CalculationContext(baritone), src.x, src.y, src.z, res);
+ apply(context, src.x, src.y, src.z, res);
if (res.y == src.y - 1) {
- return new MovementDescend(baritone, src, new BetterBlockPos(res.x, res.y, res.z));
+ return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z));
} else {
- return new MovementFall(baritone, src, new BetterBlockPos(res.x, res.y, res.z));
+ return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z));
}
}
@@ -169,13 +168,13 @@ public enum Moves {
DESCEND_WEST(-1, -1, 0, false, true) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
- apply(new CalculationContext(baritone), src.x, src.y, src.z, res);
+ apply(context, src.x, src.y, src.z, res);
if (res.y == src.y - 1) {
- return new MovementDescend(baritone, src, new BetterBlockPos(res.x, res.y, res.z));
+ return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z));
} else {
- return new MovementFall(baritone, src, new BetterBlockPos(res.x, res.y, res.z));
+ return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z));
}
}
@@ -187,13 +186,13 @@ public enum Moves {
DESCEND_NORTH(0, -1, -1, false, true) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
- apply(new CalculationContext(baritone), src.x, src.y, src.z, res);
+ apply(context, src.x, src.y, src.z, res);
if (res.y == src.y - 1) {
- return new MovementDescend(baritone, src, new BetterBlockPos(res.x, res.y, res.z));
+ return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z));
} else {
- return new MovementFall(baritone, src, new BetterBlockPos(res.x, res.y, res.z));
+ return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z));
}
}
@@ -205,13 +204,13 @@ public enum Moves {
DESCEND_SOUTH(0, -1, +1, false, true) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
- apply(new CalculationContext(baritone), src.x, src.y, src.z, res);
+ apply(context, src.x, src.y, src.z, res);
if (res.y == src.y - 1) {
- return new MovementDescend(baritone, src, new BetterBlockPos(res.x, res.y, res.z));
+ return new MovementDescend(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z));
} else {
- return new MovementFall(baritone, src, new BetterBlockPos(res.x, res.y, res.z));
+ return new MovementFall(context.getBaritone(), src, new BetterBlockPos(res.x, res.y, res.z));
}
}
@@ -223,8 +222,8 @@ public enum Moves {
DIAGONAL_NORTHEAST(+1, 0, -1) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementDiagonal(baritone, src, EnumFacing.NORTH, EnumFacing.EAST);
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.EAST);
}
@Override
@@ -235,8 +234,8 @@ public enum Moves {
DIAGONAL_NORTHWEST(-1, 0, -1) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementDiagonal(baritone, src, EnumFacing.NORTH, EnumFacing.WEST);
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.WEST);
}
@Override
@@ -247,8 +246,8 @@ public enum Moves {
DIAGONAL_SOUTHEAST(+1, 0, +1) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementDiagonal(baritone, src, EnumFacing.SOUTH, EnumFacing.EAST);
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.EAST);
}
@Override
@@ -259,8 +258,8 @@ public enum Moves {
DIAGONAL_SOUTHWEST(-1, 0, +1) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return new MovementDiagonal(baritone, src, EnumFacing.SOUTH, EnumFacing.WEST);
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.WEST);
}
@Override
@@ -271,8 +270,8 @@ public enum Moves {
PARKOUR_NORTH(0, 0, -4, true, false) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return MovementParkour.cost(baritone, src, EnumFacing.NORTH);
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return MovementParkour.cost(context, src, EnumFacing.NORTH);
}
@Override
@@ -283,8 +282,8 @@ public enum Moves {
PARKOUR_SOUTH(0, 0, +4, true, false) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return MovementParkour.cost(baritone, src, EnumFacing.SOUTH);
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return MovementParkour.cost(context, src, EnumFacing.SOUTH);
}
@Override
@@ -295,8 +294,8 @@ public enum Moves {
PARKOUR_EAST(+4, 0, 0, true, false) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return MovementParkour.cost(baritone, src, EnumFacing.EAST);
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return MovementParkour.cost(context, src, EnumFacing.EAST);
}
@Override
@@ -307,8 +306,8 @@ public enum Moves {
PARKOUR_WEST(-4, 0, 0, true, false) {
@Override
- public Movement apply0(IBaritone baritone, BetterBlockPos src) {
- return MovementParkour.cost(baritone, src, EnumFacing.WEST);
+ public Movement apply0(CalculationContext context, BetterBlockPos src) {
+ return MovementParkour.cost(context, src, EnumFacing.WEST);
}
@Override
@@ -336,7 +335,7 @@ public enum Moves {
this(x, y, z, false, false);
}
- public abstract Movement apply0(IBaritone baritone, BetterBlockPos src);
+ public abstract Movement apply0(CalculationContext context, BetterBlockPos src);
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
if (dynamicXZ || dynamicY) {
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java
index 9010251d..80d6feb4 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java
@@ -57,11 +57,11 @@ public class MovementParkour extends Movement {
this.dist = dist;
}
- public static MovementParkour cost(IBaritone baritone, BetterBlockPos src, EnumFacing direction) {
+ public static MovementParkour cost(CalculationContext context, BetterBlockPos src, EnumFacing direction) {
MutableMoveResult res = new MutableMoveResult();
- cost(new CalculationContext(baritone), src.x, src.y, src.z, direction, res);
+ cost(context, src.x, src.y, src.z, direction, res);
int dist = Math.abs(res.x - src.x) + Math.abs(res.z - src.z);
- return new MovementParkour(baritone, src, dist, direction);
+ return new MovementParkour(context.getBaritone(), src, dist, direction);
}
public static void cost(CalculationContext context, int x, int y, int z, EnumFacing dir, MutableMoveResult res) {
diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java
index 5eefe6a9..95f2122b 100644
--- a/src/main/java/baritone/process/GetToBlockProcess.java
+++ b/src/main/java/baritone/process/GetToBlockProcess.java
@@ -24,6 +24,7 @@ import baritone.api.pathing.goals.GoalGetToBlock;
import baritone.api.process.IGetToBlockProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
+import baritone.pathing.movement.CalculationContext;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.block.Block;
import net.minecraft.util.math.BlockPos;
@@ -46,7 +47,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
public void getToBlock(Block block) {
gettingTo = block;
knownLocations = null;
- rescan(new ArrayList<>());
+ rescan(new ArrayList<>(), new CalculationContext(baritone));
}
@Override
@@ -57,7 +58,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (knownLocations == null) {
- rescan(new ArrayList<>());
+ rescan(new ArrayList<>(), new CalculationContext(baritone));
}
if (knownLocations.isEmpty()) {
logDirect("No known locations of " + gettingTo + ", canceling GetToBlock");
@@ -76,7 +77,8 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
List current = new ArrayList<>(knownLocations);
- Baritone.getExecutor().execute(() -> rescan(current));
+ CalculationContext context = new CalculationContext(baritone);
+ Baritone.getExecutor().execute(() -> rescan(current, context));
}
Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new));
if (goal.isInGoal(ctx.playerFeet())) {
@@ -96,7 +98,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
return "Get To Block " + gettingTo;
}
- private void rescan(List known) {
- knownLocations = MineProcess.searchWorld(ctx, Collections.singletonList(gettingTo), 64, known);
+ private void rescan(List known, CalculationContext context) {
+ knownLocations = MineProcess.searchWorld(context, Collections.singletonList(gettingTo), 64, known);
}
}
\ No newline at end of file
diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java
index a0495ade..a59695c7 100644
--- a/src/main/java/baritone/process/MineProcess.java
+++ b/src/main/java/baritone/process/MineProcess.java
@@ -27,6 +27,7 @@ import baritone.api.utils.RotationUtils;
import baritone.cache.CachedChunk;
import baritone.cache.ChunkPacker;
import baritone.cache.WorldScanner;
+import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface;
@@ -88,7 +89,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
List curr = new ArrayList<>(knownOreLocations);
- Baritone.getExecutor().execute(() -> rescan(curr));
+ CalculationContext context = new CalculationContext(baritone);
+ Baritone.getExecutor().execute(() -> rescan(curr, context));
}
if (Baritone.settings().legitMine.get()) {
addNearby();
@@ -116,7 +118,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
private Goal updateGoal() {
List locs = knownOreLocations;
if (!locs.isEmpty()) {
- List locs2 = prune(ctx, new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT);
+ List locs2 = prune(new CalculationContext(baritone), new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT);
// can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(ctx, loc, locs2)).toArray(Goal[]::new));
knownOreLocations = locs2;
@@ -151,14 +153,14 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return branchPointRunaway;
}
- private void rescan(List already) {
+ private void rescan(List already, CalculationContext context) {
if (mining == null) {
return;
}
if (Baritone.settings().legitMine.get()) {
return;
}
- List locs = searchWorld(ctx, mining, ORE_LOCATIONS_COUNT, already);
+ List locs = searchWorld(context, mining, ORE_LOCATIONS_COUNT, already);
locs.addAll(droppedItemsScan(mining, ctx.world()));
if (locs.isEmpty()) {
logDebug("No locations for " + mining + " known, cancelling");
@@ -205,13 +207,14 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
/*public static List searchWorld(List mining, int max, World world) {
}*/
- public static List searchWorld(IPlayerContext ctx, List mining, int max, List alreadyKnown) {
+ public static List searchWorld(CalculationContext ctx, List mining, int max, List alreadyKnown) {
+ IPlayerContext ipc;
List locs = new ArrayList<>();
List uninteresting = new ArrayList<>();
//long b = System.currentTimeMillis();
for (Block m : mining) {
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) {
- locs.addAll(ctx.worldData().getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 1));
+ locs.addAll(ctx.worldData().getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 1));
} else {
uninteresting.add(m);
}
@@ -222,7 +225,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
if (!uninteresting.isEmpty()) {
//long before = System.currentTimeMillis();
- locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(ctx, uninteresting, max, 10, 26));
+ locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(ctx.getBaritone().getPlayerContext(), uninteresting, max, 10, 26));
//System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms");
}
locs.addAll(alreadyKnown);
@@ -246,22 +249,22 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
}
}
- knownOreLocations = prune(ctx, knownOreLocations, mining, ORE_LOCATIONS_COUNT);
+ knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, mining, ORE_LOCATIONS_COUNT);
}
- public static List prune(IPlayerContext ctx, List locs2, List mining, int max) {
+ public static List prune(CalculationContext ctx, List locs2, List mining, int max) {
List dropped = droppedItemsScan(mining, ctx.world());
List locs = locs2
.stream()
.distinct()
// remove any that are within loaded chunks that aren't actually what we want
- .filter(pos -> ctx.world().getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.getBlock(ctx, pos)) || dropped.contains(pos))
+ .filter(pos -> ctx.world().getChunk(pos) instanceof EmptyChunk || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos))
// remove any that are implausible to mine (encased in bedrock, or touching lava)
- .filter(pos -> MineProcess.plausibleToBreak(ctx, pos))
+ .filter(pos -> MineProcess.plausibleToBreak(ctx.bsi(), pos))
- .sorted(Comparator.comparingDouble(ctx.playerFeet()::distanceSq))
+ .sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().playerFeet()::distanceSq))
.collect(Collectors.toList());
if (locs.size() > max) {
@@ -270,12 +273,13 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return locs;
}
- public static boolean plausibleToBreak(IPlayerContext ctx, BlockPos pos) {
- if (MovementHelper.avoidBreaking(new BlockStateInterface(ctx), pos.getX(), pos.getY(), pos.getZ(), BlockStateInterface.get(ctx, pos))) {
+ public static boolean plausibleToBreak(BlockStateInterface bsi, BlockPos pos) {
+ if (MovementHelper.avoidBreaking(bsi, pos.getX(), pos.getY(), pos.getZ(), bsi.get0(pos))) {
return false;
}
+
// bedrock above and below makes it implausible, otherwise we're good
- return !(BlockStateInterface.getBlock(ctx, pos.up()) == Blocks.BEDROCK && BlockStateInterface.getBlock(ctx, pos.down()) == Blocks.BEDROCK);
+ return !(bsi.get0(pos.up()).getBlock() == Blocks.BEDROCK && bsi.get0(pos.down()).getBlock() == Blocks.BEDROCK);
}
@Override
@@ -290,6 +294,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
this.knownOreLocations = new ArrayList<>();
this.branchPoint = null;
this.branchPointRunaway = null;
- rescan(new ArrayList<>());
+ if (mining != null) {
+ rescan(new ArrayList<>(), new CalculationContext(baritone));
+ }
}
}
diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java
index 63ba8d83..9b6401e9 100644
--- a/src/main/java/baritone/utils/BlockStateInterface.java
+++ b/src/main/java/baritone/utils/BlockStateInterface.java
@@ -21,12 +21,17 @@ import baritone.Baritone;
import baritone.api.utils.IPlayerContext;
import baritone.cache.CachedRegion;
import baritone.cache.WorldData;
+import baritone.utils.accessor.IChunkProviderClient;
+import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
+import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
+import net.minecraft.world.chunk.EmptyChunk;
/**
* Wraps get for chuck caching capability
@@ -36,6 +41,7 @@ import net.minecraft.world.chunk.Chunk;
public class BlockStateInterface {
private final World world;
+ private final Long2ObjectMap loadedChunks;
private final WorldData worldData;
private Chunk prev = null;
@@ -50,6 +56,10 @@ public class BlockStateInterface {
public BlockStateInterface(World world, WorldData worldData) {
this.worldData = worldData;
this.world = world;
+ this.loadedChunks = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks();
+ if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) {
+ throw new IllegalStateException();
+ }
}
public World getWorld() {
@@ -66,6 +76,10 @@ public class BlockStateInterface {
// and toBreak and stuff fails when the movement is instantiated out of load range but it's not able to BlockStateInterface.get what it's going to walk on
}
+ public IBlockState get0(BlockPos pos) {
+ return get0(pos.getX(), pos.getY(), pos.getZ());
+ }
+
public IBlockState get0(int x, int y, int z) { // Mickey resigned
// Invalid vertical position
@@ -84,7 +98,12 @@ public class BlockStateInterface {
if (cached != null && cached.x == x >> 4 && cached.z == z >> 4) {
return cached.getBlockState(x, y, z);
}
+ Chunk c2 = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4));
Chunk chunk = world.getChunk(x >> 4, z >> 4);
+
+ if ((c2 != null && c2 != chunk) || (c2 == null && !(chunk instanceof EmptyChunk))) {
+ throw new IllegalStateException((((IChunkProviderClient) world.getChunkProvider()).loadedChunks() == loadedChunks) + " " + x + " " + y + " " + c2 + " " + chunk);
+ }
if (chunk.isLoaded()) {
prev = chunk;
return chunk.getBlockState(x, y, z);
diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java
index 841349e4..93e2742a 100644
--- a/src/main/java/baritone/utils/ExampleBaritoneControl.java
+++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java
@@ -28,6 +28,7 @@ import baritone.behavior.Behavior;
import baritone.behavior.PathingBehavior;
import baritone.cache.ChunkPacker;
import baritone.cache.Waypoint;
+import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.Moves;
import baritone.process.CustomGoalProcess;
@@ -446,7 +447,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return true;
}
if (msg.equals("costs")) {
- List moves = Stream.of(Moves.values()).map(x -> x.apply0(baritone, ctx.playerFeet())).collect(Collectors.toCollection(ArrayList::new));
+ List moves = Stream.of(Moves.values()).map(x -> x.apply0(new CalculationContext(baritone), ctx.playerFeet())).collect(Collectors.toCollection(ArrayList::new));
while (moves.contains(null)) {
moves.remove(null);
}
diff --git a/src/main/java/baritone/utils/accessor/IChunkProviderClient.java b/src/main/java/baritone/utils/accessor/IChunkProviderClient.java
new file mode 100644
index 00000000..19f14685
--- /dev/null
+++ b/src/main/java/baritone/utils/accessor/IChunkProviderClient.java
@@ -0,0 +1,25 @@
+/*
+ * 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.utils.accessor;
+
+import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
+import net.minecraft.world.chunk.Chunk;
+
+public interface IChunkProviderClient {
+ Long2ObjectMap loadedChunks();
+}