mirror of
https://github.com/YatopiaMC/Yatopia.git
synced 2024-08-24 23:03:00 +02:00
212 lines
5.5 KiB
Diff
212 lines
5.5 KiB
Diff
From 25534c1f9b7f6fc7d0394851f278a520d738ad11 Mon Sep 17 00:00:00 2001
|
|
From: tr7zw <tr7zw@live.de>
|
|
Date: Tue, 12 May 2020 00:38:31 +0200
|
|
Subject: [PATCH] lithium MixinBiome
|
|
|
|
---
|
|
.../common/util/collections/HashedList.java | 168 ++++++++++++++++++
|
|
.../java/net/minecraft/server/BiomeBase.java | 4 +-
|
|
2 files changed, 171 insertions(+), 1 deletion(-)
|
|
create mode 100644 src/main/java/me/jellysquid/mods/lithium/common/util/collections/HashedList.java
|
|
|
|
diff --git a/src/main/java/me/jellysquid/mods/lithium/common/util/collections/HashedList.java b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/HashedList.java
|
|
new file mode 100644
|
|
index 000000000..a2e3e96e1
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/HashedList.java
|
|
@@ -0,0 +1,168 @@
|
|
+package me.jellysquid.mods.lithium.common.util.collections;
|
|
+
|
|
+import it.unimi.dsi.fastutil.objects.ObjectArraySet;
|
|
+
|
|
+import java.util.*;
|
|
+
|
|
+/**
|
|
+ * Wraps a {@link List} with a hash table which provides O(1) lookups for {@link Collection#contains(Object)}.
|
|
+ *
|
|
+ * @see https://github.com/jellysquid3/lithium-fabric/blob/1.16.x/fabric/src/main/java/me/jellysquid/mods/lithium/common/util/collections/HashedList.java
|
|
+ */
|
|
+public class HashedList<T> implements List<T> {
|
|
+ private final List<T> list;
|
|
+ private final Set<T> set;
|
|
+
|
|
+ private HashedList(List<T> list, Set<T> set) {
|
|
+ this.list = list;
|
|
+ this.set = set;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int size() {
|
|
+ return this.list.size();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isEmpty() {
|
|
+ return this.list.isEmpty();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean contains(Object o) {
|
|
+ return this.set.contains(o);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Iterator<T> iterator() {
|
|
+ return this.list.iterator();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Object[] toArray() {
|
|
+ return this.list.toArray();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public <T1> T1[] toArray(T1[] a) {
|
|
+ return this.list.toArray(a);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean add(T t) {
|
|
+ this.set.add(t);
|
|
+
|
|
+ return this.list.add(t);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean remove(Object o) {
|
|
+ this.set.remove(o);
|
|
+
|
|
+ return this.list.remove(o);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean containsAll(Collection<?> c) {
|
|
+ return this.set.containsAll(c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean addAll(Collection<? extends T> c) {
|
|
+ this.set.addAll(c);
|
|
+
|
|
+ return this.list.addAll(c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean addAll(int index, Collection<? extends T> c) {
|
|
+ this.set.addAll(c);
|
|
+
|
|
+ return this.list.addAll(index, c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean removeAll(Collection<?> c) {
|
|
+ this.set.removeAll(c);
|
|
+
|
|
+ return this.list.removeAll(c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean retainAll(Collection<?> c) {
|
|
+ this.set.retainAll(c);
|
|
+
|
|
+ return this.list.retainAll(c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void clear() {
|
|
+ this.set.clear();
|
|
+ this.list.clear();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public T get(int index) {
|
|
+ return this.list.get(index);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public T set(int index, T element) {
|
|
+ T prev = this.list.set(index, element);
|
|
+
|
|
+ if (prev != null) {
|
|
+ this.set.remove(prev);
|
|
+ }
|
|
+
|
|
+ this.set.add(element);
|
|
+
|
|
+ return prev;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void add(int index, T element) {
|
|
+ this.set.add(element);
|
|
+
|
|
+ this.list.add(index, element);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public T remove(int index) {
|
|
+ T prev = this.list.remove(index);
|
|
+
|
|
+ if (prev != null) {
|
|
+ this.set.remove(prev);
|
|
+ }
|
|
+
|
|
+ return prev;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int indexOf(Object o) {
|
|
+ return this.list.indexOf(o);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int lastIndexOf(Object o) {
|
|
+ return this.list.lastIndexOf(o);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ListIterator<T> listIterator() {
|
|
+ return this.list.listIterator();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ListIterator<T> listIterator(int index) {
|
|
+ return this.list.listIterator(index);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<T> subList(int fromIndex, int toIndex) {
|
|
+ return this.list.subList(fromIndex, toIndex);
|
|
+ }
|
|
+
|
|
+ public static <T> HashedList<T> wrapper(List<T> list) {
|
|
+ return new HashedList<>(list, new ObjectArraySet<>(list));
|
|
+ }
|
|
+}
|
|
\ No newline at end of file
|
|
diff --git a/src/main/java/net/minecraft/server/BiomeBase.java b/src/main/java/net/minecraft/server/BiomeBase.java
|
|
index 798d84795..897e56f0c 100644
|
|
--- a/src/main/java/net/minecraft/server/BiomeBase.java
|
|
+++ b/src/main/java/net/minecraft/server/BiomeBase.java
|
|
@@ -7,6 +7,8 @@ import com.google.common.collect.Sets;
|
|
import com.mojang.serialization.Codec;
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
import it.unimi.dsi.fastutil.longs.Long2FloatLinkedOpenHashMap;
|
|
+import me.jellysquid.mods.lithium.common.util.collections.HashedList;
|
|
+
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.Comparator;
|
|
@@ -139,7 +141,7 @@ public class BiomeBase {
|
|
for (j = 0; j < i; ++j) {
|
|
EnumCreatureType enumcreaturetype = aenumcreaturetype[j];
|
|
|
|
- this.v.put(enumcreaturetype, new MobList()); // Paper
|
|
+ this.v.put(enumcreaturetype, HashedList.wrapper(new MobList())); // Paper // YAPFA lithium change
|
|
}
|
|
|
|
} else {
|
|
--
|
|
2.25.1.windows.1
|
|
|