9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-28 03:19:21 +00:00

Cache block state tags (#451)

* Cache block state tags

* [ci/skip] Fix comment
This commit is contained in:
hayanesuru
2025-08-09 05:37:39 +09:00
committed by GitHub
parent 1ea7c5fe56
commit c92396f324
2 changed files with 61 additions and 25 deletions

View File

@@ -1,23 +1,23 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
Date: Fri, 23 May 2025 12:01:42 +0900
Subject: [PATCH] Cache block path type
Subject: [PATCH] Cache block state tags
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 168fc4fea371dfe9ea1ffca3c9f290ba3547f0b9..463a9d9b15301e7139bd36435214662aa3ccf63d 100644
index 168fc4fea371dfe9ea1ffca3c9f290ba3547f0b9..eb1bff376d0a54c6838ca25323571c80534cb0ed 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -366,6 +366,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
}
if (org.dreeam.leaf.config.modules.async.AsyncMobSpawning.enabled) mobSpawnExecutor.start(); // Pufferfish
+ net.minecraft.world.level.block.Blocks.initPathType(); // Leaf - Cache path type
+ net.minecraft.world.level.block.Blocks.initPathType(); // Leaf - Cache block state tags
org.purpurmc.purpur.task.BossBarTask.startAll(); // Purpur - Implement TPSBar
if (org.purpurmc.purpur.PurpurConfig.beeCountPayload) org.purpurmc.purpur.task.BeehiveTask.instance().register(); // Purpur - Give bee counts in beehives to Purpur clients
diff --git a/net/minecraft/world/level/block/Blocks.java b/net/minecraft/world/level/block/Blocks.java
index 57aad048034005543a72556e990b53db8deebfee..6e6ee6f25f7cab0a6235d9e583ed5c01bca30edd 100644
index 57aad048034005543a72556e990b53db8deebfee..b7aa32927e701184d53a03e009f88e9cf6313aab 100644
--- a/net/minecraft/world/level/block/Blocks.java
+++ b/net/minecraft/world/level/block/Blocks.java
@@ -7066,4 +7066,14 @@ public class Blocks {
@@ -25,7 +25,7 @@ index 57aad048034005543a72556e990b53db8deebfee..6e6ee6f25f7cab0a6235d9e583ed5c01
}
}
+
+ // Leaf start - Cache path type
+ // Leaf start - Cache block state tags
+ public static void initPathType() {
+ for (Block block : BuiltInRegistries.BLOCK) {
+ for (BlockState blockState : block.getStateDefinition().getPossibleStates()) {
@@ -33,35 +33,37 @@ index 57aad048034005543a72556e990b53db8deebfee..6e6ee6f25f7cab0a6235d9e583ed5c01
+ }
+ }
+ }
+ // Leaf end - Cache path type
+ // Leaf end - Cache block state tags
}
diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java
index 6d522e9485fadd6fc0f350cb30ba5224aa046d4f..611887f5f8f218f5ec1ad19580f3123a60b20d46 100644
index 6d522e9485fadd6fc0f350cb30ba5224aa046d4f..9caac78f0dbadc838753e2db7b757b70cea2fae8 100644
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -473,6 +473,7 @@ public abstract class BlockBehaviour implements FeatureElement {
@@ -473,6 +473,8 @@ public abstract class BlockBehaviour implements FeatureElement {
private boolean emptyCollisionShape;
private boolean emptyConstantCollisionShape;
private VoxelShape constantCollisionShape;
+ public net.minecraft.world.level.pathfinder.PathType pathType; // Leaf - Cache path type
+ public byte pathType; // Leaf - Cache block state tags
+ public int tagFlag; // Leaf - Cache block state tags
private static void initCaches(final VoxelShape shape, final boolean neighbours) {
((ca.spottedleaf.moonrise.patches.collisions.shape.CollisionVoxelShape)shape).moonrise$isFullBlock();
@@ -642,6 +643,12 @@ public abstract class BlockBehaviour implements FeatureElement {
@@ -642,6 +644,13 @@ public abstract class BlockBehaviour implements FeatureElement {
// Paper end - optimise collisions
}
+ // Leaf start - Cache path type
+ // Leaf start - Cache block state tags
+ public void initPathType() {
+ pathType = net.minecraft.world.level.pathfinder.WalkNodeEvaluator.getPathTypeFromState(this.asState());
+ pathType = (byte) net.minecraft.world.level.pathfinder.WalkNodeEvaluator.getPathTypeFromState(this.asState()).ordinal();
+ tagFlag = org.dreeam.leaf.util.BlockMasks.init(asState());
+ }
+ // Leaf end - Cache path type
+ // Leaf end - Cache block state tags
+
public Block getBlock() {
return this.owner;
}
diff --git a/net/minecraft/world/level/pathfinder/PathTypeCache.java b/net/minecraft/world/level/pathfinder/PathTypeCache.java
index 3b190ba2a719cc45045d9be893884b50b9364b58..b44f6562a7f7651b2728ba49699031000b54b818 100644
index 3b190ba2a719cc45045d9be893884b50b9364b58..a64fde6253de1f603d36cd6ef94b9c1da47ba758 100644
--- a/net/minecraft/world/level/pathfinder/PathTypeCache.java
+++ b/net/minecraft/world/level/pathfinder/PathTypeCache.java
@@ -24,7 +24,7 @@ public class PathTypeCache {
@@ -69,12 +71,12 @@ index 3b190ba2a719cc45045d9be893884b50b9364b58..b44f6562a7f7651b2728ba4969903100
private PathType compute(BlockGetter level, BlockPos pos, int index, long packedPos) {
- PathType pathTypeFromState = WalkNodeEvaluator.getPathTypeFromState(level, pos);
+ PathType pathTypeFromState = WalkNodeEvaluator.leafPathType(level, pos); // Leaf - Cache path type
+ PathType pathTypeFromState = WalkNodeEvaluator.leafPathType(level, pos); // Leaf - Cache block state tags
this.positions[index] = packedPos;
this.pathTypes[index] = pathTypeFromState;
return pathTypeFromState;
diff --git a/net/minecraft/world/level/pathfinder/PathfindingContext.java b/net/minecraft/world/level/pathfinder/PathfindingContext.java
index 4eca1dd0819c7ee7a77e45fc5fa03f4ee5cdceaf..ff68b19b5fe4c80872d483363611b843146de989 100644
index 4eca1dd0819c7ee7a77e45fc5fa03f4ee5cdceaf..7f8b00fd7ca7fb692244d293d20f06c30bf188cc 100644
--- a/net/minecraft/world/level/pathfinder/PathfindingContext.java
+++ b/net/minecraft/world/level/pathfinder/PathfindingContext.java
@@ -27,7 +27,7 @@ public class PathfindingContext {
@@ -82,41 +84,42 @@ index 4eca1dd0819c7ee7a77e45fc5fa03f4ee5cdceaf..ff68b19b5fe4c80872d483363611b843
public PathType getPathTypeFromState(int x, int y, int z) {
BlockPos blockPos = this.mutablePos.set(x, y, z);
- return this.cache == null ? WalkNodeEvaluator.getPathTypeFromState(this.level, blockPos) : this.cache.getOrCompute(this.level, blockPos);
+ return this.cache == null ? WalkNodeEvaluator.leafPathType(this.level, blockPos) : this.cache.getOrCompute(this.level, blockPos); // Leaf - Cache path type
+ return this.cache == null ? WalkNodeEvaluator.leafPathType(this.level, blockPos) : this.cache.getOrCompute(this.level, blockPos); // Leaf - Cache block state tags
}
public BlockState getBlockState(BlockPos pos) {
diff --git a/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java b/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java
index db6baaa698fe93aba3fbd595158b568badd6cb8a..5bd1300ef82a1d431c098d9cf75a7fa9d5a43502 100644
index db6baaa698fe93aba3fbd595158b568badd6cb8a..7eb7a8a4b4c000d543d2a6bc181421493164df34 100644
--- a/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java
+++ b/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java
@@ -479,6 +479,16 @@ public class WalkNodeEvaluator extends NodeEvaluator {
@@ -479,6 +479,17 @@ public class WalkNodeEvaluator extends NodeEvaluator {
return pathType;
}
+ // Leaf start - Cache path type
+ // Leaf start - Cache block state tags
+ private static final PathType[] PATH_TYPES = PathType.values();
+ public static PathType leafPathType(BlockGetter level, BlockPos blockPos) {
+ BlockState blockState = level.getBlockStateIfLoaded(blockPos);
+ if (blockState == null) {
+ return PathType.BLOCKED;
+ }
+ return blockState.pathType;
+ return PATH_TYPES[blockState.pathType];
+ }
+ // Leaf end - Cache path type
+ // Leaf end - Cache block state tags
+
protected static PathType getPathTypeFromState(BlockGetter level, BlockPos pos) {
// Paper start - Do not load chunks during pathfinding
BlockState blockState = level.getBlockStateIfLoaded(pos);
@@ -486,6 +496,12 @@ public class WalkNodeEvaluator extends NodeEvaluator {
@@ -486,6 +497,12 @@ public class WalkNodeEvaluator extends NodeEvaluator {
return PathType.BLOCKED;
}
// Paper end
+ // Leaf start - Cache path type
+ // Leaf start - Cache block state tags
+ return getPathTypeFromState(blockState);
+ }
+
+ public static PathType getPathTypeFromState(BlockState blockState) {
+ // Leaf end - Cache path type
+ // Leaf end - Cache block state tags
Block block = blockState.getBlock();
if (blockState.isAir()) {
return PathType.OPEN;

View File

@@ -0,0 +1,33 @@
package org.dreeam.leaf.util;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.block.FenceGateBlock;
import net.minecraft.world.level.block.PowderSnowBlock;
import net.minecraft.world.level.block.TrapDoorBlock;
import net.minecraft.world.level.block.state.BlockState;
public final class BlockMasks {
public static final int WALL_TAG = 0x01;
public static final int FENCE_TAG = 0x02;
public static final int CLIMBABLE_TAG = 0x04;
public static final int POWDER_SNOW_CL = 0x08;
public static final int FENCE_GATE_CL = 0x10;
public static final int TRAP_DOOR_CL = 0x20;
public static final int WATER = 0x40;
public static final int LAVA = 0x80;
public static final int FLUID = (WATER | LAVA);
public static int init(final BlockState state) {
int i = 0;
i |= state.is(BlockTags.WALLS) ? WALL_TAG : 0;
i |= state.is(BlockTags.FENCES) ? FENCE_TAG : 0;
i |= state.is(BlockTags.CLIMBABLE) ? CLIMBABLE_TAG : 0;
i |= state.getBlock() instanceof PowderSnowBlock ? POWDER_SNOW_CL : 0;
i |= state.getBlock() instanceof FenceGateBlock ? FENCE_GATE_CL : 0;
i |= state.getBlock() instanceof TrapDoorBlock ? TRAP_DOOR_CL : 0;
i |= state.getFluidState().is(FluidTags.WATER) ? WATER : 0;
i |= state.getFluidState().is(FluidTags.LAVA) ? LAVA : 0;
return i;
}
}