Skip to content

Commit

Permalink
Fix pathfinding command coordinate handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelzangl committed May 9, 2020
1 parent f6d9864 commit 7034733
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public boolean interceptCommand(String message) {
// Show chat message to client. TODO: Use nice minecraft message
AIChatController.addChatLine("ERROR while evaluating: "
+ e.getMessage());
LOGGER.warn("Error during command evaluation", e);
}
}
// Otherwise ignored, let Minecraft handle this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*******************************************************************************/
package net.famzangl.minecraft.minebot.ai.path;

import net.famzangl.minecraft.minebot.ai.AIHelper;
import net.famzangl.minecraft.minebot.ai.command.AICommandParameter.BlockFilter;
import net.famzangl.minecraft.minebot.ai.path.world.BlockSet;
import net.famzangl.minecraft.minebot.ai.path.world.BlockSets;
Expand All @@ -35,7 +34,7 @@

public class FillAreaPathfinder extends MovePathFinder {
private static final Marker MARKER_FILL = MarkerManager.getMarker("fill");
private static final Logger LOGGER = LogManager.getLogger(AIHelper.class);
private static final Logger LOGGER = LogManager.getLogger(FillAreaPathfinder.class);
private static final BlockSet PLACEABLE_BLOCKS = BlockSets.SIMPLE_CUBE;
private static final BlockSet GROUND_BLOCKS = BlockSet.builder().add(BlockSets.SIMPLE_CUBE).add(
BlockSets.FALLING).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
import net.famzangl.minecraft.minebot.ai.utils.BlockArea;
import net.famzangl.minecraft.minebot.ai.utils.BlockCuboid;
import net.minecraft.util.math.BlockPos;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GoToPathfinder extends WalkingPathfinder {
private static final Logger LOGGER = LogManager.getLogger(FillAreaPathfinder.class);

private final BlockPos position;
int HORIZONTAL_SEARCH_MIN = (int) (HORIZONTAL_SEARCH_DISTANCE * .8);
int VERTICAL_SEARCH_MIN = (int) (VERTICAL_SEARCH_DISTANCE * .8);
Expand All @@ -38,7 +42,7 @@ protected boolean runSearch(BlockPos playerPosition) {
}
BlockPos posDiff = position.subtract(playerPosition);
BlockArea<WorldData> area = new BlockCuboid<>(
playerPosition, playerPosition
position, position
);
// X
if (posDiff.getX() > HORIZONTAL_SEARCH_MIN) {
Expand Down Expand Up @@ -85,11 +89,13 @@ protected boolean runSearch(BlockPos playerPosition) {
}
targetArea = area;

LOGGER.debug("Pathfinder target area is: {}", area);

return super.runSearch(playerPosition);
}

@Override
protected float rateDestination(int distance, int x, int y, int z) {
return targetArea.contains(world, position) ? distance : -1;
return targetArea.contains(world, x, y, z) ? distance : -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public boolean contains(WorldT world, int x, int y, int z) {
public <WorldT2 extends WorldT> void accept(AreaVisitor<? super WorldT2> visitor, WorldT2 world) {
a.accept(new FilteredAreaVisitor<WorldT2>(visitor, b), world);
}

@Override
public String toString() {
return a + " ∩ " + b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public <WorldT2 extends WorldT> void accept(AreaVisitor<? super WorldT2> visitor
public boolean contains(WorldT world, int x, int y, int z) {
return a.contains(world, x, y, z) || b.contains(world, x, y, z);
}

@Override
public String toString() {
return a + " ∪ " + b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public BlockCuboid<WorldT> move(Vec3i vec) {

@Override
public String toString() {
return "BlockCuboid [min=" + min + ", max=" + max + "]";
return "BlockCuboid [x=" + min.getX() + ".." + max.getX() + "," +
"y=" + min.getY() + ".." + max.getY() + "," +
"z=" + min.getZ() + ".." + max.getZ() + "]";
}
}

0 comments on commit 7034733

Please sign in to comment.