9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

Optimize canHoldAnyFluid in canMaybePassThrough (#527)

* optimize canHoldAnyFluid in canMaybePassThrough

* rebuild patches

* support reload
This commit is contained in:
hayanesuru
2025-10-13 03:26:33 +09:00
committed by GitHub
parent 2777740511
commit 043cb215fd
122 changed files with 50 additions and 85 deletions

View File

@@ -1,65 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Tue, 26 Nov 2024 17:15:38 -0500
Subject: [PATCH] Cache part of canHoldFluid result
Cache the result of part of canHoldFluid logic, since there are many state#is in canAnyHoldFluid method,
it uses map contains to do iteration to check whether a block has a specific block tag key,
which the contains iteration call is very expensive if called everytime
In the test, it can improve ~30% performance in ~1577000 times of canHoldAnyFluid calls (~159ms -> ~111ms)
diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java
index 84f4d772bfe06383ca718b6a00d983e97e2e35f4..3219b9caa654c7a64e5e4a92178528e1104b34c7 100644
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -451,6 +451,8 @@ public abstract class BlockBehaviour implements FeatureElement {
private VoxelShape[] occlusionShapesByFace;
private boolean propagatesSkylightDown;
private int lightBlock;
+ private boolean canHoldAnyFluidInternal; // Leaf - Cache part of canHoldFluid result
+ private boolean canHoldAnyFluidInternalInit; // Leaf - Cache part of canHoldFluid result
// Paper start - rewrite chunk system
private boolean isConditionallyFullOpaque;
@@ -600,6 +602,8 @@ public abstract class BlockBehaviour implements FeatureElement {
this.propagatesSkylightDown = this.owner.propagatesSkylightDown(this.asState());
this.lightBlock = this.owner.getLightBlock(this.asState());
+ this.canHoldAnyFluidInternal = false; // Leaf - Cache part of canHoldFluid result
+ this.canHoldAnyFluidInternalInit = false; // Leaf - Cache part of canHoldFluid result
// Paper start - rewrite chunk system
this.isConditionallyFullOpaque = this.canOcclude & this.useShapeForLightOcclusion;
// Paper end - rewrite chunk system
@@ -651,6 +655,18 @@ public abstract class BlockBehaviour implements FeatureElement {
return block != Blocks.COBWEB && block != Blocks.BAMBOO_SAPLING && this.isSolid();
}
+ // Leaf start - Cache part of canHoldFluid result
+ public boolean canHoldAnyFluidInternal() {
+ // Lazy load cache
+ if (!canHoldAnyFluidInternalInit) {
+ canHoldAnyFluidInternal = net.minecraft.world.level.material.FlowingFluid.canHoldAnyFluid(this.asState());
+ canHoldAnyFluidInternalInit = true;
+ }
+
+ return canHoldAnyFluidInternal;
+ }
+ // Leaf end - Cache part of canHoldFluid result
+
@Deprecated
public boolean isSolid() {
return this.legacySolid;
diff --git a/net/minecraft/world/level/material/FlowingFluid.java b/net/minecraft/world/level/material/FlowingFluid.java
index c4675d51bd459fcdc411b48115d512f77a232cef..4fe1b3fc6304a2a404fd0f62f52fc792bcd5dfaf 100644
--- a/net/minecraft/world/level/material/FlowingFluid.java
+++ b/net/minecraft/world/level/material/FlowingFluid.java
@@ -467,7 +467,7 @@ public abstract class FlowingFluid extends Fluid {
}
private static boolean canHoldFluid(BlockGetter level, BlockPos pos, BlockState state, Fluid fluid) {
- return canHoldAnyFluid(state) && canHoldSpecificFluid(level, pos, state, fluid);
+ return /*canHoldAnyFluid(state)*/ state.canHoldAnyFluidInternal() && canHoldSpecificFluid(level, pos, state, fluid); // Leaf - Cache part of canHoldFluid result
}
private static boolean canHoldSpecificFluid(BlockGetter level, BlockPos pos, BlockState state, Fluid fluid) {

View File

@@ -24,7 +24,7 @@ index 2352406b0284ddcfb755618837f641b059437a19..284e2332ca6c0af178169f2ab9acae3c
BlockState blockState = this.getBlockState(pos); BlockState blockState = this.getBlockState(pos);
FluidState fluidState = blockState.getFluidState(); FluidState fluidState = blockState.getFluidState();
diff --git a/net/minecraft/world/level/material/FlowingFluid.java b/net/minecraft/world/level/material/FlowingFluid.java diff --git a/net/minecraft/world/level/material/FlowingFluid.java b/net/minecraft/world/level/material/FlowingFluid.java
index 4fe1b3fc6304a2a404fd0f62f52fc792bcd5dfaf..bcda72fbd920a087ea7d10171da933b13adc1813 100644 index c4675d51bd459fcdc411b48115d512f77a232cef..a9c7966371f184ec2a23275496a5cfd7774dffae 100644
--- a/net/minecraft/world/level/material/FlowingFluid.java --- a/net/minecraft/world/level/material/FlowingFluid.java
+++ b/net/minecraft/world/level/material/FlowingFluid.java +++ b/net/minecraft/world/level/material/FlowingFluid.java
@@ -342,32 +342,124 @@ public abstract class FlowingFluid extends Fluid { @@ -342,32 +342,124 @@ public abstract class FlowingFluid extends Fluid {

View File

@@ -33,7 +33,7 @@ index 386e6a48701b4c9256e33174123381a93d61e292..2bc620ceb8368e9a74b831de698de94a
@Deprecated @Deprecated
diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java
index 3219b9caa654c7a64e5e4a92178528e1104b34c7..6d522e9485fadd6fc0f350cb30ba5224aa046d4f 100644 index 84f4d772bfe06383ca718b6a00d983e97e2e35f4..f9ff9a3a9633185c66503012eeb661a6e04fe1df 100644
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java --- a/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java +++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -101,6 +101,7 @@ public abstract class BlockBehaviour implements FeatureElement { @@ -101,6 +101,7 @@ public abstract class BlockBehaviour implements FeatureElement {

View File

@@ -4,18 +4,17 @@ Date: Fri, 23 May 2025 12:01:42 +0900
Subject: [PATCH] Cache block state tags Subject: [PATCH] Cache block state tags
diff --git a/net/minecraft/server/Main.java b/net/minecraft/server/Main.java diff --git a/net/minecraft/server/ReloadableServerResources.java b/net/minecraft/server/ReloadableServerResources.java
index 284947437eacf1d527b613d883c40bb3eb5faa90..5c96307c7cdbd80164ad8759c321c66c4b63ac9e 100644 index 42326fc40b834c944e714fec91811d5c39dbe40c..a69819ae974f41fb766f25b9138ed7e74cad36dd 100644
--- a/net/minecraft/server/Main.java --- a/net/minecraft/server/ReloadableServerResources.java
+++ b/net/minecraft/server/Main.java +++ b/net/minecraft/server/ReloadableServerResources.java
@@ -336,6 +336,7 @@ public class Main { @@ -109,5 +109,6 @@ public class ReloadableServerResources {
levelStorageAccess.saveDataTag(frozen, worldData);
*/ public void updateStaticRegistryTags() {
Class.forName(net.minecraft.world.entity.npc.VillagerTrades.class.getName()); // Paper - load this sync so it won't fail later async this.postponedTags.forEach(Registry.PendingTags::apply);
+ net.minecraft.world.level.block.Blocks.initPathType(); // Leaf - Cache block state tags + net.minecraft.world.level.block.Blocks.initPathType(); // Leaf - Cache block state tags
final DedicatedServer dedicatedServer = MinecraftServer.spin( }
thread1 -> { }
DedicatedServer dedicatedServer1 = new DedicatedServer(
diff --git a/net/minecraft/world/level/block/Blocks.java b/net/minecraft/world/level/block/Blocks.java diff --git a/net/minecraft/world/level/block/Blocks.java b/net/minecraft/world/level/block/Blocks.java
index 57aad048034005543a72556e990b53db8deebfee..b7aa32927e701184d53a03e009f88e9cf6313aab 100644 index 57aad048034005543a72556e990b53db8deebfee..b7aa32927e701184d53a03e009f88e9cf6313aab 100644
--- a/net/minecraft/world/level/block/Blocks.java --- a/net/minecraft/world/level/block/Blocks.java
@@ -36,10 +35,10 @@ index 57aad048034005543a72556e990b53db8deebfee..b7aa32927e701184d53a03e009f88e9c
+ // Leaf end - Cache block state tags + // 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 diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java
index 6d522e9485fadd6fc0f350cb30ba5224aa046d4f..9caac78f0dbadc838753e2db7b757b70cea2fae8 100644 index f9ff9a3a9633185c66503012eeb661a6e04fe1df..503420bbeaf3da0c568c28c55582f45469f40aeb 100644
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java --- a/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java +++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -473,6 +473,8 @@ public abstract class BlockBehaviour implements FeatureElement { @@ -471,6 +471,8 @@ public abstract class BlockBehaviour implements FeatureElement {
private boolean emptyCollisionShape; private boolean emptyCollisionShape;
private boolean emptyConstantCollisionShape; private boolean emptyConstantCollisionShape;
private VoxelShape constantCollisionShape; private VoxelShape constantCollisionShape;
@@ -48,7 +47,7 @@ index 6d522e9485fadd6fc0f350cb30ba5224aa046d4f..9caac78f0dbadc838753e2db7b757b70
private static void initCaches(final VoxelShape shape, final boolean neighbours) { private static void initCaches(final VoxelShape shape, final boolean neighbours) {
((ca.spottedleaf.moonrise.patches.collisions.shape.CollisionVoxelShape)shape).moonrise$isFullBlock(); ((ca.spottedleaf.moonrise.patches.collisions.shape.CollisionVoxelShape)shape).moonrise$isFullBlock();
@@ -642,6 +644,13 @@ public abstract class BlockBehaviour implements FeatureElement { @@ -638,6 +640,13 @@ public abstract class BlockBehaviour implements FeatureElement {
// Paper end - optimise collisions // Paper end - optimise collisions
} }

Some files were not shown because too many files have changed in this diff Show More