Upstream has released updates that appear to apply and compile correctly. [Purpur Changes] PurpurMC/Purpur@e86a1b6: Updated Upstream (Paper) PurpurMC/Purpur@962ee30: Updated Upstream (Paper) PurpurMC/Purpur@74d1b4c: Updated Upstream (Paper) PurpurMC/Purpur@e2e8c61: Updated Upstream (Paper) PurpurMC/Purpur@7a01fd8: Updated Upstream (Paper) PurpurMC/Purpur@34c18f0: Updated Upstream (Paper) PurpurMC/Purpur@ca668ab: Updated Upstream (Paper) PurpurMC/Purpur@200178d: Updated Upstream (Paper) PurpurMC/Purpur@9968cbb: Updated Upstream (Paper) PurpurMC/Purpur@db09358: Fix clamp-levels option not being true by default (#1609) PurpurMC/Purpur@f289b6a: Updated Upstream (Paper) PurpurMC/Purpur@959c29d: Fix Tridents giving errors without having an Elytra equipped (#1612) PurpurMC/Purpur@68c1612: Fix villagers not spawning when the `follow-emerald-blocks` option is enabled (#1611) PurpurMC/Purpur@5b75c68: fix `bypass-mob-griefing` not being the inverse of mobgriefing gamerule, closes #1603 PurpurMC/Purpur@55d4309: Updated Upstream (Paper) PurpurMC/Purpur@0601f87: Updated Upstream (Paper) PurpurMC/Purpur@06dde9d: Add Ridable and Attribute options for Creaking mob (#1613) PurpurMC/Purpur@420a1ce: Set the bee's `takes-damage-from-water` option to true by default (#1614) PurpurMC/Purpur@2b6f273: Updated Upstream (Paper) PurpurMC/Purpur@504f311: Updated Upstream (Paper) PurpurMC/Purpur@2b694c9: Updated Upstream (Paper) PurpurMC/Purpur@96d7ef7: Updated Upstream (Paper) PurpurMC/Purpur@e141f68: Updated Upstream (Paper) PurpurMC/Purpur@7f6f667: Updated Upstream (Pufferfish) PurpurMC/Purpur@de20ba9: ignore `minecart.max-speed` config value if using minecart experiment, closes #1618 PurpurMC/Purpur@03062a8: fix ridable mobs not being controllable, closes #1620 PurpurMC/Purpur@0493ac3: Updated Upstream (Paper) PurpurMC/Purpur@16ce24a: fix(ridables/creaking): override tick method in look/move control
307 lines
8.6 KiB
Diff
307 lines
8.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: AlphaKR93 <dev@alpha93.kr>
|
|
Date: Wed, 10 Jan 2024 18:08:59 +0900
|
|
Subject: [PATCH] Lithium - HashedList
|
|
|
|
|
|
diff --git a/src/main/java/me/jellysquid/mods/lithium/common/util/collections/HashedReferenceList.java b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/HashedReferenceList.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..d11579075e653868a43fe826bdf9b41ddc031b85
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/HashedReferenceList.java
|
|
@@ -0,0 +1,277 @@
|
|
+package me.jellysquid.mods.lithium.common.util.collections;
|
|
+
|
|
+import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
|
|
+import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
|
|
+import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+import java.util.*;
|
|
+
|
|
+/**
|
|
+ * 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.
|
|
+ */
|
|
+@SuppressWarnings("SuspiciousMethodCalls")
|
|
+public class HashedReferenceList<T> implements List<T> {
|
|
+ private final ReferenceArrayList<T> list;
|
|
+ private final Reference2IntOpenHashMap<T> counter;
|
|
+
|
|
+ public HashedReferenceList(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);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int size() {
|
|
+ return this.list.size();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isEmpty() {
|
|
+ return this.list.isEmpty();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean contains(Object o) {
|
|
+ return this.counter.containsKey(o);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull Iterator<T> iterator() {
|
|
+ return this.listIterator();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Object @NotNull [] toArray() {
|
|
+ return this.list.toArray();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public <T1> T1 @NotNull [] toArray(T1 @NotNull [] a) {
|
|
+ return this.list.toArray(a);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean add(T t) {
|
|
+ this.trackReferenceAdded(t);
|
|
+
|
|
+ return this.list.add(t);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean remove(Object o) {
|
|
+ this.trackReferenceRemoved(o);
|
|
+
|
|
+ return this.list.remove(o);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean containsAll(Collection<?> c) {
|
|
+ for (Object obj : c) {
|
|
+ if (!this.counter.containsKey(obj)) {
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean addAll(Collection<? extends T> c) {
|
|
+ for (T obj : c) {
|
|
+ this.trackReferenceAdded(obj);
|
|
+ }
|
|
+
|
|
+ return this.list.addAll(c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean addAll(int index, Collection<? extends T> c) {
|
|
+ for (T obj : c) {
|
|
+ this.trackReferenceAdded(obj);
|
|
+ }
|
|
+
|
|
+ return this.list.addAll(index, c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean removeAll(@NotNull Collection<?> c) {
|
|
+ if (this.size() >= 2 && c.size() > 4 && c instanceof List) {
|
|
+ //HashReferenceList uses reference equality, so using ReferenceOpenHashSet is fine
|
|
+ c = new ReferenceOpenHashSet<>(c);
|
|
+ }
|
|
+ this.counter.keySet().removeAll(c);
|
|
+ return this.list.removeAll(c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean retainAll(@NotNull Collection<?> c) {
|
|
+ this.counter.keySet().retainAll(c);
|
|
+ return this.list.retainAll(c);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void clear() {
|
|
+ this.counter.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 != element) {
|
|
+ if (prev != null) {
|
|
+ this.trackReferenceRemoved(prev);
|
|
+ }
|
|
+
|
|
+ this.trackReferenceAdded(element);
|
|
+ }
|
|
+
|
|
+ return prev;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void add(int index, T element) {
|
|
+ this.trackReferenceAdded(element);
|
|
+
|
|
+ this.list.add(index, element);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public T remove(int index) {
|
|
+ T prev = this.list.remove(index);
|
|
+
|
|
+ if (prev != null) {
|
|
+ this.trackReferenceRemoved(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 @NotNull ListIterator<T> listIterator() {
|
|
+ return this.listIterator(0);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull ListIterator<T> listIterator(int index) {
|
|
+ return new ListIterator<>() {
|
|
+ private final ListIterator<T> inner = HashedReferenceList.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 = HashedReferenceList.this.get(last);
|
|
+
|
|
+ if (prev != null) {
|
|
+ HashedReferenceList.this.trackReferenceRemoved(prev);
|
|
+ }
|
|
+
|
|
+ this.inner.remove();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void set(T t) {
|
|
+ int last = this.previousIndex();
|
|
+
|
|
+ if (last == -1) {
|
|
+ throw new NoSuchElementException();
|
|
+ }
|
|
+
|
|
+ T prev = HashedReferenceList.this.get(last);
|
|
+
|
|
+ if (prev != t) {
|
|
+ if (prev != null) {
|
|
+ HashedReferenceList.this.trackReferenceRemoved(prev);
|
|
+ }
|
|
+
|
|
+ HashedReferenceList.this.trackReferenceAdded(t);
|
|
+ }
|
|
+
|
|
+ this.inner.remove();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void add(T t) {
|
|
+ HashedReferenceList.this.trackReferenceAdded(t);
|
|
+
|
|
+ this.inner.add(t);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull List<T> subList(int fromIndex, int toIndex) {
|
|
+ return this.list.subList(fromIndex, toIndex);
|
|
+ }
|
|
+
|
|
+ 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) {
|
|
+ this.counter.removeInt(o);
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/util/random/WeightedRandomList.java b/src/main/java/net/minecraft/util/random/WeightedRandomList.java
|
|
index ef44047c3ea850fe52370b8176efbdf0515d20d6..30efa8704c1ae94027272602687cbc4a2bc8a772 100644
|
|
--- a/src/main/java/net/minecraft/util/random/WeightedRandomList.java
|
|
+++ b/src/main/java/net/minecraft/util/random/WeightedRandomList.java
|
|
@@ -10,10 +10,10 @@ import net.minecraft.util.RandomSource;
|
|
|
|
public class WeightedRandomList<E extends WeightedEntry> {
|
|
private final int totalWeight;
|
|
- private final ImmutableList<E> items;
|
|
+ private final List<E> items; // Plazma - Lithium: collections.mob_spawning
|
|
|
|
WeightedRandomList(List<? extends E> entries) {
|
|
- this.items = ImmutableList.copyOf(entries);
|
|
+ this.items = entries.size() > 4 ? ImmutableList.copyOf(entries) : java.util.Collections.unmodifiableList(new me.jellysquid.mods.lithium.common.util.collections.HashedReferenceList<>(entries)); // Plazma - Lithium: collections.mob_spawning
|
|
this.totalWeight = WeightedRandom.getTotalWeight(entries);
|
|
}
|
|
|