From 91c4d8292dea32a653c934f7554f7b5835e7f58e Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 26 Aug 2018 02:53:50 -0500 Subject: [PATCH 1/5] Cleaned up 7 duplicate switch statements --- src/main/java/baritone/pathing/movement/Movement.java | 5 +++++ .../pathing/movement/movements/MovementAscend.java | 10 ++-------- .../pathing/movement/movements/MovementDescend.java | 10 ++-------- .../pathing/movement/movements/MovementDiagonal.java | 10 ++-------- .../pathing/movement/movements/MovementDownward.java | 10 ++-------- .../pathing/movement/movements/MovementFall.java | 10 ++-------- .../pathing/movement/movements/MovementPillar.java | 10 ++-------- .../pathing/movement/movements/MovementTraverse.java | 10 ++-------- 8 files changed, 19 insertions(+), 56 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 27cbb08e..ee9bf27a 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -266,6 +266,11 @@ public abstract class Movement implements Helper, MovementHelper { } else if (state.getStatus() == MovementStatus.PREPPING) { state.setStatus(MovementStatus.WAITING); } + + if (state.getStatus() == MovementStatus.WAITING) { + state.setStatus(MovementStatus.RUNNING); + } + return state; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index f3225337..1dce611c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -122,14 +122,8 @@ public class MovementAscend extends Movement { super.updateState(state); // TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump // for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly) - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementStatus.RUNNING) + return state; if (playerFeet().equals(dest)) { return state.setStatus(MovementStatus.SUCCESS); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 6e299bd1..b9004d9a 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -65,14 +65,8 @@ public class MovementDescend extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementStatus.RUNNING) + return state; BlockPos playerFeet = playerFeet(); if (playerFeet.equals(dest)) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 7bde41c7..8ece8a44 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -52,14 +52,8 @@ public class MovementDiagonal extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementState.MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementState.MovementStatus.RUNNING) + return state; if (playerFeet().equals(dest)) { state.setStatus(MovementState.MovementStatus.SUCCESS); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 724b8688..8262035c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -60,14 +60,8 @@ public class MovementDownward extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementState.MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementState.MovementStatus.RUNNING) + return state; if (playerFeet().equals(dest)) { state.setStatus(MovementState.MovementStatus.SUCCESS); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 5c40c706..6117b418 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -80,14 +80,8 @@ public class MovementFall extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementStatus.RUNNING) + return state; BlockPos playerFeet = playerFeet(); Rotation targetRotation = null; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index dba55466..794eb317 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -107,14 +107,8 @@ public class MovementPillar extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementState.MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementState.MovementStatus.RUNNING) + return state; IBlockState fromDown = BlockStateInterface.get(src); boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index e92fc527..485fc5a7 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -129,14 +129,8 @@ public class MovementTraverse extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementState.MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementState.MovementStatus.RUNNING) + return state; Block fd = BlockStateInterface.get(src.down()).getBlock(); boolean ladder = fd instanceof BlockLadder || fd instanceof BlockVine; From 99323463e3ebfd2cd13c70074ffb59588de3afe8 Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 7 Sep 2018 19:00:36 -0500 Subject: [PATCH 2/5] Fix improper treatment of unbreakable blocks --- .../java/baritone/pathing/movement/MovementHelper.java | 6 +++++- src/main/java/baritone/utils/ToolSet.java | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 6897d5a4..49fc5968 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -259,7 +259,11 @@ public interface MovementHelper extends ActionCosts, Helper { return COST_INF; } double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table - double result = m / context.getToolSet().getStrVsBlock(state); + double strVsBlock = context.getToolSet().getStrVsBlock(state); + if (strVsBlock < 0) + return COST_INF; + + double result = m / strVsBlock; if (includeFalling) { BlockPos up = position.up(); IBlockState above = BlockStateInterface.get(up); diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 8a97980c..e31fe09e 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -77,7 +77,7 @@ public class ToolSet implements Helper { /** * Calculates how long would it take to mine the specified block given the best tool - * in this toolset is used. + * in this toolset is used. A negative value is returned if the specified block is unbreakable. * * @param state the blockstate to be mined * @return how long it would take in ticks @@ -87,9 +87,8 @@ public class ToolSet implements Helper { ItemStack contents = player().inventory.getStackInSlot(slot); float blockHard = state.getBlockHardness(null, null); - if (blockHard < 0) { - return 0; - } + if (blockHard < 0) + return -1; float speed = contents.getDestroySpeed(state); if (speed > 1) { From d17cc96e90d560b6d6d8d3c50f710c9a085e3ca6 Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 7 Sep 2018 19:40:15 -0500 Subject: [PATCH 3/5] Constructor fix --- .../baritone/pathing/movement/movements/MovementDiagonal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 127d277c..1a11295e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -47,7 +47,7 @@ public class MovementDiagonal extends Movement { } public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) { - super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}, new BlockPos[]{end.down()}); + super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}); } @Override From 3261687ee08ecadbe37d1f1fb608501673e252a3 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 18:23:32 -0700 Subject: [PATCH 4/5] render more goals, fixes #25 --- .../baritone/pathing/goals/GoalBlock.java | 3 ++- .../pathing/goals/GoalGetToBlock.java | 3 ++- .../java/baritone/pathing/goals/GoalNear.java | 3 ++- .../baritone/pathing/goals/GoalTwoBlocks.java | 5 ++-- .../java/baritone/utils/PathRenderer.java | 13 ++++++---- .../utils/interfaces/IGoalRenderPos.java | 24 +++++++++++++++++++ 6 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/main/java/baritone/utils/interfaces/IGoalRenderPos.java diff --git a/src/main/java/baritone/pathing/goals/GoalBlock.java b/src/main/java/baritone/pathing/goals/GoalBlock.java index 78d7b87d..9e6ea556 100644 --- a/src/main/java/baritone/pathing/goals/GoalBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalBlock.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; /** @@ -24,7 +25,7 @@ import net.minecraft.util.math.BlockPos; * * @author leijurv */ -public class GoalBlock implements Goal { +public class GoalBlock implements Goal, IGoalRenderPos { /** * The X block position of this goal diff --git a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java index 30937772..4e81018b 100644 --- a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.util.math.BlockPos; @@ -26,7 +27,7 @@ import net.minecraft.util.math.BlockPos; * * @author avecowa */ -public class GoalGetToBlock implements Goal { +public class GoalGetToBlock implements Goal, IGoalRenderPos { private final int x; private final int y; diff --git a/src/main/java/baritone/pathing/goals/GoalNear.java b/src/main/java/baritone/pathing/goals/GoalNear.java index 2ec6bf1d..e78788ac 100644 --- a/src/main/java/baritone/pathing/goals/GoalNear.java +++ b/src/main/java/baritone/pathing/goals/GoalNear.java @@ -17,9 +17,10 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; -public class GoalNear implements Goal { +public class GoalNear implements Goal, IGoalRenderPos { final int x; final int y; final int z; diff --git a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java index 65571a49..021103a1 100644 --- a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; /** @@ -25,7 +26,7 @@ import net.minecraft.util.math.BlockPos; * * @author leijurv */ -public class GoalTwoBlocks implements Goal { +public class GoalTwoBlocks implements Goal, IGoalRenderPos { /** * The X block position of this goal @@ -69,7 +70,7 @@ public class GoalTwoBlocks implements Goal { } public BlockPos getGoalPos() { - return new BlockPos(x, y, z); + return new BlockPos(x, y - 1, z); } @Override diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 6fd3466e..c4ea8103 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -19,9 +19,10 @@ package baritone.utils; import baritone.Baritone; import baritone.pathing.goals.Goal; -import baritone.pathing.goals.GoalBlock; +import baritone.pathing.goals.GoalComposite; import baritone.pathing.goals.GoalXZ; import baritone.pathing.path.IPath; +import baritone.utils.interfaces.IGoalRenderPos; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -183,13 +184,13 @@ public final class PathRenderer implements Helper { double maxY; double y1; double y2; - if (goal instanceof GoalBlock) { - BlockPos goalPos = ((GoalBlock) goal).getGoalPos(); + if (goal instanceof IGoalRenderPos) { + BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos(); minX = goalPos.getX() + 0.002 - renderPosX; maxX = goalPos.getX() + 1 - 0.002 - renderPosX; minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; - double y = MathHelper.sin((float) (((float) (System.nanoTime() / 1000000L) % 2000L) / 2000F * Math.PI * 2)); + double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); y1 = 1 + y + goalPos.getY() - renderPosY; y2 = 1 - y + goalPos.getY() - renderPosY; minY = goalPos.getY() - renderPosY; @@ -207,7 +208,9 @@ public final class PathRenderer implements Helper { minY = 0 - renderPosY; maxY = 256 - renderPosY; } else { - // TODO GoalComposite + for (Goal g : ((GoalComposite) goal).goals()) { + drawLitDankGoalBox(player, g, partialTicks, color); + } return; } diff --git a/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java b/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java new file mode 100644 index 00000000..0aed1ea4 --- /dev/null +++ b/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java @@ -0,0 +1,24 @@ +/* + * 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.utils.interfaces; + +import net.minecraft.util.math.BlockPos; + +public interface IGoalRenderPos { + BlockPos getGoalPos(); +} From 9052781889776458ede26003e951d0c78647d286 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 20:43:12 -0700 Subject: [PATCH 5/5] smaller cuter boxes for goaltwoblocks --- src/main/java/baritone/pathing/goals/GoalTwoBlocks.java | 2 +- src/main/java/baritone/utils/PathRenderer.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java index 021103a1..dcd8d17d 100644 --- a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java @@ -70,7 +70,7 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos { } public BlockPos getGoalPos() { - return new BlockPos(x, y - 1, z); + return new BlockPos(x, y, z); } @Override diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index c4ea8103..8f3cf37b 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -20,6 +20,7 @@ package baritone.utils; import baritone.Baritone; import baritone.pathing.goals.Goal; import baritone.pathing.goals.GoalComposite; +import baritone.pathing.goals.GoalTwoBlocks; import baritone.pathing.goals.GoalXZ; import baritone.pathing.path.IPath; import baritone.utils.interfaces.IGoalRenderPos; @@ -191,10 +192,18 @@ public final class PathRenderer implements Helper { minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); + if (goal instanceof GoalTwoBlocks) { + y /= 2; + } y1 = 1 + y + goalPos.getY() - renderPosY; y2 = 1 - y + goalPos.getY() - renderPosY; minY = goalPos.getY() - renderPosY; maxY = minY + 2; + if (goal instanceof GoalTwoBlocks) { + y1 -= 0.5; + y2 -= 0.5; + maxY--; + } } else if (goal instanceof GoalXZ) { GoalXZ goalPos = (GoalXZ) goal;