2018-08-02 21:28:35 +00:00
|
|
|
package baritone.bot.pathing.movement;
|
2018-08-02 17:25:46 +00:00
|
|
|
|
|
|
|
import baritone.bot.utils.BlockStateInterface;
|
2018-08-04 02:14:50 +00:00
|
|
|
import baritone.bot.utils.Helper;
|
2018-08-02 17:49:31 +00:00
|
|
|
import baritone.bot.utils.ToolSet;
|
2018-08-02 17:25:46 +00:00
|
|
|
import net.minecraft.block.*;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.client.Minecraft;
|
2018-08-04 02:14:50 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
2018-08-02 17:49:31 +00:00
|
|
|
import net.minecraft.init.Blocks;
|
2018-08-02 17:25:46 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-08-04 02:14:50 +00:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2018-08-02 17:25:46 +00:00
|
|
|
|
2018-08-06 07:21:47 +00:00
|
|
|
import java.util.Optional;
|
|
|
|
|
2018-08-02 17:25:46 +00:00
|
|
|
/**
|
|
|
|
* Static helpers for cost calculation
|
|
|
|
*
|
|
|
|
* @author leijurv
|
|
|
|
*/
|
2018-08-04 02:14:50 +00:00
|
|
|
public interface MovementHelper extends ActionCosts, Helper {
|
2018-08-03 07:51:10 +00:00
|
|
|
|
|
|
|
Block waterFlowing = Blocks.FLOWING_WATER;
|
2018-08-04 02:14:50 +00:00
|
|
|
Block waterStill = Blocks.WATER;
|
|
|
|
Block lavaFlowing = Blocks.FLOWING_LAVA;
|
|
|
|
Block lavaStill = Blocks.LAVA;
|
2018-08-02 17:25:46 +00:00
|
|
|
|
|
|
|
/**
|
2018-08-03 07:51:10 +00:00
|
|
|
* Returns whether or not the specified block is
|
|
|
|
* water, regardless of whether or not it is flowing.
|
2018-08-02 17:25:46 +00:00
|
|
|
*
|
2018-08-03 07:51:10 +00:00
|
|
|
* @param b The block
|
|
|
|
* @return Whether or not the block is water
|
2018-08-02 17:25:46 +00:00
|
|
|
*/
|
|
|
|
static boolean isWater(Block b) {
|
|
|
|
return waterFlowing.equals(b) || waterStill.equals(b);
|
|
|
|
}
|
|
|
|
|
2018-08-03 07:51:10 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not the block at the specified pos is
|
|
|
|
* water, regardless of whether or not it is flowing.
|
|
|
|
*
|
|
|
|
* @param bp The block pos
|
|
|
|
* @return Whether or not the block is water
|
|
|
|
*/
|
2018-08-02 17:25:46 +00:00
|
|
|
static boolean isWater(BlockPos bp) {
|
|
|
|
return isWater(BlockStateInterface.get(bp).getBlock());
|
|
|
|
}
|
|
|
|
|
2018-08-03 07:51:10 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not the specified block is any sort of liquid.
|
|
|
|
*
|
|
|
|
* @param b The block
|
|
|
|
* @return Whether or not the block is a liquid
|
|
|
|
*/
|
2018-08-02 17:25:46 +00:00
|
|
|
static boolean isLiquid(Block b) {
|
|
|
|
return b instanceof BlockLiquid;
|
2018-08-03 07:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean isLiquid(BlockPos p) {
|
|
|
|
return isLiquid(BlockStateInterface.get(p).getBlock());
|
2018-08-02 17:25:46 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 17:55:26 +00:00
|
|
|
static boolean isFlowing(IBlockState state) {
|
|
|
|
return state.getBlock() instanceof BlockLiquid
|
|
|
|
&& state.getPropertyKeys().contains(BlockLiquid.LEVEL)
|
|
|
|
&& state.getValue(BlockLiquid.LEVEL) != 0;
|
2018-08-02 17:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean isLava(Block b) {
|
|
|
|
return lavaFlowing.equals(b) || lavaStill.equals(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static boolean avoidBreaking(BlockPos pos) {
|
|
|
|
Block b = BlockStateInterface.get(pos).getBlock();
|
|
|
|
Block below = BlockStateInterface.get(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock();
|
2018-08-02 17:56:26 +00:00
|
|
|
return Blocks.ICE.equals(b) // ice becomes water, and water can mess up the path
|
2018-08-04 22:17:53 +00:00
|
|
|
|| b instanceof BlockSilverfish
|
2018-08-02 17:25:46 +00:00
|
|
|
|| isLiquid(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))//don't break anything touching liquid on any side
|
|
|
|
|| isLiquid(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ()))
|
|
|
|
|| isLiquid(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()))
|
|
|
|
|| isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1))
|
|
|
|
|| isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1))
|
|
|
|
|| (!(b instanceof BlockLilyPad && isWater(below)) && isLiquid(below));//if it's a lilypad above water, it's ok to break, otherwise don't break if its liquid
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can I walk through this block? e.g. air, saplings, torches, etc
|
|
|
|
*
|
|
|
|
* @param pos
|
|
|
|
* @return
|
|
|
|
*/
|
2018-08-04 02:14:50 +00:00
|
|
|
static boolean canWalkThrough(BlockPos pos, IBlockState state) {
|
2018-08-02 17:25:46 +00:00
|
|
|
Block block = state.getBlock();
|
2018-08-04 22:17:53 +00:00
|
|
|
if (block instanceof BlockLilyPad
|
|
|
|
|| block instanceof BlockFire
|
|
|
|
|| block instanceof BlockTripWire) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire
|
2018-08-02 17:25:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-04 22:17:53 +00:00
|
|
|
if (isFlowing(state) || isLiquid(pos.up())) {
|
2018-08-02 17:55:26 +00:00
|
|
|
return false; // Don't walk through flowing liquids
|
2018-08-02 17:25:46 +00:00
|
|
|
}
|
|
|
|
return block.isPassable(Minecraft.getMinecraft().world, pos);
|
|
|
|
}
|
|
|
|
|
2018-08-03 20:31:33 +00:00
|
|
|
static boolean avoidWalkingInto(Block block) {
|
|
|
|
return isLava(block)
|
|
|
|
|| block instanceof BlockCactus
|
2018-08-04 22:17:53 +00:00
|
|
|
|| block instanceof BlockFire
|
|
|
|
|| block instanceof BlockEndPortal
|
|
|
|
|| block instanceof BlockWeb;
|
2018-08-02 17:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can I walk on this block without anything weird happening like me falling
|
|
|
|
* through? Includes water because we know that we automatically jump on
|
|
|
|
* lava
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
2018-08-06 01:17:04 +00:00
|
|
|
static boolean canWalkOn(BlockPos pos, IBlockState state) {
|
2018-08-02 17:25:46 +00:00
|
|
|
Block block = state.getBlock();
|
|
|
|
if (block instanceof BlockLadder || block instanceof BlockVine) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-06 02:09:29 +00:00
|
|
|
if (block instanceof BlockAir) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-02 17:25:46 +00:00
|
|
|
if (isWater(block)) {
|
2018-08-04 22:17:53 +00:00
|
|
|
return isWater(pos.up()); // You can only walk on water if there is water above it
|
2018-08-02 17:25:46 +00:00
|
|
|
}
|
|
|
|
return state.isBlockNormalCube() && !isLava(block);
|
|
|
|
}
|
2018-08-02 17:49:31 +00:00
|
|
|
|
2018-08-06 01:17:04 +00:00
|
|
|
|
2018-08-02 17:49:31 +00:00
|
|
|
static boolean canFall(BlockPos pos) {
|
|
|
|
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
|
|
|
}
|
|
|
|
|
2018-08-04 02:14:50 +00:00
|
|
|
static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) {
|
|
|
|
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) {
|
2018-08-02 17:49:31 +00:00
|
|
|
if (avoidBreaking(position)) {
|
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
//if (!Baritone.allowBreakOrPlace) {
|
|
|
|
// return COST_INF;
|
|
|
|
//}
|
2018-08-02 17:57:11 +00:00
|
|
|
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1;
|
2018-08-02 17:49:31 +00:00
|
|
|
return m / ts.getStrVsBlock(block, position) + BREAK_ONE_BLOCK_ADD;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2018-08-04 02:14:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently highlighted block.
|
|
|
|
* Updated once a tick by Minecraft.
|
|
|
|
*
|
2018-08-06 07:21:47 +00:00
|
|
|
* @return the position of the highlighted block
|
2018-08-04 02:14:50 +00:00
|
|
|
*/
|
2018-08-06 07:21:47 +00:00
|
|
|
static Optional<BlockPos> whatAmILookingAt() {
|
2018-08-04 02:14:50 +00:00
|
|
|
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK) {
|
2018-08-06 07:21:47 +00:00
|
|
|
return Optional.of(mc.objectMouseOver.getBlockPos());
|
2018-08-04 02:14:50 +00:00
|
|
|
}
|
2018-08-06 07:21:47 +00:00
|
|
|
return Optional.empty();
|
2018-08-04 02:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The entity the player is currently looking at
|
|
|
|
*
|
2018-08-06 07:21:47 +00:00
|
|
|
* @return the entity object
|
2018-08-04 02:14:50 +00:00
|
|
|
*/
|
2018-08-06 07:21:47 +00:00
|
|
|
static Optional<Entity> whatEntityAmILookingAt() {
|
2018-08-04 02:14:50 +00:00
|
|
|
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.ENTITY) {
|
2018-08-06 07:21:47 +00:00
|
|
|
return Optional.of(mc.objectMouseOver.entityHit);
|
2018-08-04 02:14:50 +00:00
|
|
|
}
|
2018-08-06 07:21:47 +00:00
|
|
|
return Optional.empty();
|
2018-08-04 02:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AutoTool
|
|
|
|
*/
|
|
|
|
static void switchToBestTool() {
|
2018-08-06 07:21:47 +00:00
|
|
|
whatAmILookingAt().ifPresent(pos -> {
|
|
|
|
IBlockState state = BlockStateInterface.get(pos);
|
|
|
|
if (state.getBlock().equals(Blocks.AIR)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switchToBestToolFor(state);
|
|
|
|
});
|
2018-08-04 02:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AutoTool for a specific block
|
|
|
|
*
|
|
|
|
* @param b the blockstate to mine
|
|
|
|
*/
|
|
|
|
static void switchToBestToolFor(IBlockState b) {
|
|
|
|
switchToBestToolFor(b, new ToolSet());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AutoTool for a specific block with precomputed ToolSet data
|
|
|
|
*
|
|
|
|
* @param b the blockstate to mine
|
|
|
|
* @param ts previously calculated ToolSet
|
|
|
|
*/
|
|
|
|
static void switchToBestToolFor(IBlockState b, ToolSet ts) {
|
2018-08-06 07:21:47 +00:00
|
|
|
mc.player.inventory.currentItem = ts.getBestSlot(b);
|
2018-08-04 02:14:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 00:27:45 +00:00
|
|
|
static boolean isAir(BlockPos pos) {
|
|
|
|
return BlockStateInterface.get(pos).getBlock().equals(Blocks.AIR);
|
|
|
|
}
|
2018-08-02 17:25:46 +00:00
|
|
|
}
|