Merge ActionCosts with ActionCostsButOnlyTheOnesThatMakeMickeyDieInside
This commit is contained in:
parent
0f7743263e
commit
40bea503c3
@ -17,14 +17,14 @@
|
|||||||
|
|
||||||
package baritone.api.pathing.goals;
|
package baritone.api.pathing.goals;
|
||||||
|
|
||||||
import baritone.api.pathing.movement.ActionCostsButOnlyTheOnesThatMakeMickeyDieInside;
|
import baritone.api.pathing.movement.ActionCosts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful for mining (getting to diamond / iron level)
|
* Useful for mining (getting to diamond / iron level)
|
||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class GoalYLevel implements Goal, ActionCostsButOnlyTheOnesThatMakeMickeyDieInside {
|
public class GoalYLevel implements Goal, ActionCosts {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target Y level
|
* The target Y level
|
||||||
@ -48,11 +48,11 @@ public class GoalYLevel implements Goal, ActionCostsButOnlyTheOnesThatMakeMickey
|
|||||||
public static double calculate(int goalY, int currentY) {
|
public static double calculate(int goalY, int currentY) {
|
||||||
if (currentY > goalY) {
|
if (currentY > goalY) {
|
||||||
// need to descend
|
// need to descend
|
||||||
return ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.FALL_N_BLOCKS_COST[2] / 2 * (currentY - goalY);
|
return FALL_N_BLOCKS_COST[2] / 2 * (currentY - goalY);
|
||||||
}
|
}
|
||||||
if (currentY < goalY) {
|
if (currentY < goalY) {
|
||||||
// need to ascend
|
// need to ascend
|
||||||
return (goalY - currentY) * ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.JUMP_ONE_BLOCK_COST;
|
return (goalY - currentY) * JUMP_ONE_BLOCK_COST;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,7 @@
|
|||||||
|
|
||||||
package baritone.api.pathing.movement;
|
package baritone.api.pathing.movement;
|
||||||
|
|
||||||
import baritone.api.pathing.movement.ActionCostsButOnlyTheOnesThatMakeMickeyDieInside;
|
public interface ActionCosts {
|
||||||
|
|
||||||
public interface ActionCosts extends ActionCostsButOnlyTheOnesThatMakeMickeyDieInside {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These costs are measured roughly in ticks btw
|
* These costs are measured roughly in ticks btw
|
||||||
@ -46,4 +44,55 @@ public interface ActionCosts extends ActionCostsButOnlyTheOnesThatMakeMickeyDieI
|
|||||||
* and that would make it overflow to negative
|
* and that would make it overflow to negative
|
||||||
*/
|
*/
|
||||||
double COST_INF = 1000000;
|
double COST_INF = 1000000;
|
||||||
|
|
||||||
|
double[] FALL_N_BLOCKS_COST = generateFallNBlocksCost();
|
||||||
|
|
||||||
|
double FALL_1_25_BLOCKS_COST = distanceToTicks(1.25);
|
||||||
|
double FALL_0_25_BLOCKS_COST = distanceToTicks(0.25);
|
||||||
|
/**
|
||||||
|
* When you hit space, you get enough upward velocity to go 1.25 blocks
|
||||||
|
* Then, you fall the remaining 0.25 to get on the surface, on block higher.
|
||||||
|
* Since parabolas are symmetric, the amount of time it takes to ascend up from 1 to 1.25
|
||||||
|
* will be the same amount of time that it takes to fall back down from 1.25 to 1.
|
||||||
|
* And the same applies to the overall shape, if it takes X ticks to fall back down 1.25 blocks,
|
||||||
|
* it will take X ticks to reach the peak of your 1.25 block leap.
|
||||||
|
* Therefore, the part of your jump from y=0 to y=1.25 takes distanceToTicks(1.25) ticks,
|
||||||
|
* and the sub-part from y=1 to y=1.25 takes distanceToTicks(0.25) ticks.
|
||||||
|
* Therefore, the other sub-part, from y=0 to y-1, takes distanceToTicks(1.25)-distanceToTicks(0.25) ticks.
|
||||||
|
* That's why JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST
|
||||||
|
*/
|
||||||
|
double JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST;
|
||||||
|
|
||||||
|
|
||||||
|
static double[] generateFallNBlocksCost() {
|
||||||
|
double[] costs = new double[257];
|
||||||
|
for (int i = 0; i < 257; i++) {
|
||||||
|
costs[i] = distanceToTicks(i);
|
||||||
|
}
|
||||||
|
return costs;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double velocity(int ticks) {
|
||||||
|
return (Math.pow(0.98, ticks) - 1) * -3.92;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double oldFormula(double ticks) {
|
||||||
|
return -3.92 * (99 - 49.5 * (Math.pow(0.98, ticks) + 1) - ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double distanceToTicks(double distance) {
|
||||||
|
if (distance == 0) {
|
||||||
|
return 0; // Avoid 0/0 NaN
|
||||||
|
}
|
||||||
|
double tmpDistance = distance;
|
||||||
|
int tickCount = 0;
|
||||||
|
while (true) {
|
||||||
|
double fallDistance = velocity(tickCount);
|
||||||
|
if (tmpDistance <= fallDistance) {
|
||||||
|
return tickCount + tmpDistance / fallDistance;
|
||||||
|
}
|
||||||
|
tmpDistance -= fallDistance;
|
||||||
|
tickCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,71 +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.api.pathing.movement;
|
|
||||||
|
|
||||||
public interface ActionCostsButOnlyTheOnesThatMakeMickeyDieInside {
|
|
||||||
double[] FALL_N_BLOCKS_COST = generateFallNBlocksCost();
|
|
||||||
|
|
||||||
double FALL_1_25_BLOCKS_COST = distanceToTicks(1.25);
|
|
||||||
double FALL_0_25_BLOCKS_COST = distanceToTicks(0.25);
|
|
||||||
/**
|
|
||||||
* When you hit space, you get enough upward velocity to go 1.25 blocks
|
|
||||||
* Then, you fall the remaining 0.25 to get on the surface, on block higher.
|
|
||||||
* Since parabolas are symmetric, the amount of time it takes to ascend up from 1 to 1.25
|
|
||||||
* will be the same amount of time that it takes to fall back down from 1.25 to 1.
|
|
||||||
* And the same applies to the overall shape, if it takes X ticks to fall back down 1.25 blocks,
|
|
||||||
* it will take X ticks to reach the peak of your 1.25 block leap.
|
|
||||||
* Therefore, the part of your jump from y=0 to y=1.25 takes distanceToTicks(1.25) ticks,
|
|
||||||
* and the sub-part from y=1 to y=1.25 takes distanceToTicks(0.25) ticks.
|
|
||||||
* Therefore, the other sub-part, from y=0 to y-1, takes distanceToTicks(1.25)-distanceToTicks(0.25) ticks.
|
|
||||||
* That's why JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST
|
|
||||||
*/
|
|
||||||
double JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST;
|
|
||||||
|
|
||||||
|
|
||||||
static double[] generateFallNBlocksCost() {
|
|
||||||
double[] costs = new double[257];
|
|
||||||
for (int i = 0; i < 257; i++) {
|
|
||||||
costs[i] = distanceToTicks(i);
|
|
||||||
}
|
|
||||||
return costs;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double velocity(int ticks) {
|
|
||||||
return (Math.pow(0.98, ticks) - 1) * -3.92;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double oldFormula(double ticks) {
|
|
||||||
return -3.92 * (99 - 49.5 * (Math.pow(0.98, ticks) + 1) - ticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
static double distanceToTicks(double distance) {
|
|
||||||
if (distance == 0) {
|
|
||||||
return 0; // Avoid 0/0 NaN
|
|
||||||
}
|
|
||||||
double tmpDistance = distance;
|
|
||||||
int tickCount = 0;
|
|
||||||
while (true) {
|
|
||||||
double fallDistance = velocity(tickCount);
|
|
||||||
if (tmpDistance <= fallDistance) {
|
|
||||||
return tickCount + tmpDistance / fallDistance;
|
|
||||||
}
|
|
||||||
tmpDistance -= fallDistance;
|
|
||||||
tickCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user