From 5412fa6cfd92d6249e2c507d06b8fe3164c31ee4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 25 Feb 2019 20:35:06 -0800 Subject: [PATCH] cursed flowing --- src/main/java/baritone/cache/ChunkPacker.java | 17 ++++++++------ .../pathing/movement/MovementHelper.java | 22 +++++++++++++++---- .../movement/movements/MovementDescend.java | 2 +- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java index e2903ceaf..892369d5b 100644 --- a/src/main/java/baritone/cache/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -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; } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index a3fbf0419..592aecd0e 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -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 direct = RotationUtils.reachable(ctx, placeAt); // we assume that if there is a block there, it must be replacable diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 914a2993e..3a8ed913e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -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)) {