explore
This commit is contained in:
parent
b3c580e657
commit
74d7483b3c
@ -625,6 +625,13 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final Setting<Integer> followRadius = new Setting<>(3);
|
public final Setting<Integer> followRadius = new Setting<>(3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* true = exploration uses pythagorean distance to choose closest uncached chunk
|
||||||
|
* <p>
|
||||||
|
* false = exploration uses manhattan / taxicab distance to choose
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> exploreUsePythagorean = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached chunks (regardless of if they're in RAM or saved to disk) expire and are deleted after this number of seconds
|
* Cached chunks (regardless of if they're in RAM or saved to disk) expire and are deleted after this number of seconds
|
||||||
* -1 to disable
|
* -1 to disable
|
||||||
|
@ -25,10 +25,7 @@ import baritone.api.utils.IPlayerContext;
|
|||||||
import baritone.behavior.*;
|
import baritone.behavior.*;
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.event.GameEventHandler;
|
import baritone.event.GameEventHandler;
|
||||||
import baritone.process.CustomGoalProcess;
|
import baritone.process.*;
|
||||||
import baritone.process.FollowProcess;
|
|
||||||
import baritone.process.GetToBlockProcess;
|
|
||||||
import baritone.process.MineProcess;
|
|
||||||
import baritone.utils.*;
|
import baritone.utils.*;
|
||||||
import baritone.utils.player.PrimaryPlayerContext;
|
import baritone.utils.player.PrimaryPlayerContext;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@ -80,6 +77,7 @@ public class Baritone implements IBaritone {
|
|||||||
private MineProcess mineProcess;
|
private MineProcess mineProcess;
|
||||||
private GetToBlockProcess getToBlockProcess;
|
private GetToBlockProcess getToBlockProcess;
|
||||||
private CustomGoalProcess customGoalProcess;
|
private CustomGoalProcess customGoalProcess;
|
||||||
|
private ExploreProcess exploreProcess;
|
||||||
|
|
||||||
private PathingControlManager pathingControlManager;
|
private PathingControlManager pathingControlManager;
|
||||||
|
|
||||||
@ -118,6 +116,7 @@ public class Baritone implements IBaritone {
|
|||||||
mineProcess = new MineProcess(this);
|
mineProcess = new MineProcess(this);
|
||||||
customGoalProcess = new CustomGoalProcess(this); // very high iq
|
customGoalProcess = new CustomGoalProcess(this); // very high iq
|
||||||
getToBlockProcess = new GetToBlockProcess(this);
|
getToBlockProcess = new GetToBlockProcess(this);
|
||||||
|
exploreProcess = new ExploreProcess(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.worldProvider = new WorldProvider();
|
this.worldProvider = new WorldProvider();
|
||||||
@ -177,6 +176,10 @@ public class Baritone implements IBaritone {
|
|||||||
return this.lookBehavior;
|
return this.lookBehavior;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExploreProcess getExploreProcess() {
|
||||||
|
return this.exploreProcess;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MineProcess getMineProcess() {
|
public MineProcess getMineProcess() {
|
||||||
return this.mineProcess;
|
return this.mineProcess;
|
||||||
|
@ -107,6 +107,10 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
return region.isCached(blockX & 511, blockZ & 511);
|
return region.isCached(blockX & 511, blockZ & 511);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean regionLoaded(int blockX, int blockZ) {
|
||||||
|
return getRegion(blockX >> 9, blockZ >> 9) != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ArrayList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq) {
|
public final ArrayList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq) {
|
||||||
ArrayList<BlockPos> res = new ArrayList<>();
|
ArrayList<BlockPos> res = new ArrayList<>();
|
||||||
|
100
src/main/java/baritone/process/ExploreProcess.java
Normal file
100
src/main/java/baritone/process/ExploreProcess.java
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.process;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import baritone.api.cache.ICachedWorld;
|
||||||
|
import baritone.api.pathing.goals.GoalXZ;
|
||||||
|
import baritone.api.process.PathingCommand;
|
||||||
|
import baritone.api.process.PathingCommandType;
|
||||||
|
import baritone.cache.CachedWorld;
|
||||||
|
import baritone.utils.BaritoneProcessHelper;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class ExploreProcess extends BaritoneProcessHelper {
|
||||||
|
|
||||||
|
private BlockPos explorationOrigin;
|
||||||
|
|
||||||
|
public ExploreProcess(Baritone baritone) {
|
||||||
|
super(baritone, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
return explorationOrigin != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void explore(int centerX, int centerZ) {
|
||||||
|
explorationOrigin = new BlockPos(centerX, 0, centerZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||||
|
if (calcFailed) {
|
||||||
|
logDirect("Failed");
|
||||||
|
onLostControl();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockPos closestUncached = closestUncachedChunk(explorationOrigin);
|
||||||
|
if (closestUncached == null) {
|
||||||
|
logDebug("awaiting region load from disk");
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
System.out.println("Closest uncached: " + closestUncached);
|
||||||
|
return new PathingCommand(new GoalXZ(closestUncached.getX(), closestUncached.getZ()), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockPos closestUncachedChunk(BlockPos pos) {
|
||||||
|
int chunkX = pos.getX() >> 4;
|
||||||
|
int chunkZ = pos.getZ() >> 4;
|
||||||
|
ICachedWorld cache = baritone.getWorldProvider().getCurrentWorld().getCachedWorld();
|
||||||
|
for (int dist = 0; ; dist++) {
|
||||||
|
for (int dx = -dist; dx <= dist; dx++) {
|
||||||
|
for (int dz = -dist; dz <= dist; dz++) {
|
||||||
|
int trueDist = Baritone.settings().exploreUsePythagorean.value ? dx * dx + dz + dz : Math.abs(dx) + Math.abs(dz);
|
||||||
|
if (trueDist != dist) {
|
||||||
|
continue; // not considering this one just yet in our expanding search
|
||||||
|
}
|
||||||
|
int centerX = (chunkX + dx) * 16 + 8;
|
||||||
|
int centerZ = (chunkZ + dz) * 18 + 8;
|
||||||
|
|
||||||
|
if (cache.isCached(centerX, centerZ)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!((CachedWorld) cache).regionLoaded(centerX, centerZ)) {
|
||||||
|
Baritone.getExecutor().execute(() -> {
|
||||||
|
((CachedWorld) cache).tryLoadFromDisk(centerX >> 9, centerZ >> 9);
|
||||||
|
});
|
||||||
|
return null; // we still need to load regions from disk in order to decide properly
|
||||||
|
}
|
||||||
|
return new BlockPos(centerX, 0, centerZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLostControl() {
|
||||||
|
explorationOrigin = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String displayName() {
|
||||||
|
return "Exploring around " + explorationOrigin + ", currently going to " + closestUncachedChunk(explorationOrigin);
|
||||||
|
}
|
||||||
|
}
|
@ -374,6 +374,21 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("ok");
|
logDirect("ok");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (msg.startsWith("explore")) {
|
||||||
|
String rest = msg.substring("explore".length()).trim();
|
||||||
|
int centerX;
|
||||||
|
int centerZ;
|
||||||
|
try {
|
||||||
|
centerX = Integer.parseInt(rest.split(" ")[0]);
|
||||||
|
centerZ = Integer.parseInt(rest.split(" ")[1]);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
centerX = ctx.playerFeet().x;
|
||||||
|
centerZ = ctx.playerFeet().z;
|
||||||
|
}
|
||||||
|
baritone.getExploreProcess().explore(centerX, centerZ);
|
||||||
|
logDirect("Exploring from " + centerX + "," + centerZ);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (msg.startsWith("find")) {
|
if (msg.startsWith("find")) {
|
||||||
String blockType = msg.substring(4).trim();
|
String blockType = msg.substring(4).trim();
|
||||||
ArrayList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);
|
ArrayList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);
|
||||||
|
Loading…
Reference in New Issue
Block a user