standardize on moveresult

This commit is contained in:
Leijurv 2018-09-24 10:55:35 -07:00
parent ba7e9a56e3
commit 0ed6bc966e
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 18 additions and 88 deletions

View File

@ -19,7 +19,6 @@ package baritone.pathing.movement;
import baritone.pathing.movement.movements.*;
import baritone.pathing.movement.movements.result.MoveResult;
import baritone.pathing.movement.movements.result.ParkourResult;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.util.EnumFacing;
@ -273,8 +272,7 @@ public enum Moves {
@Override
public MoveResult apply(CalculationContext context, int x, int y, int z) {
ParkourResult res = MovementParkour.cost(context, x, y, z, EnumFacing.NORTH);
return new MoveResult(res.x, y, res.z, res.cost);
return MovementParkour.cost(context, x, y, z, EnumFacing.NORTH);
}
},
@ -286,8 +284,7 @@ public enum Moves {
@Override
public MoveResult apply(CalculationContext context, int x, int y, int z) {
ParkourResult res = MovementParkour.cost(context, x, y, z, EnumFacing.SOUTH);
return new MoveResult(res.x, y, res.z, res.cost);
return MovementParkour.cost(context, x, y, z, EnumFacing.SOUTH);
}
},
@ -299,8 +296,7 @@ public enum Moves {
@Override
public MoveResult apply(CalculationContext context, int x, int y, int z) {
ParkourResult res = MovementParkour.cost(context, x, y, z, EnumFacing.EAST);
return new MoveResult(res.x, y, res.z, res.cost);
return MovementParkour.cost(context, x, y, z, EnumFacing.EAST);
}
},
@ -312,8 +308,7 @@ public enum Moves {
@Override
public MoveResult apply(CalculationContext context, int x, int y, int z) {
ParkourResult res = MovementParkour.cost(context, x, y, z, EnumFacing.WEST);
return new MoveResult(res.x, y, res.z, res.cost);
return MovementParkour.cost(context, x, y, z, EnumFacing.WEST);
}
};

View File

@ -23,7 +23,7 @@ import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.movements.result.ParkourResult;
import baritone.pathing.movement.movements.result.MoveResult;
import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler;
import baritone.utils.Utils;
@ -37,7 +37,7 @@ import net.minecraft.util.math.Vec3d;
import java.util.Objects;
import static baritone.pathing.movement.movements.result.ParkourResult.IMPOSSIBLE;
import static baritone.pathing.movement.movements.result.MoveResult.IMPOSSIBLE;
public class MovementParkour extends Movement {
@ -54,12 +54,12 @@ public class MovementParkour extends Movement {
}
public static MovementParkour cost(CalculationContext context, BetterBlockPos src, EnumFacing direction) {
ParkourResult res = cost(context, src.x, src.y, src.z, direction);
int dist = Math.abs(res.x - src.x) + Math.abs(res.z - src.z);
MoveResult res = cost(context, src.x, src.y, src.z, direction);
int dist = Math.abs(res.destX - src.x) + Math.abs(res.destZ - src.z);
return new MovementParkour(src, dist, direction);
}
public static ParkourResult cost(CalculationContext context, int x, int y, int z, EnumFacing dir) {
public static MoveResult cost(CalculationContext context, int x, int y, int z, EnumFacing dir) {
if (!Baritone.settings().allowParkour.get()) {
return IMPOSSIBLE;
}
@ -97,7 +97,7 @@ public class MovementParkour extends Movement {
}
}
if (MovementHelper.canWalkOn(x + xDiff * i, y - 1, z + zDiff * i)) {
return new ParkourResult(x + xDiff * i, z + zDiff * i, costFromJumpDistance(i));
return new MoveResult(x + xDiff * i, y, z + zDiff * i, costFromJumpDistance(i));
}
}
if (!context.canSprint()) {
@ -122,7 +122,7 @@ public class MovementParkour extends Movement {
continue;
}
if (MovementHelper.canPlaceAgainst(againstX, y - 1, againstZ)) {
return new ParkourResult(destX, destZ, costFromJumpDistance(i) + context.placeBlockCost());
return new MoveResult(destX, y, destZ, costFromJumpDistance(i) + context.placeBlockCost());
}
}
return IMPOSSIBLE;
@ -144,8 +144,8 @@ public class MovementParkour extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
ParkourResult res = cost(context, src.x, src.y, src.z, direction);
if (res.x != dest.x || res.z != dest.z) {
MoveResult res = cost(context, src.x, src.y, src.z, direction);
if (res.destX != dest.x || res.destZ != dest.z) {
return COST_INF;
}
return res.cost;

View File

@ -19,6 +19,11 @@ package baritone.pathing.movement.movements.result;
import static baritone.pathing.movement.ActionCosts.COST_INF;
/**
* The result of a calculated movement, with destination x, y, z, and the cost of performing the movement
*
* @author leijurv
*/
public final class MoveResult {
public static final MoveResult IMPOSSIBLE = new MoveResult(0, 0, 0, COST_INF);
public final int destX;

View File

@ -1,37 +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 ParkourResult extends Result {
public static final ParkourResult IMPOSSIBLE = new ParkourResult(0, 0, COST_INF);
public final int x, z;
public ParkourResult(int x, int z, double cost) {
super(cost);
this.x = x;
this.z = z;
}
}

View File

@ -1,33 +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;
/**
* Generic class for special movement results. Only contains a single "cost" field.
*
* @author Brady
* @since 9/23/2018
*/
public class Result {
public final double cost;
public Result(double cost) {
this.cost = cost;
}
}