[Change] SurfaceRules for the Nether will get injected after all biome independent rules

This commit is contained in:
Frank 2023-06-20 22:30:01 +02:00
parent a49ada07d4
commit 00ef6fcfa1
3 changed files with 28 additions and 5 deletions

View file

@ -15,7 +15,7 @@ public interface InjectableSurfaceRules<G extends ChunkGenerator> {
*/
default void injectSurfaceRules(ResourceKey<LevelStem> dimensionKey) {
if (this instanceof NoiseBasedChunkGenerator nbc) {
SurfaceRuleUtil.injectSurfaceRules(nbc.generatorSettings().value(), nbc.getBiomeSource());
SurfaceRuleUtil.injectSurfaceRules(dimensionKey, nbc.generatorSettings().value(), nbc.getBiomeSource());
}
}
}

View file

@ -15,6 +15,7 @@ import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.SurfaceRules;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@ -50,6 +51,7 @@ public class SurfaceRuleUtil {
}
private static SurfaceRules.RuleSource mergeSurfaceRules(
ResourceKey<LevelStem> dimensionKey,
SurfaceRules.RuleSource org,
BiomeSource source,
List<SurfaceRules.RuleSource> additionalRules
@ -62,8 +64,23 @@ public class SurfaceRuleUtil {
.stream()
.filter(r -> existingSequence.indexOf(r) < 0)
.collect(Collectors.toList());
if (additionalRules.size() == 0) return null;
additionalRules.addAll(existingSequence);
if (additionalRules.isEmpty()) return null;
// when we are in the nether, we want to keep the nether roof and floor rules in the beginning of the sequence
// we will add our rules whne the first biome test sequence is found
if (dimensionKey.equals(LevelStem.NETHER)) {
final List<SurfaceRules.RuleSource> combined = new ArrayList<>(existingSequence.size() + additionalRules.size());
for (SurfaceRules.RuleSource rule : existingSequence) {
if (rule instanceof SurfaceRules.TestRuleSource testRule
&& testRule.ifTrue() instanceof SurfaceRules.BiomeConditionSource) {
combined.addAll(additionalRules);
}
combined.add(rule);
}
additionalRules = combined;
} else {
additionalRules.addAll(existingSequence);
}
} else {
if (!additionalRules.contains(org))
additionalRules.add(org);
@ -75,10 +92,15 @@ public class SurfaceRuleUtil {
return new SurfaceRules.SequenceRuleSource(additionalRules);
}
public static void injectSurfaceRules(NoiseGeneratorSettings noiseSettings, BiomeSource loadedBiomeSource) {
public static void injectSurfaceRules(
ResourceKey<LevelStem> dimensionKey,
NoiseGeneratorSettings noiseSettings,
BiomeSource loadedBiomeSource
) {
if (((Object) noiseSettings) instanceof SurfaceRuleProvider srp) {
SurfaceRules.RuleSource originalRules = srp.bclib_getOriginalSurfaceRules();
srp.bclib_overwriteSurfaceRules(mergeSurfaceRules(
dimensionKey,
originalRules,
loadedBiomeSource,
getRulesForBiomes(loadedBiomeSource.possibleBiomes().stream().map(h -> h.value()).toList())

View file

@ -15,7 +15,8 @@ accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRul
accessible class net/minecraft/server/dedicated/DedicatedServerProperties$WorldDimensionData
accessible class net/minecraft/client/resources/model/AtlasSet$AtlasEntry
extendable class net/minecraft/world/level/block/state/properties/WoodType
accessible class net/minecraft/world/level/levelgen/SurfaceRules$BiomeConditionSource
accessible class net/minecraft/world/level/levelgen/SurfaceRules$TestRuleSource
#Methods
accessible method net/minecraft/world/level/storage/loot/LootPool <init> ([Lnet/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer;[Lnet/minecraft/world/level/storage/loot/predicates/LootItemCondition;[Lnet/minecraft/world/level/storage/loot/functions/LootItemFunction;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;)V