This commit is contained in:
Leijurv 2019-03-05 12:26:52 -08:00
parent b3c580e657
commit 74d7483b3c
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 133 additions and 4 deletions

View File

@ -625,6 +625,13 @@ public final class Settings {
*/
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
* -1 to disable

View File

@ -25,10 +25,7 @@ import baritone.api.utils.IPlayerContext;
import baritone.behavior.*;
import baritone.cache.WorldProvider;
import baritone.event.GameEventHandler;
import baritone.process.CustomGoalProcess;
import baritone.process.FollowProcess;
import baritone.process.GetToBlockProcess;
import baritone.process.MineProcess;
import baritone.process.*;
import baritone.utils.*;
import baritone.utils.player.PrimaryPlayerContext;
import net.minecraft.client.Minecraft;
@ -80,6 +77,7 @@ public class Baritone implements IBaritone {
private MineProcess mineProcess;
private GetToBlockProcess getToBlockProcess;
private CustomGoalProcess customGoalProcess;
private ExploreProcess exploreProcess;
private PathingControlManager pathingControlManager;
@ -118,6 +116,7 @@ public class Baritone implements IBaritone {
mineProcess = new MineProcess(this);
customGoalProcess = new CustomGoalProcess(this); // very high iq
getToBlockProcess = new GetToBlockProcess(this);
exploreProcess = new ExploreProcess(this);
}
this.worldProvider = new WorldProvider();
@ -177,6 +176,10 @@ public class Baritone implements IBaritone {
return this.lookBehavior;
}
public ExploreProcess getExploreProcess() {
return this.exploreProcess;
}
@Override
public MineProcess getMineProcess() {
return this.mineProcess;

View File

@ -107,6 +107,10 @@ public final class CachedWorld implements ICachedWorld, Helper {
return region.isCached(blockX & 511, blockZ & 511);
}
public final boolean regionLoaded(int blockX, int blockZ) {
return getRegion(blockX >> 9, blockZ >> 9) != null;
}
@Override
public final ArrayList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq) {
ArrayList<BlockPos> res = new ArrayList<>();

View 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);
}
}

View File

@ -374,6 +374,21 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
logDirect("ok");
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")) {
String blockType = msg.substring(4).trim();
ArrayList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);