mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
44 lines
1.8 KiB
Diff
44 lines
1.8 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..76678beea53dac2fa7c394e97a6616a32ac08a64 100644
|
|
--- a/net/minecraft/util/random/WeightedRandomList.java
|
|
+++ b/net/minecraft/util/random/WeightedRandomList.java
|
|
@@ -2,6 +2,8 @@ package net.minecraft.util.random;
|
|
|
|
import com.google.common.collect.ImmutableList;
|
|
import com.mojang.serialization.Codec;
|
|
+
|
|
+import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Optional;
|
|
@@ -11,10 +13,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;
|
|
|
|
WeightedRandomList(List<? extends E> items) {
|
|
this.items = ImmutableList.copyOf(items);
|
|
this.totalWeight = WeightedRandom.getTotalWeight(items);
|
|
+ this.entryHashList = this.items.size() > 4 ? this.items : Collections.unmodifiableList(new org.dreeam.leaf.util.list.HashedReferenceList<E>(this.items));
|
|
}
|
|
|
|
public static <E extends WeightedEntry> WeightedRandomList<E> create() {
|
|
@@ -43,9 +47,7 @@ public class WeightedRandomList<E extends WeightedEntry> {
|
|
}
|
|
}
|
|
|
|
- public List<E> unwrap() {
|
|
- return this.items;
|
|
- }
|
|
+ public List<E> unwrap() {return this.entryHashList;}
|
|
|
|
public static <E extends WeightedEntry> Codec<WeightedRandomList<E>> codec(Codec<E> elementCodec) {
|
|
return elementCodec.listOf().xmap(WeightedRandomList::create, WeightedRandomList::unwrap);
|