mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-27 19:09:22 +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.
44 lines
2.1 KiB
Diff
44 lines
2.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: hayanesuru <hayanesuru@outlook.jp>
|
|
Date: Fri, 23 May 2025 15:57:42 +0900
|
|
Subject: [PATCH] optimize getEntityStatus
|
|
|
|
|
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java
|
|
index 2d24d03bbdb5ee0d862cbfff2219f58afffafe12..703bf9c2a56b262e2719a1787584de537b8f12e0 100644
|
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java
|
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java
|
|
@@ -93,8 +93,14 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
|
|
if (entity == null) {
|
|
return null;
|
|
}
|
|
- final Visibility visibility = EntityLookup.getEntityStatus(entity);
|
|
- return visibility.isAccessible() ? entity : null;
|
|
+ // Leaf start - optimize getEntityStatus
|
|
+ final FullChunkStatus entityStatus = ((ChunkSystemEntity) entity).moonrise$getChunkStatus();
|
|
+ return switch (entityStatus) {
|
|
+ case INACCESSIBLE -> null;
|
|
+ case FULL, BLOCK_TICKING, ENTITY_TICKING -> entity;
|
|
+ case null -> null;
|
|
+ };
|
|
+ // Leaf end - optimize getEntityStatus
|
|
}
|
|
|
|
@Override
|
|
@@ -398,7 +404,14 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
|
|
return Visibility.TICKING;
|
|
}
|
|
final FullChunkStatus entityStatus = ((ChunkSystemEntity)entity).moonrise$getChunkStatus();
|
|
- return Visibility.fromFullChunkStatus(entityStatus == null ? FullChunkStatus.INACCESSIBLE : entityStatus);
|
|
+ // Leaf start - optimize getEntityStatus
|
|
+ return switch (entityStatus) {
|
|
+ case INACCESSIBLE -> Visibility.HIDDEN;
|
|
+ case FULL, BLOCK_TICKING -> Visibility.TRACKED;
|
|
+ case ENTITY_TICKING -> Visibility.TICKING;
|
|
+ case null -> Visibility.HIDDEN;
|
|
+ };
|
|
+ // Leaf end - optimize getEntityStatus
|
|
}
|
|
|
|
protected boolean addEntity(final Entity entity, final boolean fromDisk, final boolean event) {
|