mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-29 20:09:17 +00:00
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2 since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList. Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2 lazy handles filter condition on iteration, so much better.
64 lines
2.9 KiB
Diff
64 lines
2.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Sat, 8 Feb 2025 05:32:30 +0100
|
|
Subject: [PATCH] Cache supporting block check
|
|
|
|
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 4e914104b02355fb854b0f4946671429264e1e1d..1d75ea57923f891a07b0c29e065ad46cdfac9b91 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -1104,12 +1104,36 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return this.mainSupportingBlockPos.isPresent() && this.mainSupportingBlockPos.get().equals(pos);
|
|
}
|
|
|
|
+ // Leaf start - Cache supporting block check
|
|
+ private boolean canSkipSupportingBlockSearch = false;
|
|
+ private BlockState cachedSupportingBlockState = null;
|
|
+ // Leaf end - Cache supporting block check
|
|
+
|
|
protected void checkSupportingBlock(boolean onGround, @Nullable Vec3 movement) {
|
|
+ // Leaf start - Cache supporting block check
|
|
+ // Skip full check if no movement and cache is valid
|
|
+ if (movement == null || (movement.x == 0 && movement.z == 0 && movement.y == 0)) {
|
|
+ if (canSkipSupportingBlockSearch) {
|
|
+ return;
|
|
+ }
|
|
+ } else {
|
|
+ // Invalidate cache on movement
|
|
+ canSkipSupportingBlockSearch = false;
|
|
+ cachedSupportingBlockState = null;
|
|
+ }
|
|
+ // Leaf end - Cache supporting block check
|
|
if (onGround) {
|
|
AABB boundingBox = this.getBoundingBox();
|
|
AABB aabb = new AABB(boundingBox.minX, boundingBox.minY - 1.0E-6, boundingBox.minZ, boundingBox.maxX, boundingBox.minY, boundingBox.maxZ);
|
|
Optional<BlockPos> optional = this.level.findSupportingBlock(this, aabb);
|
|
if (optional.isPresent() || this.onGroundNoBlocks) {
|
|
+ // Leaf start - Cache supporting block check
|
|
+ if (optional.isPresent()) { // Cache the block state if found
|
|
+ BlockPos pos = optional.get();
|
|
+ cachedSupportingBlockState = this.level.getBlockState(pos);
|
|
+ canSkipSupportingBlockSearch = true;
|
|
+ }
|
|
+ // Leaf end - Cache supporting block check
|
|
this.mainSupportingBlockPos = optional;
|
|
} else if (movement != null) {
|
|
AABB aabb1 = aabb.move(-movement.x, 0.0, -movement.z);
|
|
@@ -1126,6 +1150,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
}
|
|
|
|
+
|
|
+ // Leaf start - Cache supporting block check
|
|
+ // Helper method to get cached supporting block state
|
|
+ @Nullable
|
|
+ public BlockState getCachedSupportingBlock() {
|
|
+ return canSkipSupportingBlockSearch ? cachedSupportingBlockState : null;
|
|
+ }
|
|
+ // Leaf end - Cache supporting block check
|
|
+
|
|
public boolean onGround() {
|
|
return this.onGround;
|
|
}
|