001/* 002 * This file is part of Baritone. 003 * 004 * Baritone is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU Lesser General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * Baritone is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU Lesser General Public License for more details. 013 * 014 * You should have received a copy of the GNU Lesser General Public License 015 * along with Baritone. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package baritone.api.pathing.movement; 019 020public interface ActionCosts { 021 022 /** 023 * These costs are measured roughly in ticks btw 024 */ 025 double WALK_ONE_BLOCK_COST = 20 / 4.317; // 4.633 026 double WALK_ONE_IN_WATER_COST = 20 / 2.2; // 9.091 027 double WALK_ONE_OVER_SOUL_SAND_COST = WALK_ONE_BLOCK_COST * 2; // 0.4 in BlockSoulSand but effectively about half 028 double LADDER_UP_ONE_COST = 20 / 2.35; // 8.511 029 double LADDER_DOWN_ONE_COST = 20 / 3.0; // 6.667 030 double SNEAK_ONE_BLOCK_COST = 20 / 1.3; // 15.385 031 double SPRINT_ONE_BLOCK_COST = 20 / 5.612; // 3.564 032 double SPRINT_MULTIPLIER = SPRINT_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST; // 0.769 033 /** 034 * To walk off an edge you need to walk 0.5 to the edge then 0.3 to start falling off 035 */ 036 double WALK_OFF_BLOCK_COST = WALK_ONE_BLOCK_COST * 0.8; // 3.706 037 /** 038 * To walk the rest of the way to be centered on the new block 039 */ 040 double CENTER_AFTER_FALL_COST = WALK_ONE_BLOCK_COST - WALK_OFF_BLOCK_COST; // 0.927 041 042 /** 043 * don't make this Double.MAX_VALUE because it's added to other things, maybe other COST_INFs, 044 * and that would make it overflow to negative 045 */ 046 double COST_INF = 1000000; 047 048 double[] FALL_N_BLOCKS_COST = generateFallNBlocksCost(); 049 050 double FALL_1_25_BLOCKS_COST = distanceToTicks(1.25); 051 double FALL_0_25_BLOCKS_COST = distanceToTicks(0.25); 052 /** 053 * When you hit space, you get enough upward velocity to go 1.25 blocks 054 * Then, you fall the remaining 0.25 to get on the surface, on block higher. 055 * Since parabolas are symmetric, the amount of time it takes to ascend up from 1 to 1.25 056 * will be the same amount of time that it takes to fall back down from 1.25 to 1. 057 * And the same applies to the overall shape, if it takes X ticks to fall back down 1.25 blocks, 058 * it will take X ticks to reach the peak of your 1.25 block leap. 059 * Therefore, the part of your jump from y=0 to y=1.25 takes distanceToTicks(1.25) ticks, 060 * and the sub-part from y=1 to y=1.25 takes distanceToTicks(0.25) ticks. 061 * Therefore, the other sub-part, from y=0 to y-1, takes distanceToTicks(1.25)-distanceToTicks(0.25) ticks. 062 * That's why JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST 063 */ 064 double JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST; 065 066 067 static double[] generateFallNBlocksCost() { 068 double[] costs = new double[257]; 069 for (int i = 0; i < 257; i++) { 070 costs[i] = distanceToTicks(i); 071 } 072 return costs; 073 } 074 075 static double velocity(int ticks) { 076 return (Math.pow(0.98, ticks) - 1) * -3.92; 077 } 078 079 static double oldFormula(double ticks) { 080 return -3.92 * (99 - 49.5 * (Math.pow(0.98, ticks) + 1) - ticks); 081 } 082 083 static double distanceToTicks(double distance) { 084 if (distance == 0) { 085 return 0; // Avoid 0/0 NaN 086 } 087 double tmpDistance = distance; 088 int tickCount = 0; 089 while (true) { 090 double fallDistance = velocity(tickCount); 091 if (tmpDistance <= fallDistance) { 092 return tickCount + tmpDistance / fallDistance; 093 } 094 tmpDistance -= fallDistance; 095 tickCount++; 096 } 097 } 098}