From e1bb7811651dc15d65bb630602b2c5a9028311df Mon Sep 17 00:00:00 2001 From: RuleGaed Date: Wed, 8 Jul 2026 23:26:34 +0300 Subject: [PATCH] optimize blockstate precompute masks --- .../pathfinder/WalkNodeEvaluator.java.patch | 71 +++++++++++++++++++ .../java/org/dreeam/leaf/util/BlockMasks.java | 20 ++++++ 2 files changed, 91 insertions(+) create mode 100644 gale-server/minecraft-patches/sources/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java.patch diff --git a/gale-server/minecraft-patches/sources/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java.patch b/gale-server/minecraft-patches/sources/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java.patch new file mode 100644 index 00000000..3267d744 --- /dev/null +++ b/gale-server/minecraft-patches/sources/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java.patch @@ -0,0 +1,71 @@ +--- a/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java ++++ b/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java +@@ -524,64 +_,64 @@ + if (blockState.isAir()) { + return PathType.OPEN; + } + +- if (blockState.is(BlockTags.TRAPDOORS) || blockState.is(Blocks.LILY_PAD) || blockState.is(Blocks.BIG_DRIPLEAF)) { ++ if (blockState.isAny(org.dreeam.leaf.util.BlockMasks.TRAPDOORS_TAG) || blockState.is(Blocks.LILY_PAD) || blockState.is(Blocks.BIG_DRIPLEAF)) { // Gale - Pre-compute - Common BlockState predicates - Apply + return PathType.TRAPDOOR; + } + + if (blockState.is(Blocks.POWDER_SNOW)) { + return PathType.POWDER_SNOW; + } + + if (blockState.is(Blocks.CACTUS) || blockState.is(Blocks.SWEET_BERRY_BUSH)) { + return PathType.DAMAGING; + } + + if (blockState.is(Blocks.HONEY_BLOCK)) { + return PathType.STICKY_HONEY; + } + + if (blockState.is(Blocks.COCOA)) { + return PathType.COCOA; + } + +- if (!blockState.is(Blocks.WITHER_ROSE) && !blockState.is(BlockTags.SPELEOTHEMS)) { ++ if (!blockState.is(Blocks.WITHER_ROSE) && !blockState.isAny(org.dreeam.leaf.util.BlockMasks.SPELEOTHEMS_TAG)) { // Gale - Pre-compute - Common BlockState predicates - Apply + FluidState fluidState = blockState.getFluidState(); + if (fluidState.is(FluidTags.LAVA)) { + return PathType.LAVA; + } + + if (isBurningBlock(blockState)) { + return PathType.FIRE; + } + + if (block instanceof DoorBlock door) { + if (blockState.getValue(DoorBlock.OPEN)) { + return PathType.DOOR_OPEN; + } else { + return door.type().canOpenByHand() ? PathType.DOOR_WOOD_CLOSED : PathType.DOOR_IRON_CLOSED; + } + } else { + if (block instanceof BaseRailBlock) { + return PathType.RAIL; + } + + if (block instanceof LeavesBlock) { + return PathType.LEAVES; + } + +- if (!blockState.is(BlockTags.FENCES) +- && !blockState.is(BlockTags.WALLS) ++ if (!blockState.isAny(org.dreeam.leaf.util.BlockMasks.FENCES_TAG) // Gale - Pre-compute - Common BlockState predicates - Apply ++ && !blockState.isAny(org.dreeam.leaf.util.BlockMasks.WALLS_TAG) // Gale - Pre-compute - Common BlockState predicates - Apply + && (!(block instanceof FenceGateBlock) || blockState.getValue(FenceGateBlock.OPEN))) { + if (!blockState.isPathfindable(PathComputationType.LAND)) { + return PathType.BLOCKED; + } else { + return fluidState.is(FluidTags.WATER) ? PathType.WATER : PathType.OPEN; + } + } else { + return PathType.FENCE; + } + } + } else { + return PathType.DAMAGE_CAUTIOUS; + } diff --git a/gale-server/src/main/java/org/dreeam/leaf/util/BlockMasks.java b/gale-server/src/main/java/org/dreeam/leaf/util/BlockMasks.java index 5dd18ba5..0b0f5c1f 100644 --- a/gale-server/src/main/java/org/dreeam/leaf/util/BlockMasks.java +++ b/gale-server/src/main/java/org/dreeam/leaf/util/BlockMasks.java @@ -76,6 +76,23 @@ public final class BlockMasks { */ public static final int BEDS_TAG = 0x80; + /** + * {@link BlockTags#FIRE}. + */ + public static final int FIRE_TAG = 0x1000; + + /** + * {@link BlockTags#TRAPDOORS}. + */ + public static final int TRAPDOORS_TAG = 0x2000; + + /** + * {@link BlockTags#SPELEOTHEMS}. + */ + public static final int SPELEOTHEMS_TAG = 0x4000; + + + /** * {@link #WALLS_TAG} or {@link #FENCE_GATE_CLASS}. */ @@ -101,6 +118,9 @@ public static int init(final BlockState state) { i |= state.is(BlockTags.DOORS) ? DOORS_TAG : 0; i |= state.is(BlockTags.ICE) ? ICE_TAG : 0; i |= state.is(BlockTags.BEDS) ? BEDS_TAG : 0; + i |= state.is(BlockTags.FIRE) ? FIRE_TAG : 0; + i |= state.is(BlockTags.TRAPDOORS) ? TRAPDOORS_TAG : 0; + i |= state.is(BlockTags.SPELEOTHEMS) ? SPELEOTHEMS_TAG : 0; i |= state.getBlock() instanceof PowderSnowBlock ? POWDER_SNOW_CLASS : 0; i |= state.getBlock() instanceof FenceGateBlock ? FENCE_GATE_CLASS : 0; i |= state.getBlock() instanceof TrapDoorBlock && state.getValue(TrapDoorBlock.OPEN) ? TRAP_DOOR_CLASS_AND_OPEN_PROPERTY_IS_TRUE : 0;