remove intermediate object
This commit is contained in:
parent
df88b02ed5
commit
ba7e9a56e3
@ -18,7 +18,6 @@
|
|||||||
package baritone.pathing.movement;
|
package baritone.pathing.movement;
|
||||||
|
|
||||||
import baritone.pathing.movement.movements.*;
|
import baritone.pathing.movement.movements.*;
|
||||||
import baritone.pathing.movement.movements.result.DescendResult;
|
|
||||||
import baritone.pathing.movement.movements.result.MoveResult;
|
import baritone.pathing.movement.movements.result.MoveResult;
|
||||||
import baritone.pathing.movement.movements.result.ParkourResult;
|
import baritone.pathing.movement.movements.result.ParkourResult;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
@ -163,8 +162,7 @@ public enum Moves {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MoveResult apply(CalculationContext context, int x, int y, int z) {
|
public MoveResult apply(CalculationContext context, int x, int y, int z) {
|
||||||
DescendResult res = MovementDescend.cost(context, x, y, z, x + 1, z);
|
return MovementDescend.cost(context, x, y, z, x + 1, z);
|
||||||
return new MoveResult(x + 1, res.y, z, res.cost);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -181,8 +179,7 @@ public enum Moves {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MoveResult apply(CalculationContext context, int x, int y, int z) {
|
public MoveResult apply(CalculationContext context, int x, int y, int z) {
|
||||||
DescendResult res = MovementDescend.cost(context, x, y, z, x - 1, z);
|
return MovementDescend.cost(context, x, y, z, x - 1, z);
|
||||||
return new MoveResult(x - 1, res.y, z, res.cost);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -199,8 +196,7 @@ public enum Moves {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MoveResult apply(CalculationContext context, int x, int y, int z) {
|
public MoveResult apply(CalculationContext context, int x, int y, int z) {
|
||||||
DescendResult res = MovementDescend.cost(context, x, y, z, x, z - 1);
|
return MovementDescend.cost(context, x, y, z, x, z - 1);
|
||||||
return new MoveResult(x, res.y, z - 1, res.cost);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -217,8 +213,7 @@ public enum Moves {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MoveResult apply(CalculationContext context, int x, int y, int z) {
|
public MoveResult apply(CalculationContext context, int x, int y, int z) {
|
||||||
DescendResult res = MovementDescend.cost(context, x, y, z, x, z + 1);
|
return MovementDescend.cost(context, x, y, z, x, z + 1);
|
||||||
return new MoveResult(x, res.y, z + 1, res.cost);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import baritone.pathing.movement.Movement;
|
|||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||||
import baritone.pathing.movement.movements.result.DescendResult;
|
import baritone.pathing.movement.movements.result.MoveResult;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
@ -33,7 +33,7 @@ import net.minecraft.block.state.IBlockState;
|
|||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import static baritone.pathing.movement.movements.result.DescendResult.IMPOSSIBLE;
|
import static baritone.pathing.movement.movements.result.MoveResult.IMPOSSIBLE;
|
||||||
|
|
||||||
public class MovementDescend extends Movement {
|
public class MovementDescend extends Movement {
|
||||||
|
|
||||||
@ -51,14 +51,14 @@ public class MovementDescend extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(CalculationContext context) {
|
protected double calculateCost(CalculationContext context) {
|
||||||
DescendResult result = cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
MoveResult result = cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
||||||
if (result.y != dest.y) {
|
if (result.destY != dest.y) {
|
||||||
return COST_INF; // doesn't apply to us, this position is a fall not a descend
|
return COST_INF; // doesn't apply to us, this position is a fall not a descend
|
||||||
}
|
}
|
||||||
return result.cost;
|
return result.cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DescendResult cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
|
public static MoveResult cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
|
||||||
Block fromDown = BlockStateInterface.get(x, y - 1, z).getBlock();
|
Block fromDown = BlockStateInterface.get(x, y - 1, z).getBlock();
|
||||||
if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) {
|
if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) {
|
||||||
return IMPOSSIBLE;
|
return IMPOSSIBLE;
|
||||||
@ -105,10 +105,10 @@ public class MovementDescend extends Movement {
|
|||||||
walk = WALK_ONE_OVER_SOUL_SAND_COST;
|
walk = WALK_ONE_OVER_SOUL_SAND_COST;
|
||||||
}
|
}
|
||||||
totalCost += walk + Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST);
|
totalCost += walk + Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST);
|
||||||
return new DescendResult(y - 1, totalCost);
|
return new MoveResult(destX, y - 1, destZ, totalCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DescendResult dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, IBlockState below) {
|
public static MoveResult dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, IBlockState below) {
|
||||||
if (frontBreak != 0 && BlockStateInterface.get(destX, y + 2, destZ).getBlock() instanceof BlockFalling) {
|
if (frontBreak != 0 && BlockStateInterface.get(destX, y + 2, destZ).getBlock() instanceof BlockFalling) {
|
||||||
// if frontBreak is 0 we can actually get through this without updating the falling block and making it actually fall
|
// if frontBreak is 0 we can actually get through this without updating the falling block and making it actually fall
|
||||||
// but if frontBreak is nonzero, we're breaking blocks in front, so don't let anything fall through this column,
|
// but if frontBreak is nonzero, we're breaking blocks in front, so don't let anything fall through this column,
|
||||||
@ -132,7 +132,7 @@ public class MovementDescend extends Movement {
|
|||||||
return IMPOSSIBLE; // TODO fix
|
return IMPOSSIBLE; // TODO fix
|
||||||
}
|
}
|
||||||
// found a fall into water
|
// found a fall into water
|
||||||
return new DescendResult(newY, tentativeCost); // TODO incorporate water swim up cost?
|
return new MoveResult(destX, newY, destZ, tentativeCost); // TODO incorporate water swim up cost?
|
||||||
}
|
}
|
||||||
if (ontoBlock.getBlock() == Blocks.FLOWING_WATER) {
|
if (ontoBlock.getBlock() == Blocks.FLOWING_WATER) {
|
||||||
return IMPOSSIBLE;
|
return IMPOSSIBLE;
|
||||||
@ -147,11 +147,11 @@ public class MovementDescend extends Movement {
|
|||||||
return IMPOSSIBLE; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect
|
return IMPOSSIBLE; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect
|
||||||
}
|
}
|
||||||
if (context.hasWaterBucket() && fallHeight <= context.maxFallHeightBucket() + 1) {
|
if (context.hasWaterBucket() && fallHeight <= context.maxFallHeightBucket() + 1) {
|
||||||
return new DescendResult(newY + 1, tentativeCost + context.placeBlockCost()); // this is the block we're falling onto, so dest is +1
|
return new MoveResult(destX, newY + 1, destZ, tentativeCost + context.placeBlockCost()); // this is the block we're falling onto, so dest is +1
|
||||||
}
|
}
|
||||||
if (fallHeight <= context.maxFallHeightNoWater() + 1) {
|
if (fallHeight <= context.maxFallHeightNoWater() + 1) {
|
||||||
// fallHeight = 4 means onto.up() is 3 blocks down, which is the max
|
// fallHeight = 4 means onto.up() is 3 blocks down, which is the max
|
||||||
return new DescendResult(newY + 1, tentativeCost);
|
return new MoveResult(destX, newY + 1, destZ, tentativeCost);
|
||||||
} else {
|
} else {
|
||||||
return IMPOSSIBLE;
|
return IMPOSSIBLE;
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,11 @@ import baritone.pathing.movement.MovementHelper;
|
|||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||||
import baritone.pathing.movement.movements.result.DescendResult;
|
import baritone.pathing.movement.movements.result.MoveResult;
|
||||||
import baritone.utils.*;
|
import baritone.utils.BlockStateInterface;
|
||||||
|
import baritone.utils.InputOverrideHandler;
|
||||||
|
import baritone.utils.RayTraceUtils;
|
||||||
|
import baritone.utils.Utils;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
@ -46,8 +49,8 @@ public class MovementFall extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(CalculationContext context) {
|
protected double calculateCost(CalculationContext context) {
|
||||||
DescendResult result = MovementDescend.cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
MoveResult result = MovementDescend.cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
||||||
if (result.y != dest.y) {
|
if (result.destY != dest.y) {
|
||||||
return COST_INF; // doesn't apply to us, this position is a descend not a fall
|
return COST_INF; // doesn't apply to us, this position is a descend not a fall
|
||||||
}
|
}
|
||||||
return result.cost;
|
return result.cost;
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Baritone.
|
|
||||||
*
|
|
||||||
* Baritone is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package baritone.pathing.movement.movements.result;
|
|
||||||
|
|
||||||
import static baritone.pathing.movement.ActionCosts.COST_INF;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Brady
|
|
||||||
* @since 9/23/2018
|
|
||||||
*/
|
|
||||||
public final class DescendResult extends Result {
|
|
||||||
|
|
||||||
public static final DescendResult IMPOSSIBLE = new DescendResult(0, COST_INF);
|
|
||||||
|
|
||||||
public final int y;
|
|
||||||
|
|
||||||
public DescendResult(int y, double cost) {
|
|
||||||
super(cost);
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
package baritone.pathing.movement.movements.result;
|
package baritone.pathing.movement.movements.result;
|
||||||
|
|
||||||
|
import static baritone.pathing.movement.ActionCosts.COST_INF;
|
||||||
|
|
||||||
public final class MoveResult {
|
public final class MoveResult {
|
||||||
|
public static final MoveResult IMPOSSIBLE = new MoveResult(0, 0, 0, COST_INF);
|
||||||
public final int destX;
|
public final int destX;
|
||||||
public final int destY;
|
public final int destY;
|
||||||
public final int destZ;
|
public final int destZ;
|
||||||
|
Loading…
Reference in New Issue
Block a user