Crash fix

This commit is contained in:
paulevsGitch 2021-12-03 15:45:19 +03:00
parent 8e3147f176
commit d3273f609a
3 changed files with 30 additions and 23 deletions

View file

@ -33,6 +33,7 @@ import net.minecraft.world.level.levelgen.GenerationStep.Carving;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.SurfaceRules;
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
@ -442,24 +443,14 @@ public class BiomeAPI {
Set<Biome> biomes = source.possibleBiomes(); Set<Biome> biomes = source.possibleBiomes();
if (level.dimension() == Level.NETHER) { if (level.dimension() == Level.NETHER) {
Set<ResourceLocation> biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet()); RuleSource[] rules = getRuleSources(biomes);
List<SurfaceRules.RuleSource> rules = Lists.newArrayList(); netherRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null;
SURFACE_RULES.forEach((biomeID, rule) -> { System.out.println("Adding nether sources! " + rules.length);
if (biomeIDs.contains(biomeID)) {
rules.add(rule);
}
});
netherRuleSource = SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()]));
} }
else if (level.dimension() == Level.END) { else if (level.dimension() == Level.END) {
Set<ResourceLocation> biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet()); RuleSource[] rules = getRuleSources(biomes);
List<SurfaceRules.RuleSource> rules = Lists.newArrayList(); endRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null;
SURFACE_RULES.forEach((biomeID, rule) -> { System.out.println("Adding end sources! " + rules.length);
if (biomeIDs.contains(biomeID)) {
rules.add(rule);
}
});
endRuleSource = SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()]));
} }
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(level.dimension()); List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(level.dimension());
@ -485,6 +476,17 @@ public class BiomeAPI {
}); });
} }
private static SurfaceRules.RuleSource[] getRuleSources(Set<Biome> biomes) {
Set<ResourceLocation> biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet());
List<SurfaceRules.RuleSource> rules = Lists.newArrayList();
SURFACE_RULES.forEach((biomeID, rule) -> {
if (biomeIDs.contains(biomeID)) {
rules.add(rule);
}
});
return rules.toArray(new SurfaceRules.RuleSource[rules.size()]);
}
/** /**
* Adds new features to existing biome. * Adds new features to existing biome.
* @param biome {@link Biome} to add features in. * @param biome {@link Biome} to add features in.

View file

@ -13,15 +13,19 @@ import ru.bclib.api.biomes.BiomeAPI;
public class SurfaceRuleDataMixin { public class SurfaceRuleDataMixin {
@Inject(method = "nether", at = @At("RETURN"), cancellable = true) @Inject(method = "nether", at = @At("RETURN"), cancellable = true)
private static void bclib_addNetherRuleSource(CallbackInfoReturnable<SurfaceRules.RuleSource> info) { private static void bclib_addNetherRuleSource(CallbackInfoReturnable<SurfaceRules.RuleSource> info) {
RuleSource source = info.getReturnValue(); if (BiomeAPI.getNetherRuleSource() != null) {
source = SurfaceRules.sequence(source, BiomeAPI.getNetherRuleSource()); RuleSource source = info.getReturnValue();
info.setReturnValue(source); source = SurfaceRules.sequence(source, BiomeAPI.getNetherRuleSource());
info.setReturnValue(source);
}
} }
@Inject(method = "end", at = @At("RETURN"), cancellable = true) @Inject(method = "end", at = @At("RETURN"), cancellable = true)
private static void bclib_addEndRuleSource(CallbackInfoReturnable<SurfaceRules.RuleSource> info) { private static void bclib_addEndRuleSource(CallbackInfoReturnable<SurfaceRules.RuleSource> info) {
RuleSource source = info.getReturnValue(); if (BiomeAPI.getEndRuleSource() != null) {
source = SurfaceRules.sequence(source, BiomeAPI.getEndRuleSource()); RuleSource source = info.getReturnValue();
info.setReturnValue(source); source = SurfaceRules.sequence(source, BiomeAPI.getEndRuleSource());
info.setReturnValue(source);
}
} }
} }

View file

@ -37,7 +37,8 @@
"MainMixin", "MainMixin",
"BiomeGenerationSettingsAccessor", "BiomeGenerationSettingsAccessor",
"MobSpawnSettingsAccessor", "MobSpawnSettingsAccessor",
"StructureSettingsAccessor" "StructureSettingsAccessor",
"SurfaceRuleDataMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1