2020-06-16 16:46:05 +02:00
|
|
|
From ced57e7913ed54cc8b442742d119e7f22bca7e26 Mon Sep 17 00:00:00 2001
|
2020-05-12 01:17:43 +02:00
|
|
|
From: tr7zw <tr7zw@live.de>
|
|
|
|
Date: Tue, 12 May 2020 01:16:14 +0200
|
|
|
|
Subject: [PATCH] lithium MixinTypeFilterableList
|
|
|
|
|
|
|
|
---
|
|
|
|
.../net/minecraft/server/EntitySlice.java | 97 +++++++++++++++++++
|
|
|
|
1 file changed, 97 insertions(+)
|
|
|
|
create mode 100644 src/main/java/net/minecraft/server/EntitySlice.java
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntitySlice.java b/src/main/java/net/minecraft/server/EntitySlice.java
|
|
|
|
new file mode 100644
|
2020-06-16 16:46:05 +02:00
|
|
|
index 000000000..e61f53a15
|
2020-05-12 01:17:43 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntitySlice.java
|
|
|
|
@@ -0,0 +1,97 @@
|
|
|
|
+package net.minecraft.server;
|
|
|
|
+
|
|
|
|
+import java.util.AbstractCollection;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+import com.google.common.collect.Iterators;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
+
|
|
|
|
+public class EntitySlice<T> extends AbstractCollection<T> {
|
|
|
|
+ private final Map<Class<?>, List<T>> a = Maps.newHashMap();
|
|
|
|
+ private final Class<T> b;
|
|
|
|
+ private final List<T> c = Lists.newArrayList();
|
|
|
|
+
|
|
|
|
+ public EntitySlice(Class<T> var0) {
|
|
|
|
+ this.b = var0;
|
|
|
|
+ this.a.put(var0, this.c);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean add(T var0) {
|
|
|
|
+ boolean var1 = false;
|
|
|
|
+ for (Map.Entry<Class<?>, List<T>> var3 : this.a.entrySet()) {
|
|
|
|
+ if (!var3.getKey().isInstance(var0))
|
|
|
|
+ continue;
|
|
|
|
+ var1 |= var3.getValue().add(var0);
|
|
|
|
+ }
|
|
|
|
+ return var1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean remove(Object var0) {
|
|
|
|
+ boolean var1 = false;
|
|
|
|
+ for (Map.Entry<Class<?>, List<T>> var3 : this.a.entrySet()) {
|
|
|
|
+ if (!var3.getKey().isInstance(var0))
|
|
|
|
+ continue;
|
|
|
|
+ List<T> var4 = var3.getValue();
|
|
|
|
+ var1 |= var4.remove(var0);
|
|
|
|
+ }
|
|
|
|
+ return var1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean contains(Object var0) {
|
|
|
|
+ return this.a(var0.getClass()).contains(var0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @reason Only perform the slow Class#isAssignableFrom(Class) if a list doesn't exist for the type, otherwise
|
|
|
|
+ * we can assume it's already valid. The slow-path code is moved to a separate method to help the JVM inline this.
|
|
|
|
+ * @author JellySquid
|
|
|
|
+ */
|
|
|
|
+ public <S> Collection<S> a(Class<S> var02) {
|
|
|
|
+ Collection<T> collection = this.a.get(var02);
|
|
|
|
+
|
|
|
|
+ if(collection == null) {
|
|
|
|
+ collection = createCollection(var02);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return (Collection<S>) Collections.unmodifiableCollection(collection);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public <S> Collection<T> createCollection(Class<S> var02) {
|
|
|
|
+ if (!this.b.isAssignableFrom(var02)) {
|
|
|
|
+ throw new IllegalArgumentException("Don't know how to search for " + var02);
|
|
|
|
+ }
|
|
|
|
+ List<T> list = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (T allElement : this.c) {
|
|
|
|
+ if (var02.isInstance(allElement)) {
|
|
|
|
+ list.add(allElement);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.a.put(var02, list);
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Iterator<T> iterator() {
|
|
|
|
+ if (this.c.isEmpty()) {
|
|
|
|
+ return Collections.emptyIterator();
|
|
|
|
+ }
|
|
|
|
+ return Iterators.unmodifiableIterator(this.c.iterator());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int size() {
|
|
|
|
+ return this.c.size();
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
\ No newline at end of file
|
|
|
|
--
|
|
|
|
2.25.1.windows.1
|
|
|
|
|