9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0171-Use-HashedList-on-WeightedRandomList.patch
2025-06-11 03:59:45 +08:00

33 lines
1.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Tue, 13 May 2025 20:41:07 +0200
Subject: [PATCH] Use HashedList on WeightedRandomList
diff --git a/net/minecraft/util/random/WeightedRandomList.java b/net/minecraft/util/random/WeightedRandomList.java
index d81648b9159b765ea3ff99abd46c065ac7f08d6b..dc141f55f2df22b49b7db034cad9a2f57f6b8731 100644
--- a/net/minecraft/util/random/WeightedRandomList.java
+++ b/net/minecraft/util/random/WeightedRandomList.java
@@ -11,10 +11,12 @@ import net.minecraft.util.RandomSource;
public class WeightedRandomList<E extends WeightedEntry> {
private final int totalWeight;
private final ImmutableList<E> items;
+ private List<E> entryHashList; // Leaf - Use HashedList on WeightedRandomList
WeightedRandomList(List<? extends E> items) {
this.items = ImmutableList.copyOf(items);
this.totalWeight = WeightedRandom.getTotalWeight(items);
+ this.entryHashList = this.items.size() > 4 ? this.items : java.util.Collections.unmodifiableList(new org.dreeam.leaf.util.list.HashedReferenceList<>(this.items)); // Leaf - Use HashedList on WeightedRandomList
}
public static <E extends WeightedEntry> WeightedRandomList<E> create() {
@@ -44,7 +46,7 @@ public class WeightedRandomList<E extends WeightedEntry> {
}
public List<E> unwrap() {
- return this.items;
+ return this.entryHashList; // Leaf - Use HashedList on WeightedRandomList
}
public static <E extends WeightedEntry> Codec<WeightedRandomList<E>> codec(Codec<E> elementCodec) {