Yatopia/patches/server/0017-lithium-MixinBiome.patch

308 lines
8.5 KiB
Diff
Raw Normal View History

2020-07-17 18:05:50 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
[WIP] Better Patch System (#18) * Update build.yml * Remove 3rd party patches * Add Upsteam Submodules * Fix patches * ? * Fix patches * Add Fast Init script * Lots of stuff also it's broke * more broken * fixes * mor stuff * gfhfgh hg * fix patch * fix up script * update submodule * add papercut * update tuinity * update gitmodules * fix var name * fix more var stuff * some how it's not deleting shit anymore * should now use the branch it just made why are we doing this again? * now it does thing thing * return previous so YAPFA can use it * ok now it really does the thing * for REAL it does the thing * don't do the thing because it causes too many problems * fix api * work * use better patching for YAPFA patches * fix better patching * more fixes * new patches stuff * remove old 3rd parry patches add removed akarin patches * make new branch for making patches * hopefully build patches correctly * fix gitignore and add config patches * remove papercut files * fix some weirdness * fix bug * time to do some fixin' :eyes: * New Patch System Rebased Patches * fix full build * exit 1 * fix * Remove patch * Hopefully fix compile errors * fixes * this might work * don't use rej for our patches * tmp disable cache * some times case sensitivity is dumb * my sanity is at an all time low :) * dfg * readd cahce * fix? * Update Upstream * fix perms * fix * fix api * Redo API * rm folders * fix villager brain patch * emc explosion pref * fixed aikar's shit * betterfix * fix lagggg * Origami * Origami Fixes * Update readme * test async path finding * WIP Async Path Finding * WIP fix async path finding * same as bellow * same * update to newer funcs * fix newer funcs * fix author * Updates, Fixes, and new patches * fixes * possibly async flying path finding * minor asnyc pathfinding fix * test remove non asnyc path finder * WIP make all path finding async * Rename everything * Exec flag * Rebuild hashes * remove dupe patch * fix? * Fix packages, redirect config * old nav class is now async and back * add getchatcolor.getbyid and handle patches with a . in them better Co-authored-by: tr7zw <tr7zw@live.de> Co-authored-by: Unknown <unknown@example.com> Co-authored-by: Ovydux <68059159+Ovydux@users.noreply.github.com>
2020-08-03 18:48:42 +02:00
From: JellySquid <jellysquid+atwork@protonmail.com>
Date: Fri, 31 Jul 2020 21:46:32 -0500
2020-06-27 20:02:39 +02:00
Subject: [PATCH] lithium MixinBiome
Original code by JellySquid, licensed under GNU Lesser General Public License v3.0
2020-08-06 23:02:30 +02:00
you can find the original code on https://github.com/jellysquid3/lithium-fabric/tree/1.16.x/fabric (Yarn mappings)
2020-06-27 20:02:39 +02:00
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 0000000000000000000000000000000000000000..2d79932dbd1fc386a94b8d6ea3526934c54c2aad
2020-06-27 20:02:39 +02:00
--- /dev/null
+++ b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/HashedList.java
2020-09-09 19:36:29 +02:00
@@ -0,0 +1,280 @@
2020-06-27 20:02:39 +02:00
+package me.jellysquid.mods.lithium.common.util.collections;
+
2020-09-09 19:36:29 +02:00
+import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
+import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
2020-09-09 19:36:29 +02:00
+import java.util.NoSuchElementException;
2020-06-27 20:02:39 +02:00
+
+/**
2020-09-09 19:36:29 +02:00
+ * Wraps a {@link List} with a hash table which provides O(1) lookups for {@link Collection#contains(Object)}. The type
+ * contained by this list must use reference-equality semantics.
2020-06-27 20:02:39 +02:00
+ */
2020-09-09 19:36:29 +02:00
+@SuppressWarnings("SuspiciousMethodCalls")
2020-06-27 20:02:39 +02:00
+public class HashedList<T> implements List<T> {
2020-09-09 19:36:29 +02:00
+ private final ReferenceArrayList<T> list;
+ private final Reference2IntOpenHashMap<T> counter;
2020-06-27 20:02:39 +02:00
+
2020-09-09 19:36:29 +02:00
+ public HashedList(List<T> list) {
+ this.list = new ReferenceArrayList<>();
+ this.list.addAll(list);
+
+ this.counter = new Reference2IntOpenHashMap<>();
+ this.counter.defaultReturnValue(0);
+
+ for (T obj : this.list) {
+ this.counter.addTo(obj, 1);
+ }
2020-06-27 20:02:39 +02:00
+ }
+
+ @Override
+ public int size() {
+ return this.list.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return this.list.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
2020-09-09 19:36:29 +02:00
+ return this.counter.containsKey(o);
2020-06-27 20:02:39 +02:00
+ }
+
+ @Override
+ public Iterator<T> iterator() {
2020-09-09 19:36:29 +02:00
+ return this.listIterator();
2020-06-27 20:02:39 +02:00
+ }
+
+ @Override
+ public Object[] toArray() {
+ return this.list.toArray();
+ }
+
2020-09-09 19:36:29 +02:00
+ @SuppressWarnings("SuspiciousToArrayCall")
2020-06-27 20:02:39 +02:00
+ @Override
+ public <T1> T1[] toArray(T1[] a) {
+ return this.list.toArray(a);
+ }
+
+ @Override
+ public boolean add(T t) {
2020-09-09 19:36:29 +02:00
+ this.trackReferenceAdded(t);
2020-06-27 20:02:39 +02:00
+
+ return this.list.add(t);
+ }
+
+ @Override
+ public boolean remove(Object o) {
2020-09-09 19:36:29 +02:00
+ this.trackReferenceRemoved(o);
2020-06-27 20:02:39 +02:00
+
+ return this.list.remove(o);
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
2020-09-09 19:36:29 +02:00
+ for (Object obj : c) {
+ if (!this.counter.containsKey(obj)) {
+ return false;
+ }
+ }
+
+ return true;
2020-06-27 20:02:39 +02:00
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends T> c) {
2020-09-09 19:36:29 +02:00
+ for (T obj : c) {
+ this.trackReferenceAdded(obj);
+ }
2020-06-27 20:02:39 +02:00
+
+ return this.list.addAll(c);
+ }
+
+ @Override
+ public boolean addAll(int index, Collection<? extends T> c) {
2020-09-09 19:36:29 +02:00
+ for (T obj : c) {
+ this.trackReferenceAdded(obj);
+ }
2020-06-27 20:02:39 +02:00
+
+ return this.list.addAll(index, c);
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
2020-09-09 19:36:29 +02:00
+ for (Object obj : c) {
+ this.trackReferenceRemoved(obj);
+ }
2020-06-27 20:02:39 +02:00
+
+ return this.list.removeAll(c);
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ return this.list.retainAll(c);
+ }
+
+ @Override
+ public void clear() {
2020-09-09 19:36:29 +02:00
+ this.counter.clear();
2020-06-27 20:02:39 +02:00
+ 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);
+
2020-09-09 19:36:29 +02:00
+ if (prev != element) {
+ if (prev != null) {
+ this.trackReferenceRemoved(prev);
+ }
2020-06-27 20:02:39 +02:00
+
2020-09-09 19:36:29 +02:00
+ this.trackReferenceAdded(element);
+ }
2020-06-27 20:02:39 +02:00
+
+ return prev;
+ }
+
+ @Override
+ public void add(int index, T element) {
2020-09-09 19:36:29 +02:00
+ this.trackReferenceAdded(element);
2020-06-27 20:02:39 +02:00
+
+ this.list.add(index, element);
+ }
+
+ @Override
+ public T remove(int index) {
+ T prev = this.list.remove(index);
+
+ if (prev != null) {
2020-09-09 19:36:29 +02:00
+ this.trackReferenceRemoved(prev);
2020-06-27 20:02:39 +02:00
+ }
+
+ 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() {
2020-09-09 19:36:29 +02:00
+ return this.listIterator(0);
2020-06-27 20:02:39 +02:00
+ }
+
+ @Override
+ public ListIterator<T> listIterator(int index) {
2020-09-09 19:36:29 +02:00
+ return new ListIterator<T>() {
+ private final ListIterator<T> inner = HashedList.this.list.listIterator(index);
+
+ @Override
+ public boolean hasNext() {
+ return this.inner.hasNext();
+ }
+
+ @Override
+ public T next() {
+ return this.inner.next();
+ }
+
+ @Override
+ public boolean hasPrevious() {
+ return this.inner.hasPrevious();
+ }
+
+ @Override
+ public T previous() {
+ return this.inner.previous();
+ }
+
+ @Override
+ public int nextIndex() {
+ return this.inner.nextIndex();
+ }
+
+ @Override
+ public int previousIndex() {
+ return this.inner.previousIndex();
+ }
+
+ @Override
+ public void remove() {
+ int last = this.previousIndex();
+
+ if (last == -1) {
+ throw new NoSuchElementException();
+ }
+
+ T prev = HashedList.this.get(last);
+
+ if (prev != null) {
+ HashedList.this.trackReferenceRemoved(prev);
+ }
+
+ this.inner.remove();
+ }
+
+ @Override
+ public void set(T t) {
+ int last = this.previousIndex();
+
+ if (last == -1) {
+ throw new NoSuchElementException();
+ }
+
+ T prev = HashedList.this.get(last);
+
+ if (prev != t) {
+ if (prev != null) {
+ HashedList.this.trackReferenceRemoved(prev);
+ }
+
+ HashedList.this.trackReferenceAdded(t);
+ }
+
+ this.inner.remove();
+ }
+
+ @Override
+ public void add(T t) {
+ HashedList.this.trackReferenceAdded(t);
+
+ this.inner.add(t);
+ }
+ };
2020-06-27 20:02:39 +02:00
+ }
+
+ @Override
+ public List<T> subList(int fromIndex, int toIndex) {
+ return this.list.subList(fromIndex, toIndex);
+ }
+
2020-09-09 19:36:29 +02:00
+ private void trackReferenceAdded(T t) {
+ this.counter.addTo(t, 1);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void trackReferenceRemoved(Object o) {
+ if (this.counter.addTo((T) o, -1) <= 1) {
2020-09-09 19:36:29 +02:00
+ this.counter.removeInt(o);
+ }
+ }
+
2020-06-27 20:02:39 +02:00
+ public static <T> HashedList<T> wrapper(List<T> list) {
2020-09-09 19:36:29 +02:00
+ return new HashedList<>(list);
2020-06-27 20:02:39 +02:00
+ }
+}
diff --git a/src/main/java/net/minecraft/server/BiomeSettingsMobs.java b/src/main/java/net/minecraft/server/BiomeSettingsMobs.java
index a18ca3f0001a771f21012bd39711f581efb2fef0..0f88b7b38b6191c3adbebdee82427275640c4197 100644
--- a/src/main/java/net/minecraft/server/BiomeSettingsMobs.java
+++ b/src/main/java/net/minecraft/server/BiomeSettingsMobs.java
@@ -113,7 +113,7 @@ public class BiomeSettingsMobs {
private final Map<EnumCreatureType, List<BiomeSettingsMobs.c>> a = (Map) Stream.of(EnumCreatureType.values()).collect(Maps.toImmutableEnumMap((enumcreaturetype) -> {
return enumcreaturetype;
}, (enumcreaturetype) -> {
- return new MobList(); // Use MobList instead of ArrayList
+ return me.jellysquid.mods.lithium.common.util.collections.HashedList.wrapper(new MobList()); // Use MobList instead of ArrayList // Yatopia - hashedlist
}));
// Paper end
private final Map<EntityTypes<?>, BiomeSettingsMobs.b> b = Maps.newLinkedHashMap();