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
2018-09-17 22:11:40 +00:00
* 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 .
*
2018-08-08 04:15:22 +00:00
* 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
2018-09-17 22:11:40 +00:00
* GNU Lesser General Public License for more details .
2018-08-08 03:16:53 +00:00
*
2018-09-17 22:11:40 +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.movements ;
2018-08-06 15:27:50 +00:00
2018-08-22 20:15:56 +00:00
import baritone.pathing.movement.CalculationContext ;
import baritone.pathing.movement.Movement ;
import baritone.pathing.movement.MovementHelper ;
import baritone.pathing.movement.MovementState ;
import baritone.pathing.movement.MovementState.MovementStatus ;
import baritone.utils.BlockStateInterface ;
import baritone.utils.InputOverrideHandler ;
2018-09-09 16:22:35 +00:00
import baritone.utils.pathing.BetterBlockPos ;
2018-08-06 15:27:50 +00:00
import net.minecraft.block.Block ;
2018-08-13 20:18:42 +00:00
import net.minecraft.init.Blocks ;
2018-08-06 15:27:50 +00:00
import net.minecraft.util.math.BlockPos ;
public class MovementDescend extends Movement {
2018-08-07 21:14:36 +00:00
2018-09-17 00:49:19 +00:00
private int numTicks = 0 ;
2018-09-09 16:22:35 +00:00
public MovementDescend ( BetterBlockPos start , BetterBlockPos end ) {
2018-08-28 20:41:44 +00:00
super ( start , end , new BlockPos [ ] { end . up ( 2 ) , end . up ( ) , end } , end . down ( ) ) ;
2018-08-06 15:27:50 +00:00
}
2018-08-23 18:14:37 +00:00
@Override
public void reset ( ) {
super . reset ( ) ;
numTicks = 0 ;
}
2018-08-06 15:27:50 +00:00
@Override
2018-08-07 21:36:32 +00:00
protected double calculateCost ( CalculationContext context ) {
2018-09-03 16:15:18 +00:00
Block fromDown = BlockStateInterface . get ( src . down ( ) ) . getBlock ( ) ;
if ( fromDown = = Blocks . LADDER | | fromDown = = Blocks . VINE ) {
return COST_INF ;
}
2018-08-28 20:41:44 +00:00
if ( ! MovementHelper . canWalkOn ( positionToPlace ) ) {
2018-08-06 15:27:50 +00:00
return COST_INF ;
}
Block tmp1 = BlockStateInterface . get ( dest ) . getBlock ( ) ;
2018-09-03 16:15:18 +00:00
if ( tmp1 = = Blocks . LADDER | | tmp1 = = Blocks . VINE ) {
2018-08-06 15:27:50 +00:00
return COST_INF ;
}
2018-08-07 21:36:32 +00:00
// we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel)
2018-08-13 20:18:42 +00:00
double walk = WALK_OFF_BLOCK_COST ;
2018-09-03 16:15:18 +00:00
if ( fromDown = = Blocks . SOUL_SAND ) {
2018-08-17 19:24:40 +00:00
// use this ratio to apply the soul sand speed penalty to our 0.8 block distance
2018-09-03 16:15:18 +00:00
walk = WALK_ONE_OVER_SOUL_SAND_COST ;
2018-08-13 20:18:42 +00:00
}
2018-08-17 20:17:16 +00:00
return walk + Math . max ( FALL_N_BLOCKS_COST [ 1 ] , CENTER_AFTER_FALL_COST ) + getTotalHardnessOfBlocksToBreak ( context ) ;
2018-08-06 15:27:50 +00:00
}
@Override
public MovementState updateState ( MovementState state ) {
super . updateState ( state ) ;
2018-09-08 04:32:25 +00:00
if ( state . getStatus ( ) ! = MovementStatus . RUNNING ) {
2018-08-26 07:53:50 +00:00
return state ;
2018-09-08 04:32:25 +00:00
}
2018-08-25 23:30:12 +00:00
2018-08-14 15:28:35 +00:00
BlockPos playerFeet = playerFeet ( ) ;
if ( playerFeet . equals ( dest ) ) {
2018-08-20 22:01:34 +00:00
if ( BlockStateInterface . isLiquid ( dest ) | | player ( ) . posY - playerFeet . getY ( ) < 0 . 094 ) { // lilypads
2018-08-14 15:28:35 +00:00
// Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
2018-09-17 17:17:42 +00:00
return state . setStatus ( MovementStatus . SUCCESS ) ;
2018-08-14 15:28:35 +00:00
} else {
System . out . println ( player ( ) . posY + " " + playerFeet . getY ( ) + " " + ( player ( ) . posY - playerFeet . getY ( ) ) ) ;
}
}
double diffX = player ( ) . posX - ( dest . getX ( ) + 0 . 5 ) ;
double diffZ = player ( ) . posZ - ( dest . getZ ( ) + 0 . 5 ) ;
double ab = Math . sqrt ( diffX * diffX + diffZ * diffZ ) ;
double x = player ( ) . posX - ( src . getX ( ) + 0 . 5 ) ;
double z = player ( ) . posZ - ( src . getZ ( ) + 0 . 5 ) ;
double fromStart = Math . sqrt ( x * x + z * z ) ;
if ( ! playerFeet . equals ( dest ) | | ab > 0 . 25 ) {
BlockPos fakeDest = new BlockPos ( dest . getX ( ) * 2 - src . getX ( ) , dest . getY ( ) , dest . getZ ( ) * 2 - src . getZ ( ) ) ;
if ( numTicks + + < 20 ) {
MovementHelper . moveTowards ( state , fakeDest ) ;
if ( fromStart > 1 . 25 ) {
state . setInput ( InputOverrideHandler . Input . MOVE_FORWARD , false ) ;
state . setInput ( InputOverrideHandler . Input . MOVE_BACK , true ) ;
}
} else {
MovementHelper . moveTowards ( state , dest ) ;
}
}
return state ;
2018-08-06 15:27:50 +00:00
}
}