Rebuild indexed features during biome modification ()

This commit is contained in:
apple502j 2024-04-20 19:28:40 +09:00 committed by GitHub
parent 7f0e1106e7
commit 76551cf623
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 5 deletions
fabric-biome-api-v1/src/main

View file

@ -103,6 +103,10 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
spawnSettings.freeze();
}
boolean shouldRebuildFeatures() {
return generationSettings.rebuildFeatures;
}
private class WeatherContextImpl implements WeatherContext {
@Override
public void setPrecipitation(boolean hasPrecipitation) {
@ -194,7 +198,7 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
private final Registry<PlacedFeature> features = registries.get(RegistryKeys.PLACED_FEATURE);
private final GenerationSettings generationSettings = biome.getGenerationSettings();
private boolean rebuildFlowerFeatures;
boolean rebuildFeatures;
/**
* Unfreeze the immutable lists found in the generation settings, and make sure they're filled up to every
@ -204,7 +208,7 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
unfreezeCarvers();
unfreezeFeatures();
rebuildFlowerFeatures = false;
rebuildFeatures = false;
}
private void unfreezeCarvers() {
@ -225,7 +229,7 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
freezeCarvers();
freezeFeatures();
if (rebuildFlowerFeatures) {
if (rebuildFeatures) {
rebuildFlowerFeatures();
}
}
@ -267,7 +271,7 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
if (features.removeIf(feature -> feature.value() == placedFeature)) {
featureSteps.set(stepIndex, RegistryEntryList.of(features));
rebuildFlowerFeatures = true;
rebuildFeatures = true;
return true;
}
@ -288,7 +292,7 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
featureSteps.set(index, plus(featureSteps.get(index), getEntry(features, entry)));
// Ensure the list of flower features is up-to-date
rebuildFlowerFeatures = true;
rebuildFeatures = true;
}
@Override

View file

@ -26,6 +26,7 @@ import java.util.function.Consumer;
import java.util.function.Predicate;
import com.google.common.base.Stopwatch;
import com.google.common.base.Suppliers;
import org.jetbrains.annotations.TestOnly;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -36,6 +37,7 @@ import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.util.PlacedFeatureIndexer;
import net.fabricmc.fabric.api.biome.v1.BiomeModificationContext;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectionContext;
@ -152,6 +154,18 @@ public class BiomeModificationImpl {
// Re-freeze and apply certain cleanup actions
if (modificationContext != null) {
modificationContext.freeze();
if (modificationContext.shouldRebuildFeatures()) {
impl.get(RegistryKeys.DIMENSION).stream().forEach(dimensionOptions -> {
dimensionOptions.chunkGenerator().indexedFeaturesListSupplier = Suppliers.memoize(
() -> PlacedFeatureIndexer.collectIndexedFeatures(
List.copyOf(dimensionOptions.chunkGenerator().getBiomeSource().getBiomes()),
(biomeEntry) -> (biomeEntry.value().generationSettings).getFeatures(),
true
)
);
});
}
}
}

View file

@ -55,3 +55,7 @@ accessible field net/minecraft/world/biome/GenerationSettings flowerFeatures Lja
mutable field net/minecraft/world/biome/GenerationSettings flowerFeatures Ljava/util/function/Supplier;
accessible field net/minecraft/world/biome/GenerationSettings allowedFeatures Ljava/util/function/Supplier;
mutable field net/minecraft/world/biome/GenerationSettings allowedFeatures Ljava/util/function/Supplier;
# ChunkGenerator
accessible field net/minecraft/world/gen/chunk/ChunkGenerator indexedFeaturesListSupplier Ljava/util/function/Supplier;
mutable field net/minecraft/world/gen/chunk/ChunkGenerator indexedFeaturesListSupplier Ljava/util/function/Supplier;