From f881ba5e592ec07329a6f88c5a621dbcb8b57625 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 13 Aug 2018 17:15:59 -0700 Subject: [PATCH 1/4] first attempt at settings --- src/main/java/baritone/bot/Baritone.java | 9 +++++ src/main/java/baritone/bot/Settings.java | 36 +++++++++++++++++++ .../bot/behavior/impl/PathingBehavior.java | 2 +- .../baritone/bot/pathing/goals/GoalXZ.java | 3 +- .../pathing/movement/CalculationContext.java | 5 +-- .../bot/pathing/movement/MovementHelper.java | 4 +++ 6 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/main/java/baritone/bot/Settings.java diff --git a/src/main/java/baritone/bot/Baritone.java b/src/main/java/baritone/bot/Baritone.java index 1f89291d..a6ba7d50 100755 --- a/src/main/java/baritone/bot/Baritone.java +++ b/src/main/java/baritone/bot/Baritone.java @@ -44,6 +44,7 @@ public enum Baritone { private GameEventHandler gameEventHandler; private InputOverrideHandler inputOverrideHandler; + private Settings settings; private List behaviors; /** @@ -82,4 +83,12 @@ public enum Baritone { public final boolean isActive() { return this.active; } + + public final Settings getSettings() { + return this.settings; + } + + public static Settings settings() { + return Baritone.INSTANCE.settings; // yolo + } } diff --git a/src/main/java/baritone/bot/Settings.java b/src/main/java/baritone/bot/Settings.java new file mode 100644 index 00000000..d9fe7db1 --- /dev/null +++ b/src/main/java/baritone/bot/Settings.java @@ -0,0 +1,36 @@ +/* + * 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 . + */ + +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; + + Settings() { + + } +} diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index a2917880..2ffb36d2 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -125,7 +125,7 @@ public class PathingBehavior extends Behavior { // and this path dosen't get us all the way there 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 displayChatMessageRaw("Path almost over. Planning ahead..."); findPathInNewThread(current.getPath().getDest(), false); diff --git a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java index c1756e1b..acc8592c 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java @@ -17,6 +17,7 @@ package baritone.bot.pathing.goals; +import baritone.bot.Baritone; import baritone.bot.utils.Utils; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -98,7 +99,7 @@ public class GoalXZ implements Goal { diagonal = z; } 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) { diff --git a/src/main/java/baritone/bot/pathing/movement/CalculationContext.java b/src/main/java/baritone/bot/pathing/movement/CalculationContext.java index 52fa03b2..6c171475 100644 --- a/src/main/java/baritone/bot/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/bot/pathing/movement/CalculationContext.java @@ -17,6 +17,7 @@ package baritone.bot.pathing.movement; +import baritone.bot.Baritone; import baritone.bot.utils.Helper; import baritone.bot.utils.ToolSet; import net.minecraft.entity.player.InventoryPlayer; @@ -41,8 +42,8 @@ public class CalculationContext implements Helper { public CalculationContext(ToolSet toolSet) { this.toolSet = toolSet; - this.hasWaterBucket = InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_WATER)) && !world().provider.isNether(); - this.hasThrowaway = MovementHelper.throwaway(false); + this.hasWaterBucket = Baritone.settings().allowWaterBucketFall && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_WATER)) && !world().provider.isNether(); + this.hasThrowaway = Baritone.settings().allowPlaceThrowaway && MovementHelper.throwaway(false); } public ToolSet getToolSet() { diff --git a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java index f96eb64b..045e0d9c 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java @@ -17,6 +17,7 @@ package baritone.bot.pathing.movement; +import baritone.bot.Baritone; import baritone.bot.InputOverrideHandler; import baritone.bot.behavior.impl.LookBehaviorUtils; import baritone.bot.pathing.movement.MovementState.MovementTarget; @@ -140,6 +141,9 @@ public interface MovementHelper extends ActionCosts, Helper { if (avoidBreaking(position)) { return COST_INF; } + if (!Baritone.settings().allowBreak) { + return COST_INF; + } //if (!Baritone.allowBreakOrPlace) { // return COST_INF; //} From 04005b6e596a9ff08b477f85a3dca2a73118ec76 Mon Sep 17 00:00:00 2001 From: leijurv Date: Mon, 13 Aug 2018 20:17:16 -0700 Subject: [PATCH 2/4] more settings --- src/main/java/baritone/bot/Settings.java | 2 ++ .../bot/behavior/impl/PathingBehavior.java | 6 ++++- .../baritone/bot/event/GameEventHandler.java | 22 ++++++++++--------- .../bot/pathing/calc/AStarPathFinder.java | 15 ++++++++----- .../bot/utils/BlockStateInterface.java | 4 +++- src/main/java/baritone/bot/utils/Helper.java | 6 +++++ 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/main/java/baritone/bot/Settings.java b/src/main/java/baritone/bot/Settings.java index d9fe7db1..48ad9679 100644 --- a/src/main/java/baritone/bot/Settings.java +++ b/src/main/java/baritone/bot/Settings.java @@ -29,6 +29,8 @@ public class Settings { public boolean chuckCaching = false; public boolean allowWaterBucketFall = true; public int planningTickLookAhead = 150; + public boolean renderPath = true; + public boolean chatDebug = true; Settings() { diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index 2ffb36d2..074d2b04 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -42,7 +42,8 @@ public class PathingBehavior extends Behavior { public static final PathingBehavior INSTANCE = new PathingBehavior(); - private PathingBehavior() {} + private PathingBehavior() { + } private PathExecutor current; private PathExecutor next; @@ -274,6 +275,9 @@ public class PathingBehavior extends Behavior { @Override public void onRenderPass(RenderEvent event) { + if (!Baritone.settings().renderPath) { + return; + } // System.out.println("Render passing"); // System.out.println(event.getPartialTicks()); float partialTicks = event.getPartialTicks(); diff --git a/src/main/java/baritone/bot/event/GameEventHandler.java b/src/main/java/baritone/bot/event/GameEventHandler.java index 7c9f03a1..a6fd77d1 100644 --- a/src/main/java/baritone/bot/event/GameEventHandler.java +++ b/src/main/java/baritone/bot/event/GameEventHandler.java @@ -130,17 +130,19 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public void onWorldEvent(WorldEvent event) { - CachedWorldProvider cache = CachedWorldProvider.INSTANCE; + if (Baritone.settings().chuckCaching) { + CachedWorldProvider cache = CachedWorldProvider.INSTANCE; - switch (event.getState()) { - case PRE: - cache.ifWorldLoaded(CachedWorld::save); - break; - case POST: - cache.closeWorld(); - if (event.getWorld() != null) - cache.initWorld(event.getWorld()); - break; + switch (event.getState()) { + case PRE: + cache.ifWorldLoaded(CachedWorld::save); + break; + case POST: + cache.closeWorld(); + if (event.getWorld() != null) + cache.initWorld(event.getWorld()); + break; + } } dispatch(behavior -> behavior.onWorldEvent(event)); diff --git a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java index 242911f9..3de70552 100644 --- a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java @@ -34,6 +34,7 @@ package baritone.bot.pathing.calc; +import baritone.bot.Baritone; import baritone.bot.chunk.CachedWorldProvider; import baritone.bot.pathing.calc.openset.BinaryHeapOpenSet; import baritone.bot.pathing.calc.openset.IOpenSet; @@ -86,6 +87,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { int numNodes = 0; CalculationContext calcContext = new CalculationContext(); int numEmptyChunk = 0; + boolean cache = Baritone.settings().chuckCaching; while (!openSet.isEmpty() && numEmptyChunk < 50 && System.currentTimeMillis() < timeoutTime) { if (slowPath) { try { @@ -117,11 +119,14 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } boolean isPositionCached = false; - if (CachedWorldProvider.INSTANCE.getCurrentWorld() != null) - if (CachedWorldProvider.INSTANCE.getCurrentWorld().getBlockType(movementToGetToNeighbor.getDest()) != null) - isPositionCached = true; - - if (Minecraft.getMinecraft().world.getChunk(movementToGetToNeighbor.getDest()) instanceof EmptyChunk && !isPositionCached) { + if (cache) { + if (CachedWorldProvider.INSTANCE.getCurrentWorld() != null) { + if (CachedWorldProvider.INSTANCE.getCurrentWorld().getBlockType(movementToGetToNeighbor.getDest()) != null) { + isPositionCached = true; + } + } + } + if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(movementToGetToNeighbor.getDest()) instanceof EmptyChunk) { numEmptyChunk++; continue; } diff --git a/src/main/java/baritone/bot/utils/BlockStateInterface.java b/src/main/java/baritone/bot/utils/BlockStateInterface.java index 23aa88e3..7ab42c1d 100644 --- a/src/main/java/baritone/bot/utils/BlockStateInterface.java +++ b/src/main/java/baritone/bot/utils/BlockStateInterface.java @@ -17,6 +17,7 @@ package baritone.bot.utils; +import baritone.bot.Baritone; import baritone.bot.chunk.CachedWorld; import baritone.bot.chunk.CachedWorldProvider; import baritone.bot.utils.pathing.PathingBlockType; @@ -39,7 +40,8 @@ public class BlockStateInterface implements Helper { Chunk chunk = mc.world.getChunk(pos); if (chunk.isLoaded()) { return chunk.getBlockState(pos); - } else { + } + if(Baritone.settings().chuckCaching) { CachedWorld world = CachedWorldProvider.INSTANCE.getCurrentWorld(); if (world != null) { PathingBlockType type = world.getBlockType(pos); diff --git a/src/main/java/baritone/bot/utils/Helper.java b/src/main/java/baritone/bot/utils/Helper.java index 0bc696f4..ffa3094d 100755 --- a/src/main/java/baritone/bot/utils/Helper.java +++ b/src/main/java/baritone/bot/utils/Helper.java @@ -17,6 +17,7 @@ package baritone.bot.utils; +import baritone.bot.Baritone; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiNewChat; @@ -69,6 +70,11 @@ public interface Helper { } 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(); int normalMaxWidth = MathHelper.floor((float) gui.getChatWidth() / gui.getChatScale()); int widthWithStyleFormat = normalMaxWidth - 2; From ebee78b0352455d21a2df06ea3988ef7d9656911 Mon Sep 17 00:00:00 2001 From: leijurv Date: Mon, 13 Aug 2018 20:18:12 -0700 Subject: [PATCH 3/4] optim --- .../java/baritone/bot/pathing/movement/MovementHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java index 045e0d9c..78b3a4b5 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java @@ -138,10 +138,10 @@ public interface MovementHelper extends ActionCosts, Helper { IBlockState state = BlockStateInterface.get(position); Block block = state.getBlock(); if (!block.equals(Blocks.AIR) && !canWalkThrough(position)) { - if (avoidBreaking(position)) { + if (!Baritone.settings().allowBreak) { return COST_INF; } - if (!Baritone.settings().allowBreak) { + if (avoidBreaking(position)) { return COST_INF; } //if (!Baritone.allowBreakOrPlace) { From e4d6d6ff641d8fa83f71d8e07d7b3fc92fee846d Mon Sep 17 00:00:00 2001 From: leijurv Date: Mon, 13 Aug 2018 20:19:27 -0700 Subject: [PATCH 4/4] missed a spot --- src/main/java/baritone/bot/event/GameEventHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/bot/event/GameEventHandler.java b/src/main/java/baritone/bot/event/GameEventHandler.java index a6fd77d1..ea151c2e 100644 --- a/src/main/java/baritone/bot/event/GameEventHandler.java +++ b/src/main/java/baritone/bot/event/GameEventHandler.java @@ -108,10 +108,12 @@ public final class GameEventHandler implements IGameEventListener, Helper { && type == ChunkEvent.Type.UNLOAD && mc.world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ()); - if (isPostPopulate || isPreUnload) { - CachedWorldProvider.INSTANCE.ifWorldLoaded(world -> - world.updateCachedChunk(event.getX(), event.getZ(), - ChunkPacker.createPackedChunk(mc.world.getChunk(event.getX(), event.getZ())))); + if (Baritone.settings().chuckCaching) { + if (isPostPopulate || isPreUnload) { + CachedWorldProvider.INSTANCE.ifWorldLoaded(world -> + world.updateCachedChunk(event.getX(), event.getZ(), + ChunkPacker.createPackedChunk(mc.world.getChunk(event.getX(), event.getZ())))); + } } dispatch(behavior -> behavior.onChunkEvent(event));