From 76d8a3a0295c100a7f8c798aaf18083e53b605cd Mon Sep 17 00:00:00 2001 From: Ivan Pekov Date: Thu, 29 Oct 2020 15:33:46 +0200 Subject: [PATCH] Update some stuff in EntitySlice --- ...0035-lithium-collision-optimizations.patch | 60 ++++++++++++------- .../0043-Fix-Unable-to-save-chunk-error.patch | 4 +- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/patches/server/0035-lithium-collision-optimizations.patch b/patches/server/0035-lithium-collision-optimizations.patch index 821b60b4..48c9b99c 100644 --- a/patches/server/0035-lithium-collision-optimizations.patch +++ b/patches/server/0035-lithium-collision-optimizations.patch @@ -880,7 +880,7 @@ index e0381ed6945f734f8802d07b8cbd6b27852db449..220d5273543ea0b143cf9c894c89cabe // Paper end diff --git a/src/main/java/net/minecraft/server/EntitySlice.java b/src/main/java/net/minecraft/server/EntitySlice.java -index 1250c3cbe915815939627701c153ba6254fc05f0..06a51ca13d484dd319aa96364b2f1b533b184c36 100644 +index 1250c3cbe915815939627701c153ba6254fc05f0..cdf54580a8275f40730f9cbdc1c0c4b4a3999a90 100644 --- a/src/main/java/net/minecraft/server/EntitySlice.java +++ b/src/main/java/net/minecraft/server/EntitySlice.java @@ -14,18 +14,35 @@ import java.util.Map.Entry; @@ -889,8 +889,8 @@ index 1250c3cbe915815939627701c153ba6254fc05f0..06a51ca13d484dd319aa96364b2f1b53 -public class EntitySlice extends AbstractCollection { +// Yatopia start -+import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; +import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet; ++import it.unimi.dsi.fastutil.objects.Reference2ReferenceArrayMap; +import me.jellysquid.mods.lithium.common.entity.EntityClassGroup; +// Yatopia end + @@ -901,12 +901,12 @@ index 1250c3cbe915815939627701c153ba6254fc05f0..06a51ca13d484dd319aa96364b2f1b53 - private final List c = Lists.newArrayList(); + private final List c = new net.yatopia.server.list.GlueList<>(); // Yatopia + -+ private Reference2ReferenceOpenHashMap> entitiesByGroup; // Yatopia ++ private final Reference2ReferenceArrayMap> entitiesByGroup; // Yatopia public EntitySlice(Class oclass) { this.b = oclass; this.a.put(oclass, this.c); -+ this.entitiesByGroup = new Reference2ReferenceOpenHashMap<>(); // Yatopia ++ this.entitiesByGroup = new Reference2ReferenceArrayMap<>(); // Yatopia } public boolean add(T t0) { @@ -933,29 +933,47 @@ index 1250c3cbe915815939627701c153ba6254fc05f0..06a51ca13d484dd319aa96364b2f1b53 boolean flag = false; Iterator iterator = this.a.entrySet().iterator(); -@@ -65,11 +87,16 @@ public class EntitySlice extends AbstractCollection { +@@ -61,10 +83,13 @@ public class EntitySlice extends AbstractCollection { + return this.a(object.getClass()).contains(object); + } + ++ @SuppressWarnings("unchecked") // Yatopia + public Collection a(Class oclass) { if (!this.b.isAssignableFrom(oclass)) { throw new IllegalArgumentException("Don't know how to search for " + oclass); } else { -- List list = (List) this.a.computeIfAbsent(oclass, (oclass1) -> { -- Stream stream = this.c.stream(); -- -- oclass1.getClass(); -- return (List) stream.filter(oclass1::isInstance).collect(Collectors.toList()); -+ List list = (List) this.a.computeIfAbsent(oclass, (oclass1) -> { // Yatopia - decompile fix -+ // Yatopia start - how about we nuke stream? -+ List ret = new net.yatopia.server.list.GlueList<>(); -+ for (T t : c) { -+ if (oclass1.isInstance(t)) { -+ ret.add(t); -+ } -+ } -+ return ret; -+ // Yatopia end ++ // Yatopia start - replace this ++ /* + List list = (List) this.a.computeIfAbsent(oclass, (oclass1) -> { + Stream stream = this.c.stream(); + +@@ -73,6 +98,18 @@ public class EntitySlice extends AbstractCollection { }); return Collections.unmodifiableCollection(list); -@@ -87,4 +114,38 @@ public class EntitySlice extends AbstractCollection { ++ */ ++ if (a.containsKey(oclass)) { ++ return (Collection) Collections.unmodifiableCollection(a.get(oclass)); ++ } ++ List list = new net.yatopia.server.list.GlueList<>(); ++ for (T allElement : this.c) { ++ if (oclass.isInstance(allElement)) { ++ list.add(allElement); ++ } ++ } ++ a.put(oclass, list); ++ return (Collection) Collections.unmodifiableCollection(list); + } + } + +@@ -81,10 +118,44 @@ public class EntitySlice extends AbstractCollection { + } + + public List a() { +- return ImmutableList.copyOf(this.c); ++ return Collections.unmodifiableList(this.c); // Yatopia - avoid copying + } + public int size() { return this.c.size(); } diff --git a/patches/server/0043-Fix-Unable-to-save-chunk-error.patch b/patches/server/0043-Fix-Unable-to-save-chunk-error.patch index c1476023..34a3d8da 100644 --- a/patches/server/0043-Fix-Unable-to-save-chunk-error.patch +++ b/patches/server/0043-Fix-Unable-to-save-chunk-error.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Fix "Unable to save chunk" error diff --git a/src/main/java/net/minecraft/server/EntitySlice.java b/src/main/java/net/minecraft/server/EntitySlice.java -index 06a51ca13d484dd319aa96364b2f1b533b184c36..70bfc97601059ab585f20e62163e59a8a31dc48e 100644 +index cdf54580a8275f40730f9cbdc1c0c4b4a3999a90..cf4da23e790af36e450fb1ffee9cab84b1c5f508 100644 --- a/src/main/java/net/minecraft/server/EntitySlice.java +++ b/src/main/java/net/minecraft/server/EntitySlice.java -@@ -104,7 +104,7 @@ public class EntitySlice extends AbstractCollection implements me.jellysqu +@@ -114,7 +114,7 @@ public class EntitySlice extends AbstractCollection implements me.jellysqu } public Iterator iterator() {