From 8de7963c74f147aa119a5c3dae234fd77d457588 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 26 Aug 2018 02:17:52 -0500 Subject: [PATCH] Allow opening of fence gates that are blocking movement, fixes #46 --- .../pathing/movement/MovementHelper.java | 31 +++++++++++++++---- .../movement/movements/MovementTraverse.java | 28 ++++++++++++----- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 547043e8..34c65ae6 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -24,6 +24,7 @@ import baritone.pathing.movement.movements.MovementDescend; import baritone.pathing.movement.movements.MovementFall; import baritone.utils.*; import net.minecraft.block.*; +import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; @@ -77,13 +78,13 @@ 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 instanceof BlockDoor || block instanceof BlockFenceGate) { 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) { + if (block instanceof BlockSnow || 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 @@ -127,13 +128,31 @@ public interface MovementHelper extends ActionCosts, Helper { if (!(state.getBlock() instanceof BlockDoor)) return true; - EnumFacing.Axis facing = state.getValue(BlockDoor.FACING).getAxis(); - boolean open = state.getValue(BlockDoor.OPEN); + return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN); + } + + static boolean isGatePassable(BlockPos gatePos, BlockPos playerPos) { + if (playerPos.equals(gatePos)) + return false; + + IBlockState state = BlockStateInterface.get(gatePos); + if (!(state.getBlock() instanceof BlockFenceGate)) + return true; + + return isHorizontalBlockPassable(gatePos, state, playerPos, BlockFenceGate.OPEN); + } + + static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, PropertyBool propertyOpen) { + if (playerPos.equals(blockPos)) + return false; + + EnumFacing.Axis facing = blockState.getValue(BlockHorizontal.FACING).getAxis(); + boolean open = blockState.getValue(propertyOpen); EnumFacing.Axis playerFacing; - if (playerPos.north().equals(doorPos) || playerPos.south().equals(doorPos)) { + if (playerPos.north().equals(blockPos) || playerPos.south().equals(blockPos)) { playerFacing = EnumFacing.Axis.Z; - } else if (playerPos.east().equals(doorPos) || playerPos.west().equals(doorPos)) { + } else if (playerPos.east().equals(blockPos) || playerPos.west().equals(blockPos)) { playerFacing = EnumFacing.Axis.X; } else { return true; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index c784f07b..e92fc527 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -26,10 +26,7 @@ import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; import baritone.utils.Utils; -import net.minecraft.block.Block; -import net.minecraft.block.BlockDoor; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; +import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; @@ -145,17 +142,17 @@ public class MovementTraverse extends Movement { boolean ladder = fd instanceof BlockLadder || fd instanceof BlockVine; IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]); IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]); - boolean door = BlockStateInterface.get(src).getBlock() instanceof BlockDoor || pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor; + + boolean door = pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor; if (door) { boolean isDoorActuallyBlockingUs = false; - Block srcBlock = BlockStateInterface.get(src).getBlock(); - if (srcBlock instanceof BlockDoor && !MovementHelper.isDoorPassable(src, dest)) { + if (pb0.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(src, dest)) { isDoorActuallyBlockingUs = true; } else if (pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(dest, src)) { isDoorActuallyBlockingUs = true; } if (isDoorActuallyBlockingUs) { - if (!(Blocks.IRON_DOOR.equals(srcBlock) || Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) { + if (!(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) { state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(positionsToBreak[0], world())), true)); state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); return state; @@ -163,6 +160,21 @@ public class MovementTraverse extends Movement { } } + if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) { + BlockPos blocked = null; + if (!MovementHelper.isGatePassable(positionsToBreak[0], src.up())) { + blocked = positionsToBreak[0]; + } else if (!MovementHelper.isGatePassable(positionsToBreak[1], src)) { + blocked = positionsToBreak[1]; + } + + if (blocked != null) { + state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(blocked, world())), true)); + state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); + return state; + } + } + boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionsToPlace[0]) || ladder; BlockPos whereAmI = playerFeet(); if (whereAmI.getY() != dest.getY() && !ladder) {