Skip to content

Commit

Permalink
Improve fix to only make changes when required.
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Oct 8, 2023
1 parent 2d3e4ff commit c81dc45
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.LinkedHashSet;
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 LinkedHashSet<>(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 c81dc45

Please sign in to comment.