cursed flowing

This commit is contained in:
Leijurv 2019-02-25 20:35:06 -08:00
parent 6e7320b954
commit 5412fa6cfd
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 29 additions and 12 deletions

View File

@ -19,10 +19,7 @@ package baritone.cache;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.pathing.PathingBlockType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDoublePlant;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.BlockTallGrass;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.ResourceLocation;
@ -73,7 +70,7 @@ public final class ChunkPacker {
for (int x = 0; x < 16; x++) {
int index = CachedChunk.getPositionIndex(x, y, z);
IBlockState state = bsc.get(x, y1, z);
boolean[] bits = getPathingBlockType(state).getBits();
boolean[] bits = getPathingBlockType(state, chunk, x, y, z).getBits();
bitSet.set(index, bits[0]);
bitSet.set(index + 1, bits[1]);
Block block = state.getBlock();
@ -122,11 +119,17 @@ public final class ChunkPacker {
return resourceCache.computeIfAbsent(name, n -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n));
}
private static PathingBlockType getPathingBlockType(IBlockState state) {
private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) {
Block block = state.getBlock();
if ((block == Blocks.WATER || block == Blocks.FLOWING_WATER) && !MovementHelper.isFlowing(state)) {
if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) {
// only water source blocks are plausibly usable, flowing water should be avoid
// FLOWING_WATER is a waterfall, it doesn't really matter and caching it as AVOID just makes it look wrong
if (!MovementHelper.possiblyFlowing(state)) {
return PathingBlockType.WATER;
}
if (BlockLiquid.getSlopeAngle(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4), state.getMaterial(), state) != -1000.0F) {
return PathingBlockType.AVOID;
}
return PathingBlockType.WATER;
}

View File

@ -109,7 +109,7 @@ public interface MovementHelper extends ActionCosts, Helper {
}
throw new IllegalStateException();
}
if (isFlowing(state)) {
if (isFlowing(x, y, z, state, bsi)) {
return false; // Don't walk through flowing liquids
}
if (block instanceof BlockLiquid) {
@ -288,10 +288,10 @@ public interface MovementHelper extends ActionCosts, Helper {
// since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()"
// BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability
Block up = bsi.get0(x, y + 1, z).getBlock();
if (up == Blocks.WATERLILY) {
if (up == Blocks.WATERLILY || up == Blocks.CARPET) {
return true;
}
if (isFlowing(state) || block == Blocks.FLOWING_WATER) {
if (isFlowing(x, y, z, state, bsi) || block == Blocks.FLOWING_WATER) {
// the only scenario in which we can walk on flowing water is if it's under still water with jesus off
return isWater(up) && !Baritone.settings().assumeWalkOnWater.get();
}
@ -488,12 +488,26 @@ public interface MovementHelper extends ActionCosts, Helper {
return BlockStateInterface.getBlock(ctx, p) instanceof BlockLiquid;
}
static boolean isFlowing(IBlockState state) {
static boolean possiblyFlowing(IBlockState state) {
// Will be IFluidState in 1.13
return state.getBlock() instanceof BlockLiquid
&& state.getValue(BlockLiquid.LEVEL) != 0;
}
static boolean isFlowing(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
if (!(state.getBlock() instanceof BlockLiquid)) {
return false;
}
if (state.getValue(BlockLiquid.LEVEL) != 0) {
return true;
}
return possiblyFlowing(bsi.get0(x + 1, y, z))
|| possiblyFlowing(bsi.get0(x - 1, y, z))
|| possiblyFlowing(bsi.get0(x, y, z + 1))
|| possiblyFlowing(bsi.get0(x, y, z - 1));
}
static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) {
IPlayerContext ctx = baritone.getPlayerContext();
Optional<Rotation> direct = RotationUtils.reachable(ctx, placeAt); // we assume that if there is a block there, it must be replacable

View File

@ -143,7 +143,7 @@ public class MovementDescend extends Movement {
if (context.assumeWalkOnWater) {
return false; // TODO fix
}
if (MovementHelper.isFlowing(ontoBlock)) {
if (MovementHelper.isFlowing(destX, newY, destZ, ontoBlock, context.bsi)) {
return false; // TODO flowing check required here?
}
if (!MovementHelper.canWalkOn(context.bsi, destX, newY - 1, destZ)) {