Surface rules API
This commit is contained in:
parent
92dae621f1
commit
c7ce0b5547
6 changed files with 94 additions and 62 deletions
|
@ -31,7 +31,6 @@ import net.minecraft.world.level.levelgen.GenerationStep.Carving;
|
|||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
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.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
|
@ -40,6 +39,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.config.Configs;
|
||||
import ru.bclib.interfaces.SurfaceRuleProvider;
|
||||
import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor;
|
||||
import ru.bclib.mixin.common.MobSpawnSettingsAccessor;
|
||||
import ru.bclib.mixin.common.StructureSettingsAccessor;
|
||||
|
@ -94,9 +94,6 @@ public class BiomeAPI {
|
|||
public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")));
|
||||
public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")));
|
||||
|
||||
private static SurfaceRules.RuleSource netherRuleSource;
|
||||
private static SurfaceRules.RuleSource endRuleSource;
|
||||
|
||||
/**
|
||||
* Initialize registry for current server.
|
||||
* @param biomeRegistry - {@link Registry} for {@link Biome}.
|
||||
|
@ -297,8 +294,10 @@ public class BiomeAPI {
|
|||
* @param biome - {@link Biome} from server world.
|
||||
* @return biome {@link ResourceKey} or {@code null}.
|
||||
*/
|
||||
@Nullable
|
||||
public static ResourceKey getBiomeKey(Biome biome) {
|
||||
return biomeRegistry.getResourceKey(biome).orElse(null);
|
||||
ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).orElse(null);
|
||||
return key != null ? key : biomeRegistry != null ? biomeRegistry.getResourceKey(biome).orElse(null) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -307,7 +306,10 @@ public class BiomeAPI {
|
|||
* @return biome {@link ResourceLocation}.
|
||||
*/
|
||||
public static ResourceLocation getBiomeID(Biome biome) {
|
||||
ResourceLocation id = biomeRegistry.getKey(biome);
|
||||
ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome);
|
||||
if (id == null && biomeRegistry != null) {
|
||||
id = biomeRegistry.getKey(biome);
|
||||
}
|
||||
return id == null ? EMPTY_BIOME.getID() : id;
|
||||
}
|
||||
|
||||
|
@ -416,22 +418,6 @@ public class BiomeAPI {
|
|||
registerBiomeModification(Level.END, modification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns surface rule source for the Nether.
|
||||
* @return {@link SurfaceRules.RuleSource}.
|
||||
*/
|
||||
public static SurfaceRules.RuleSource getNetherRuleSource() {
|
||||
return netherRuleSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns surface rule source for the End.
|
||||
* @return {@link SurfaceRules.RuleSource}.
|
||||
*/
|
||||
public static SurfaceRules.RuleSource getEndRuleSource() {
|
||||
return endRuleSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will apply biome modifications to world, internal usage only.
|
||||
* @param level
|
||||
|
@ -440,15 +426,24 @@ public class BiomeAPI {
|
|||
BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource();
|
||||
Set<Biome> biomes = source.possibleBiomes();
|
||||
|
||||
NoiseGeneratorSettings generator = null;
|
||||
if (level.dimension() == Level.NETHER) {
|
||||
RuleSource[] rules = getRuleSources(biomes, level.dimension());
|
||||
netherRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null;
|
||||
System.out.println("Adding nether sources! " + rules.length);
|
||||
generator = BuiltinRegistries.NOISE_GENERATOR_SETTINGS.get(NoiseGeneratorSettings.NETHER);
|
||||
}
|
||||
else if (level.dimension() == Level.END) {
|
||||
RuleSource[] rules = getRuleSources(biomes, level.dimension());
|
||||
endRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null;
|
||||
System.out.println("Adding end sources! " + rules.length);
|
||||
generator = BuiltinRegistries.NOISE_GENERATOR_SETTINGS.get(NoiseGeneratorSettings.END);
|
||||
}
|
||||
|
||||
if (generator != null) {
|
||||
List<SurfaceRules.RuleSource> rules = getRuleSources(biomes, level.dimension());
|
||||
SurfaceRuleProvider provider = SurfaceRuleProvider.class.cast(generator);
|
||||
if (rules.size() > 0) {
|
||||
rules.add(provider.getSurfaceRule());
|
||||
provider.setSurfaceRule(SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()])));
|
||||
}
|
||||
else {
|
||||
provider.setSurfaceRule(null);
|
||||
}
|
||||
}
|
||||
|
||||
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(level.dimension());
|
||||
|
@ -474,7 +469,7 @@ public class BiomeAPI {
|
|||
});
|
||||
}
|
||||
|
||||
private static SurfaceRules.RuleSource[] getRuleSources(Set<Biome> biomes, ResourceKey<Level> dimensionType) {
|
||||
private static List<SurfaceRules.RuleSource> getRuleSources(Set<Biome> biomes, ResourceKey<Level> dimensionType) {
|
||||
Set<ResourceLocation> biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet());
|
||||
List<SurfaceRules.RuleSource> rules = Lists.newArrayList();
|
||||
SURFACE_RULES.forEach((biomeID, rule) -> {
|
||||
|
@ -506,7 +501,7 @@ public class BiomeAPI {
|
|||
}
|
||||
}*/
|
||||
|
||||
return rules.toArray(new SurfaceRules.RuleSource[rules.size()]);
|
||||
return rules;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
21
src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java
Normal file
21
src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package ru.bclib.api.biomes;
|
||||
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules.ConditionSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SurfaceRuleBuilder {
|
||||
private static final SurfaceRuleBuilder INSTANCE = new SurfaceRuleBuilder();
|
||||
private List<ConditionSource> conditions;
|
||||
|
||||
private SurfaceRuleBuilder() {}
|
||||
|
||||
public static SurfaceRuleBuilder start() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static SurfaceRules.RuleSource build() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package ru.bclib.interfaces;
|
||||
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
|
||||
public interface SurfaceRuleProvider {
|
||||
void setSurfaceRule(SurfaceRules.RuleSource surfaceRule);
|
||||
|
||||
SurfaceRules.RuleSource getSurfaceRule();
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package ru.bclib.mixin.common;
|
||||
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import ru.bclib.interfaces.SurfaceRuleProvider;
|
||||
|
||||
@Mixin(NoiseGeneratorSettings.class)
|
||||
public class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider {
|
||||
@Final
|
||||
@Shadow
|
||||
private SurfaceRules.RuleSource surfaceRule;
|
||||
|
||||
private SurfaceRules.RuleSource bclib_surfaceRule;
|
||||
|
||||
@Override
|
||||
public void setSurfaceRule(SurfaceRules.RuleSource surfaceRule) {
|
||||
bclib_surfaceRule = surfaceRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleSource getSurfaceRule() {
|
||||
return surfaceRule;
|
||||
}
|
||||
|
||||
@Inject(method = "surfaceRule", at = @At("HEAD"), cancellable = true)
|
||||
private void bclib_surfaceRule(CallbackInfoReturnable<SurfaceRules.RuleSource> info) {
|
||||
if (bclib_surfaceRule != null) {
|
||||
info.setReturnValue(bclib_surfaceRule);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package ru.bclib.mixin.common;
|
||||
|
||||
import net.minecraft.data.worldgen.SurfaceRuleData;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import ru.bclib.api.biomes.BiomeAPI;
|
||||
|
||||
@Mixin(SurfaceRuleData.class)
|
||||
public class SurfaceRuleDataMixin {
|
||||
@Inject(method = "nether", at = @At("RETURN"), cancellable = true)
|
||||
private static void bclib_addNetherRuleSource(CallbackInfoReturnable<SurfaceRules.RuleSource> info) {
|
||||
if (BiomeAPI.getNetherRuleSource() != null) {
|
||||
RuleSource source = info.getReturnValue();
|
||||
source = SurfaceRules.sequence(source, BiomeAPI.getNetherRuleSource());
|
||||
info.setReturnValue(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "end", at = @At("RETURN"), cancellable = true)
|
||||
private static void bclib_addEndRuleSource(CallbackInfoReturnable<SurfaceRules.RuleSource> info) {
|
||||
if (BiomeAPI.getEndRuleSource() != null) {
|
||||
RuleSource source = info.getReturnValue();
|
||||
source = SurfaceRules.sequence(source, BiomeAPI.getEndRuleSource());
|
||||
info.setReturnValue(source);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@
|
|||
"BiomeGenerationSettingsAccessor",
|
||||
"MobSpawnSettingsAccessor",
|
||||
"StructureSettingsAccessor",
|
||||
"SurfaceRuleDataMixin"
|
||||
"NoiseGeneratorSettingsMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue