baritone/src/test/java/baritone/pathing/movement/ActionCostsTest.java

53 lines
2.0 KiB
Java
Raw Normal View History

2018-08-08 03:16:53 +00:00
/*
* 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
2018-08-08 03:16:53 +00:00
* 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,
2018-08-08 03:16:53 +00:00
* 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.
2018-08-08 03:16:53 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
2018-08-08 03:16:53 +00:00
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
2018-08-22 20:15:56 +00:00
package baritone.pathing.movement;
2018-08-04 22:28:36 +00:00
import org.junit.Test;
2018-09-25 01:45:16 +00:00
import static baritone.api.pathing.movement.ActionCosts.*;
2018-08-04 22:28:36 +00:00
import static org.junit.Assert.assertEquals;
2018-09-25 14:08:29 +00:00
public class ActionCostsTest {
2019-09-19 20:40:46 +00:00
2018-08-04 22:28:36 +00:00
@Test
public void testFallNBlocksCost() {
assertEquals(FALL_N_BLOCKS_COST.length, 4097); // Fall 0 blocks through fall 4096 blocks
2022-02-08 18:41:45 +00:00
for (int i = 0; i < 4097; i++) {
2018-08-05 03:19:32 +00:00
double blocks = ticksToBlocks(FALL_N_BLOCKS_COST[i]);
2022-02-08 18:41:45 +00:00
assertEquals(blocks, i, 0.00000000001); // If you add another 0 the test fails at i=989 LOL
2018-08-04 22:28:36 +00:00
}
2018-08-17 19:24:40 +00:00
assertEquals(FALL_1_25_BLOCKS_COST, 6.2344, 0.00001);
assertEquals(FALL_0_25_BLOCKS_COST, 3.0710, 0.00001);
assertEquals(JUMP_ONE_BLOCK_COST, 3.1634, 0.00001);
2018-08-04 22:28:36 +00:00
}
2018-08-05 03:19:32 +00:00
public double ticksToBlocks(double ticks) {
double fallDistance = 0;
int integralComponent = (int) Math.floor(ticks);
for (int tick = 0; tick < integralComponent; tick++) {
fallDistance += velocity(tick);
}
double partialTickComponent = ticks - Math.floor(ticks);
double finalPartialTickVelocity = velocity(integralComponent);
double finalPartialTickDistance = finalPartialTickVelocity * partialTickComponent;
fallDistance += finalPartialTickDistance;
return fallDistance;
}
2018-12-21 05:22:18 +00:00
}