Simplify fall logic and move methods

This commit is contained in:
Howard Stark 2018-08-07 06:16:38 -07:00
parent 8b63a3adad
commit e30405c0ca
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
2 changed files with 47 additions and 44 deletions

View File

@ -1,6 +1,8 @@
package baritone.bot.pathing.movement;
import baritone.bot.behavior.impl.LookBehaviorUtils;
import baritone.bot.pathing.movement.movements.MovementDescend;
import baritone.bot.pathing.movement.movements.MovementFall;
import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.Helper;
import baritone.bot.utils.ToolSet;
@ -12,6 +14,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
@ -177,6 +180,41 @@ public interface MovementHelper extends ActionCosts, Helper {
return false;
}
static Movement generateMovementFallOrDescend(BlockPos pos, EnumFacing direction) {
BlockPos dest = pos.offset(direction);
BlockPos destUp = dest.up();
BlockPos destDown = dest.down();
for (int i = 0; i < 4; i++) {
if (!(BlockStateInterface.get(destUp.down(i)).getBlock() instanceof BlockAir)) {
//if any of these four aren't air, that means that a fall N isn't possible
//so try a movementdescend
//if all four of them are air, a movementdescend isn't possible anyway
return new MovementDescend(pos, destDown);
}
}
// we're clear for a fall 2
// let's see how far we can fall
for (int fallHeight = 3; true; fallHeight++) {
BlockPos onto = dest.down(fallHeight);
if (onto.getY() <= 0) {
break;
}
IBlockState fallOn = BlockStateInterface.get(onto);
if (fallOn.getBlock() instanceof BlockAir) {
continue;
}
if (BlockStateInterface.isWater(fallOn.getBlock())) {
return new MovementFall(pos, onto);
}
if (MovementHelper.canWalkOn(onto)) {
return new MovementFall(pos, onto);
}
break;
}
return null;
}
static boolean hasthrowaway() {
EntityPlayerSP p = Minecraft.getMinecraft().player;
NonNullList<ItemStack> inv = p.inventory.mainInventory;

View File

@ -40,41 +40,6 @@ public class MovementFall extends Movement {
super(src, dest, MovementFall.buildPositionsToBreak(src, dest), new BlockPos[]{dest.down()});
}
public static Movement generateMovementFallOrDescend(BlockPos pos, EnumFacing direction) {
BlockPos dest = pos.offset(direction);
BlockPos destUp = dest.up();
BlockPos destDown = dest.down();
for (int i = 0; i < 4; i++) {
if (!(BlockStateInterface.get(destUp.down(i)).getBlock() instanceof BlockAir)) {
//if any of these four aren't air, that means that a fall N isn't possible
//so try a movementdescend
//if all four of them are air, a movementdescend isn't possible anyway
return new MovementDescend(pos, destDown);
}
}
// we're clear for a fall 2
// let's see how far we can fall
for (int fallHeight = 3; true; fallHeight++) {
BlockPos onto = dest.down(fallHeight);
if (onto.getY() <= 0) {
break;
}
IBlockState fallOn = BlockStateInterface.get(onto);
if (fallOn.getBlock() instanceof BlockAir) {
continue;
}
if (BlockStateInterface.isWater(fallOn.getBlock())) {
return new MovementFall(pos, onto);
}
if (MovementHelper.canWalkOn(onto)) {
return new MovementFall(pos, onto);
}
break;
}
return null;
}
@Override
protected double calculateCost(ToolSet ts) {
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
@ -104,16 +69,10 @@ public class MovementFall extends Movement {
state.setStatus(MovementStatus.RUNNING);
case RUNNING:
BlockPos playerFeet = playerFeet();
if (src.getY() - dest.getY() > 3 && !BlockStateInterface.isWater(dest) && !player().inventory.hasItemStack(new ItemStack(new ItemBucket(Blocks.WATER)))) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01 || BlockStateInterface.isWater(dest)))
return state.setStatus(MovementStatus.SUCCESS);
Vec3d destCenter = Utils.calcCenterFromCoords(dest, world());
if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) {
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
}
if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3) {
if(!player().inventory.hasItemStack(new ItemStack(new ItemBucket(Blocks.WATER)))) {
state.setStatus(MovementStatus.UNREACHABLE);
}
LookBehaviorUtils.reachable(dest).ifPresent(rotation ->
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true)
.setTarget(new MovementTarget(rotation))
@ -122,6 +81,12 @@ public class MovementFall extends Movement {
Rotation rotationToBlock = Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(dest, world()));
state.setTarget(new MovementTarget(rotationToBlock));
}
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01 || BlockStateInterface.isWater(dest)))
return state.setStatus(MovementStatus.SUCCESS);
Vec3d destCenter = Utils.calcCenterFromCoords(dest, world());
if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) {
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
}
return state;
default:
return state;