From 342bb8616c66c7e213e3862bf9fa3bf773c1a8e0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 25 Aug 2018 08:44:33 -0700 Subject: [PATCH] fix passable and replacable checks for snow in cached chunks, fixes #87 --- src/main/java/baritone/chunk/ChunkPacker.java | 1 - .../pathing/movement/MovementHelper.java | 39 +++++++++++++++++-- .../movement/movements/MovementAscend.java | 5 +-- .../movement/movements/MovementTraverse.java | 2 +- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index 7cc569a7..845c2d99 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -112,7 +112,6 @@ public final class ChunkPacker implements Helper { if (MovementHelper.avoidWalkingInto(block)) { return PathingBlockType.AVOID; } - // We used to do an AABB check here // however, this failed in the nether when you were near a nether fortress // because fences check their adjacent blocks in the world for their fence connection status to determine AABB shape diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 26a026d0..ed52f8cc 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -33,6 +33,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.world.chunk.EmptyChunk; import java.util.Optional; @@ -75,16 +76,48 @@ public interface MovementHelper extends ActionCosts, Helper { || block instanceof BlockEndPortal) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire return false; } + if (block instanceof BlockDoor) { + if (block == Blocks.IRON_DOOR) { + return false; + } + return true; // we can just open the door + } + if (block instanceof BlockSnow || block instanceof BlockFenceGate || block instanceof BlockTrapDoor) { + // we've already checked doors + // so the only remaining dynamic isPassables are snow, fence gate, and trapdoor + // if they're cached as a top block, we don't know their metadata + // default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible) + if (mc.world.getChunk(pos) instanceof EmptyChunk) { + return true; + } + } IBlockState up = BlockStateInterface.get(pos.up()); if (BlockStateInterface.isFlowing(state) || up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { return false; // Don't walk through flowing liquids } - if (block instanceof BlockDoor && !Blocks.IRON_DOOR.equals(block)) { - return true; // we can just open the door - } return block.isPassable(mc.world, pos); } + static boolean isReplacable(BlockPos pos, IBlockState state) { + // for MovementTraverse and MovementAscend + // block double plant defaults to true when the block doesn't match, so don't need to check that case + // all other overrides just return true or false + // the only case to deal with is snow + /* + * public boolean isReplaceable(IBlockAccess worldIn, BlockPos pos) + * { + * return ((Integer)worldIn.getBlockState(pos).getValue(LAYERS)).intValue() == 1; + * } + */ + if (state.getBlock() instanceof BlockSnow) { + // as before, default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible) + if (mc.world.getChunk(pos) instanceof EmptyChunk) { + return true; + } + } + return state.getBlock().isReplaceable(mc.world, pos); + } + static boolean isDoorPassable(BlockPos doorPos, BlockPos playerPos) { IBlockState door = BlockStateInterface.get(doorPos); if (!(door.getBlock() instanceof BlockDoor)) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index bbaca073..956d7091 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -74,11 +74,10 @@ public class MovementAscend extends Movement { protected double calculateCost(CalculationContext context) { IBlockState toPlace = BlockStateInterface.get(positionsToPlace[0]); if (!MovementHelper.canWalkOn(positionsToPlace[0], toPlace)) { - if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock())) { - // TODO replace this check with isReplacable or similar + if (!context.hasThrowaway()) { return COST_INF; } - if (!context.hasThrowaway()) { + if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionsToPlace[0], toPlace)) { return COST_INF; } for (BlockPos against1 : against) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 51429db4..aac418a6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -107,7 +107,7 @@ public class MovementTraverse extends Movement { return COST_INF; } IBlockState pp0 = BlockStateInterface.get(positionsToPlace[0]); - if (pp0.getBlock().equals(Blocks.AIR) || (!BlockStateInterface.isWater(pp0.getBlock()) && pp0.getBlock().isReplaceable(Minecraft.getMinecraft().world, positionsToPlace[0]))) { + if (pp0.getBlock().equals(Blocks.AIR) || (!BlockStateInterface.isWater(pp0.getBlock()) && MovementHelper.isReplacable(positionsToPlace[0], pp0))) { if (!context.hasThrowaway()) { return COST_INF; }