From 2e19023357b7d2751a8b9dd169d6c5dfed3247df Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 1 Aug 2018 21:50:48 -0700 Subject: [PATCH] Clean up some goal constructors --- .../java/baritone/bot/pathing/goals/Goal.java | 5 ---- .../baritone/bot/pathing/goals/GoalBlock.java | 23 ++++++++----------- .../bot/pathing/goals/GoalComposite.java | 12 ++-------- .../bot/pathing/goals/GoalGetToBlock.java | 5 ---- .../bot/pathing/goals/GoalRunAway.java | 5 ---- .../bot/pathing/goals/GoalTwoBlocks.java | 5 ---- .../baritone/bot/pathing/goals/GoalXZ.java | 5 ---- .../bot/pathing/goals/GoalYLevel.java | 5 ---- 8 files changed, 11 insertions(+), 54 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/goals/Goal.java b/src/main/java/baritone/bot/pathing/goals/Goal.java index 8122daa9..2d9063dd 100644 --- a/src/main/java/baritone/bot/pathing/goals/Goal.java +++ b/src/main/java/baritone/bot/pathing/goals/Goal.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package baritone.bot.pathing.goals; import baritone.bot.pathing.actions.ActionCosts; diff --git a/src/main/java/baritone/bot/pathing/goals/GoalBlock.java b/src/main/java/baritone/bot/pathing/goals/GoalBlock.java index f7f19b0c..75564d35 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalBlock.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalBlock.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package baritone.bot.pathing.goals; import net.minecraft.util.math.BlockPos; @@ -13,7 +8,7 @@ import net.minecraft.util.math.BlockPos; */ public class GoalBlock implements Goal { - final int x, y, z; + private final int x, y, z; public GoalBlock(BlockPos pos) { this(pos.getX(), pos.getY(), pos.getZ()); @@ -25,10 +20,6 @@ public class GoalBlock implements Goal { this.z = z; } - public BlockPos pos() { - return new BlockPos(x, y, z); - } - @Override public boolean isInGoal(BlockPos pos) { return pos.getX() == this.x && pos.getY() == this.y && pos.getZ() == this.z; @@ -47,6 +38,11 @@ public class GoalBlock implements Goal { double zDiff = pos.getZ() - this.z; return calculate(xDiff, yDiff, zDiff); } + + @Override + public String toString() { + return "Goal{x=" + x + ",y=" + y + ",z=" + z + "}"; + } public static double calculate(double xDiff, double yDiff, double zDiff) { double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff); @@ -69,9 +65,8 @@ public class GoalBlock implements Goal { heuristic += GoalXZ.calculate(xDiff, zDiff, pythaDist); return heuristic; } - - @Override - public String toString() { - return "Goal{x=" + x + ",y=" + y + ",z=" + z + "}"; + + public BlockPos getGoalPos() { + return new BlockPos(x, y, z); } } diff --git a/src/main/java/baritone/bot/pathing/goals/GoalComposite.java b/src/main/java/baritone/bot/pathing/goals/GoalComposite.java index fa05a61d..1f9d4196 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalComposite.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalComposite.java @@ -24,19 +24,11 @@ public class GoalComposite implements Goal { } public GoalComposite(BlockPos... blocks) { - goals = new Goal[blocks.length]; - for (int i = 0; i < blocks.length; i++) { - goals[i] = new GoalBlock(blocks[i]); - } + this(Arrays.asList(blocks)); } public GoalComposite(Collection blocks) { - goals = new Goal[blocks.size()]; - int i = 0; - for (BlockPos pos : blocks) { - goals[i] = new GoalBlock(pos); - i++; - } + this(blocks.stream().map(GoalBlock::new).toArray(Goal[]::new)); } public Goal[] goals() { diff --git a/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java index 2433932b..a751fdd6 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package baritone.bot.pathing.goals; import net.minecraft.util.EnumFacing; diff --git a/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java b/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java index 4685d1ee..7c9a3bc6 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package baritone.bot.pathing.goals; import java.util.Arrays; diff --git a/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java index 7c7bbcd6..169e2019 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package baritone.bot.pathing.goals; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java index 7a2d36ba..ff52eb91 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package baritone.bot.pathing.goals; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/bot/pathing/goals/GoalYLevel.java b/src/main/java/baritone/bot/pathing/goals/GoalYLevel.java index eff7d8cd..804c620c 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalYLevel.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalYLevel.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package baritone.bot.pathing.goals; import net.minecraft.util.math.BlockPos;