Merge branch 'leijurv-settings'

This commit is contained in:
leijurv 2018-08-13 20:20:54 -07:00
commit d399857309
10 changed files with 99 additions and 25 deletions

View File

@ -44,6 +44,7 @@ public enum Baritone {
private GameEventHandler gameEventHandler; private GameEventHandler gameEventHandler;
private InputOverrideHandler inputOverrideHandler; private InputOverrideHandler inputOverrideHandler;
private Settings settings;
private List<Behavior> behaviors; private List<Behavior> behaviors;
/** /**
@ -82,4 +83,12 @@ public enum Baritone {
public final boolean isActive() { public final boolean isActive() {
return this.active; return this.active;
} }
public final Settings getSettings() {
return this.settings;
}
public static Settings settings() {
return Baritone.INSTANCE.settings; // yolo
}
} }

View File

@ -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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.bot;
/**
* Baritone's settings
*
* @author leijurv
*/
public class Settings {
public boolean allowBreak = true;
public boolean allowPlaceThrowaway = true;
public double costHeuristic = 4;
public boolean chuckCaching = false;
public boolean allowWaterBucketFall = true;
public int planningTickLookAhead = 150;
public boolean renderPath = true;
public boolean chatDebug = true;
Settings() {
}
}

View File

@ -42,7 +42,8 @@ public class PathingBehavior extends Behavior {
public static final PathingBehavior INSTANCE = new PathingBehavior(); public static final PathingBehavior INSTANCE = new PathingBehavior();
private PathingBehavior() {} private PathingBehavior() {
}
private PathExecutor current; private PathExecutor current;
private PathExecutor next; private PathExecutor next;
@ -125,7 +126,7 @@ public class PathingBehavior extends Behavior {
// and this path dosen't get us all the way there // and this path dosen't get us all the way there
return; return;
} }
if (current.getPath().ticksRemainingFrom(current.getPosition()) < 150) { if (current.getPath().ticksRemainingFrom(current.getPosition()) < Baritone.settings().planningTickLookAhead) {
// and this path has 5 seconds or less left // and this path has 5 seconds or less left
displayChatMessageRaw("Path almost over. Planning ahead..."); displayChatMessageRaw("Path almost over. Planning ahead...");
findPathInNewThread(current.getPath().getDest(), false); findPathInNewThread(current.getPath().getDest(), false);
@ -274,6 +275,9 @@ public class PathingBehavior extends Behavior {
@Override @Override
public void onRenderPass(RenderEvent event) { public void onRenderPass(RenderEvent event) {
if (!Baritone.settings().renderPath) {
return;
}
// System.out.println("Render passing"); // System.out.println("Render passing");
// System.out.println(event.getPartialTicks()); // System.out.println(event.getPartialTicks());
float partialTicks = event.getPartialTicks(); float partialTicks = event.getPartialTicks();

View File

@ -108,10 +108,12 @@ public final class GameEventHandler implements IGameEventListener, Helper {
&& type == ChunkEvent.Type.UNLOAD && type == ChunkEvent.Type.UNLOAD
&& mc.world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ()); && mc.world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ());
if (isPostPopulate || isPreUnload) { if (Baritone.settings().chuckCaching) {
CachedWorldProvider.INSTANCE.ifWorldLoaded(world -> if (isPostPopulate || isPreUnload) {
world.updateCachedChunk(event.getX(), event.getZ(), CachedWorldProvider.INSTANCE.ifWorldLoaded(world ->
ChunkPacker.createPackedChunk(mc.world.getChunk(event.getX(), event.getZ())))); world.updateCachedChunk(event.getX(), event.getZ(),
ChunkPacker.createPackedChunk(mc.world.getChunk(event.getX(), event.getZ()))));
}
} }
dispatch(behavior -> behavior.onChunkEvent(event)); dispatch(behavior -> behavior.onChunkEvent(event));
@ -130,17 +132,19 @@ public final class GameEventHandler implements IGameEventListener, Helper {
@Override @Override
public void onWorldEvent(WorldEvent event) { public void onWorldEvent(WorldEvent event) {
CachedWorldProvider cache = CachedWorldProvider.INSTANCE; if (Baritone.settings().chuckCaching) {
CachedWorldProvider cache = CachedWorldProvider.INSTANCE;
switch (event.getState()) { switch (event.getState()) {
case PRE: case PRE:
cache.ifWorldLoaded(CachedWorld::save); cache.ifWorldLoaded(CachedWorld::save);
break; break;
case POST: case POST:
cache.closeWorld(); cache.closeWorld();
if (event.getWorld() != null) if (event.getWorld() != null)
cache.initWorld(event.getWorld()); cache.initWorld(event.getWorld());
break; break;
}
} }
dispatch(behavior -> behavior.onWorldEvent(event)); dispatch(behavior -> behavior.onWorldEvent(event));

View File

@ -34,6 +34,7 @@
package baritone.bot.pathing.calc; package baritone.bot.pathing.calc;
import baritone.bot.Baritone;
import baritone.bot.chunk.CachedWorldProvider; import baritone.bot.chunk.CachedWorldProvider;
import baritone.bot.pathing.calc.openset.BinaryHeapOpenSet; import baritone.bot.pathing.calc.openset.BinaryHeapOpenSet;
import baritone.bot.pathing.calc.openset.IOpenSet; import baritone.bot.pathing.calc.openset.IOpenSet;
@ -86,6 +87,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
int numNodes = 0; int numNodes = 0;
CalculationContext calcContext = new CalculationContext(); CalculationContext calcContext = new CalculationContext();
int numEmptyChunk = 0; int numEmptyChunk = 0;
boolean cache = Baritone.settings().chuckCaching;
while (!openSet.isEmpty() && numEmptyChunk < 50 && System.currentTimeMillis() < timeoutTime) { while (!openSet.isEmpty() && numEmptyChunk < 50 && System.currentTimeMillis() < timeoutTime) {
if (slowPath) { if (slowPath) {
try { try {
@ -117,11 +119,14 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
} }
boolean isPositionCached = false; boolean isPositionCached = false;
if (CachedWorldProvider.INSTANCE.getCurrentWorld() != null) if (cache) {
if (CachedWorldProvider.INSTANCE.getCurrentWorld().getBlockType(movementToGetToNeighbor.getDest()) != null) if (CachedWorldProvider.INSTANCE.getCurrentWorld() != null) {
isPositionCached = true; if (CachedWorldProvider.INSTANCE.getCurrentWorld().getBlockType(movementToGetToNeighbor.getDest()) != null) {
isPositionCached = true;
if (Minecraft.getMinecraft().world.getChunk(movementToGetToNeighbor.getDest()) instanceof EmptyChunk && !isPositionCached) { }
}
}
if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(movementToGetToNeighbor.getDest()) instanceof EmptyChunk) {
numEmptyChunk++; numEmptyChunk++;
continue; continue;
} }

View File

@ -17,6 +17,7 @@
package baritone.bot.pathing.goals; package baritone.bot.pathing.goals;
import baritone.bot.Baritone;
import baritone.bot.utils.Utils; import baritone.bot.utils.Utils;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -98,7 +99,7 @@ public class GoalXZ implements Goal {
diagonal = z; diagonal = z;
} }
diagonal *= SQRT_2; diagonal *= SQRT_2;
return (diagonal + straight) * 4; // big TODO tune return (diagonal + straight) * Baritone.settings().costHeuristic; // big TODO tune
} }
public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) { public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) {

View File

@ -17,6 +17,7 @@
package baritone.bot.pathing.movement; package baritone.bot.pathing.movement;
import baritone.bot.Baritone;
import baritone.bot.utils.Helper; import baritone.bot.utils.Helper;
import baritone.bot.utils.ToolSet; import baritone.bot.utils.ToolSet;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
@ -41,8 +42,8 @@ public class CalculationContext implements Helper {
public CalculationContext(ToolSet toolSet) { public CalculationContext(ToolSet toolSet) {
this.toolSet = toolSet; this.toolSet = toolSet;
this.hasWaterBucket = InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_WATER)) && !world().provider.isNether(); this.hasWaterBucket = Baritone.settings().allowWaterBucketFall && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_WATER)) && !world().provider.isNether();
this.hasThrowaway = MovementHelper.throwaway(false); this.hasThrowaway = Baritone.settings().allowPlaceThrowaway && MovementHelper.throwaway(false);
} }
public ToolSet getToolSet() { public ToolSet getToolSet() {

View File

@ -17,6 +17,7 @@
package baritone.bot.pathing.movement; package baritone.bot.pathing.movement;
import baritone.bot.Baritone;
import baritone.bot.InputOverrideHandler; import baritone.bot.InputOverrideHandler;
import baritone.bot.behavior.impl.LookBehaviorUtils; import baritone.bot.behavior.impl.LookBehaviorUtils;
import baritone.bot.pathing.movement.MovementState.MovementTarget; import baritone.bot.pathing.movement.MovementState.MovementTarget;
@ -137,6 +138,9 @@ public interface MovementHelper extends ActionCosts, Helper {
IBlockState state = BlockStateInterface.get(position); IBlockState state = BlockStateInterface.get(position);
Block block = state.getBlock(); Block block = state.getBlock();
if (!block.equals(Blocks.AIR) && !canWalkThrough(position)) { if (!block.equals(Blocks.AIR) && !canWalkThrough(position)) {
if (!Baritone.settings().allowBreak) {
return COST_INF;
}
if (avoidBreaking(position)) { if (avoidBreaking(position)) {
return COST_INF; return COST_INF;
} }

View File

@ -17,6 +17,7 @@
package baritone.bot.utils; package baritone.bot.utils;
import baritone.bot.Baritone;
import baritone.bot.chunk.CachedWorld; import baritone.bot.chunk.CachedWorld;
import baritone.bot.chunk.CachedWorldProvider; import baritone.bot.chunk.CachedWorldProvider;
import baritone.bot.utils.pathing.PathingBlockType; import baritone.bot.utils.pathing.PathingBlockType;
@ -39,7 +40,8 @@ public class BlockStateInterface implements Helper {
Chunk chunk = mc.world.getChunk(pos); Chunk chunk = mc.world.getChunk(pos);
if (chunk.isLoaded()) { if (chunk.isLoaded()) {
return chunk.getBlockState(pos); return chunk.getBlockState(pos);
} else { }
if(Baritone.settings().chuckCaching) {
CachedWorld world = CachedWorldProvider.INSTANCE.getCurrentWorld(); CachedWorld world = CachedWorldProvider.INSTANCE.getCurrentWorld();
if (world != null) { if (world != null) {
PathingBlockType type = world.getBlockType(pos); PathingBlockType type = world.getBlockType(pos);

View File

@ -17,6 +17,7 @@
package baritone.bot.utils; package baritone.bot.utils;
import baritone.bot.Baritone;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiNewChat; import net.minecraft.client.gui.GuiNewChat;
@ -69,6 +70,11 @@ public interface Helper {
} }
default void displayChatMessageRaw(String message) { default void displayChatMessageRaw(String message) {
if (!Baritone.settings().chatDebug) {
System.out.println("Suppressed debug message:");
System.out.println(message);
return;
}
GuiNewChat gui = mc.ingameGUI.getChatGUI(); GuiNewChat gui = mc.ingameGUI.getChatGUI();
int normalMaxWidth = MathHelper.floor((float) gui.getChatWidth() / gui.getChatScale()); int normalMaxWidth = MathHelper.floor((float) gui.getChatWidth() / gui.getChatScale());
int widthWithStyleFormat = normalMaxWidth - 2; int widthWithStyleFormat = normalMaxWidth - 2;