From 5ec99977face3d15257d5c4672a9fd04f01bd923 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 26 Aug 2018 00:09:44 -0500 Subject: [PATCH] Fix water bucket falling, fixes #91 --- .../movement/movements/MovementFall.java | 26 +++++----- .../java/baritone/utils/RayTraceUtils.java | 47 +++++++++++++++++++ 2 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 src/main/java/baritone/utils/RayTraceUtils.java diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 86597f2a..707a997b 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -18,26 +18,20 @@ package baritone.pathing.movement.movements; import baritone.Baritone; -import baritone.behavior.impl.LookBehaviorUtils; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementTarget; -import baritone.utils.BlockStateInterface; -import baritone.utils.InputOverrideHandler; -import baritone.utils.Rotation; -import baritone.utils.Utils; -import net.minecraft.block.Block; +import baritone.utils.*; import net.minecraft.block.BlockFalling; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; -import java.util.Optional; - public class MovementFall extends Movement { private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET); @@ -96,20 +90,26 @@ public class MovementFall extends Movement { } BlockPos playerFeet = playerFeet(); - Optional targetRotation = Optional.empty(); + Rotation targetRotation = null; if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > Baritone.settings().maxFallHeightNoWater.get() && !playerFeet.equals(dest)) { if (!player().inventory.hasItemStack(STACK_BUCKET_WATER) || world().provider.isNether()) { // TODO check if water bucket is on hotbar or main inventory state.setStatus(MovementStatus.UNREACHABLE); return state; } + if (player().posY - dest.getY() < mc.playerController.getBlockReachDistance()) { player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_WATER); - targetRotation = LookBehaviorUtils.reachable((BlockStateInterface.get(dest).getCollisionBoundingBox(mc.world, dest) == Block.NULL_AABB) ? dest : dest.down()); + + targetRotation = new Rotation(player().rotationYaw, 90.0F); + + RayTraceResult trace = RayTraceUtils.simulateRayTrace(player().rotationYaw, 90.0F); + if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK) { + state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); + } } } - if (targetRotation.isPresent()) { - state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true) - .setTarget(new MovementTarget(targetRotation.get(), true)); + if (targetRotation != null) { + state.setTarget(new MovementTarget(targetRotation, true)); } else { state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false)); } diff --git a/src/main/java/baritone/utils/RayTraceUtils.java b/src/main/java/baritone/utils/RayTraceUtils.java new file mode 100644 index 00000000..f6547454 --- /dev/null +++ b/src/main/java/baritone/utils/RayTraceUtils.java @@ -0,0 +1,47 @@ +/* + * 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; + +import net.minecraft.util.math.RayTraceResult; + +/** + * @author Brady + * @since 8/25/2018 + */ +public final class RayTraceUtils implements Helper { + + private RayTraceUtils() {} + + public static RayTraceResult simulateRayTrace(float yaw, float pitch) { + RayTraceResult oldTrace = mc.objectMouseOver; + float oldYaw = mc.player.rotationYaw; + float oldPitch = mc.player.rotationPitch; + + mc.player.rotationYaw = yaw; + mc.player.rotationPitch = pitch; + + mc.entityRenderer.getMouseOver(1.0F); + RayTraceResult result = mc.objectMouseOver; + mc.objectMouseOver = oldTrace; + + mc.player.rotationYaw = oldYaw; + mc.player.rotationPitch = oldPitch; + + return result; + } +}