Skip to content

Commit

Permalink
Fix inconsistency of placed feature locations (#3369)
Browse files Browse the repository at this point in the history
* Fix inconsistency of placed feature locations

`BiomeSource#getBiomes` mixin applies to all biome sources, including one for Overworld.
The return value is a set; however one caller in the worldgen code iterates over it: `PlacedFeatureIndexer`.
Using a hash set here randomizes the return value, affecting feature placement.
Use a linked hash set instead.

* Improve fix to only make changes when required.

---------

Co-authored-by: modmuss50 <[email protected]>
(cherry picked from commit 661cc8c)
(cherry picked from commit 215bbe9)
  • Loading branch information
apple502j authored and modmuss50 committed Oct 8, 2023
1 parent 85da0b3 commit 6b24207
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package net.fabricmc.fabric.mixin.biome;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;

Expand All @@ -33,11 +31,10 @@
public class BiomeSourceMixin {
@Redirect(method = "getBiomes", at = @At(value = "INVOKE", target = "Ljava/util/function/Supplier;get()Ljava/lang/Object;"))
private Object getBiomes(Supplier<Set<RegistryEntry<Biome>>> instance) {
var biomes = new HashSet<>(instance.get());
fabric_modifyBiomeSet(biomes);
return Collections.unmodifiableSet(biomes);
return fabric_modifyBiomeSet(instance.get());
}

protected void fabric_modifyBiomeSet(Set<RegistryEntry<Biome>> biomes) {
protected Set<RegistryEntry<Biome>> fabric_modifyBiomeSet(Set<RegistryEntry<Biome>> biomes) {
return biomes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package net.fabricmc.fabric.mixin.biome;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.function.Supplier;

Expand Down Expand Up @@ -108,14 +110,18 @@ private void getWeightedEndBiome(int biomeX, int biomeY, int biomeZ, MultiNoiseU
}

@Override
protected void fabric_modifyBiomeSet(Set<RegistryEntry<Biome>> biomes) {
protected Set<RegistryEntry<Biome>> fabric_modifyBiomeSet(Set<RegistryEntry<Biome>> biomes) {
if (!hasCheckedForModifiedSet) {
hasCheckedForModifiedSet = true;
biomeSetModified = !overrides.get().customBiomes.isEmpty();
}

if (biomeSetModified) {
biomes.addAll(overrides.get().customBiomes);
var modifiedBiomes = new LinkedHashSet<>(biomes);
modifiedBiomes.addAll(overrides.get().customBiomes);
return Collections.unmodifiableSet(modifiedBiomes);
}

return biomes;
}
}

0 comments on commit 6b24207

Please sign in to comment.