Maintain insertion order for RandomPattern sub-patterns (#2603)

This commit is contained in:
Hannes Greule 2024-03-04 07:32:33 +01:00 committed by GitHub
parent 164271374b
commit 641297497a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -33,7 +33,7 @@ public abstract class RandomCollection<T> {
public static <T> RandomCollection<T> of(Map<T, Double> weights, SimpleRandom random) { public static <T> RandomCollection<T> of(Map<T, Double> weights, SimpleRandom random) {
checkNotNull(random); checkNotNull(random);
return FastRandomCollection.create(weights, random) return FastRandomCollection.create(weights, random)
.orElse(new SimpleRandomCollection<>(weights, random)); .orElseGet(() -> new SimpleRandomCollection<>(weights, random));
} }
public void setRandom(SimpleRandom random) { public void setRandom(SimpleRandom random) {

View File

@ -27,7 +27,7 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -41,7 +41,7 @@ public class RandomPattern extends AbstractPattern {
//FAWE start - SimpleRandom > Random, LHS<P> > List //FAWE start - SimpleRandom > Random, LHS<P> > List
private final SimpleRandom random; private final SimpleRandom random;
private Map<Pattern, Double> weights = new HashMap<>(); private Map<Pattern, Double> weights = new LinkedHashMap<>();
private RandomCollection<Pattern> collection; private RandomCollection<Pattern> collection;
private LinkedHashSet<Pattern> patterns = new LinkedHashSet<>(); private LinkedHashSet<Pattern> patterns = new LinkedHashSet<>();
//FAWE end //FAWE end