[Changes] Build for 1.19.3-pre3

This commit is contained in:
Frank 2022-11-30 01:40:42 +01:00
parent 0dcb7809b8
commit 7b726d958d
96 changed files with 1315 additions and 1198 deletions

View file

@ -1,11 +1,11 @@
package org.betterx.worlds.together.biomesource;
import net.minecraft.core.Registry;
import net.minecraft.core.HolderGetter;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
public interface BiomeSourceFromRegistry<T extends BiomeSource> {
Registry<Biome> getBiomeRegistry();
HolderGetter<Biome> getBiomeRegistry();
boolean didBiomeRegistryChange();
default <R extends BiomeSource> boolean togetherBiomeSourceContentChanged(BiomeSourceFromRegistry<R> other) {

View file

@ -12,6 +12,7 @@ import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
import org.betterx.worlds.together.worldPreset.WorldPresets;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.Registries;
@ -28,7 +29,6 @@ import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.WorldDimensions;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import net.minecraft.world.level.levelgen.synth.NormalNoise;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
@ -99,35 +99,31 @@ public class WorldGenUtil {
}
public static class Context extends StemContext {
public final Registry<Biome> biomes;
public final HolderGetter<Biome> biomes;
public Context(
Registry<Biome> biomes,
HolderGetter<Biome> biomes,
Holder<DimensionType> dimension,
Registry<StructureSet> structureSets,
Registry<NormalNoise.NoiseParameters> noiseParameters,
HolderGetter<StructureSet> structureSets,
Holder<NoiseGeneratorSettings> generatorSettings
) {
super(dimension, structureSets, noiseParameters, generatorSettings);
super(dimension, structureSets, generatorSettings);
this.biomes = biomes;
}
}
public static class StemContext {
public final Holder<DimensionType> dimension;
public final Registry<StructureSet> structureSets;
public final Registry<NormalNoise.NoiseParameters> noiseParameters;
public final HolderGetter<StructureSet> structureSets;
public final Holder<NoiseGeneratorSettings> generatorSettings;
public StemContext(
Holder<DimensionType> dimension,
Registry<StructureSet> structureSets,
Registry<NormalNoise.NoiseParameters> noiseParameters,
HolderGetter<StructureSet> structureSets,
Holder<NoiseGeneratorSettings> generatorSettings
) {
this.dimension = dimension;
this.structureSets = structureSets;
this.noiseParameters = noiseParameters;
this.generatorSettings = generatorSettings;
}
}

View file

@ -1,32 +0,0 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
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.CallbackInfo;
@Mixin(BuiltInRegistries.class)
public class BuiltinRegistriesMixin {
@Inject(method = "<clinit>", at = @At(value = "INVOKE", target = "Ljava/util/Map;forEach(Ljava/util/function/BiConsumer;)V"))
private static void together_registerSurface(CallbackInfo ci) {
SurfaceRuleRegistry.BUILTIN_SURFACE_RULES = registerSimple(
SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
SurfaceRuleRegistry::bootstrap
);
}
@Shadow
static protected <T> Registry<T> registerSimple(
ResourceKey<? extends Registry<T>> resourceKey, BuiltInRegistries.RegistryBootstrap<T> registryBootstrap
) {
throw new RuntimeException("Shadowed Call");
}
}

View file

@ -1,6 +1,5 @@
package org.betterx.worlds.together.mixin.common;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.RegistryOps;
import org.spongepowered.asm.mixin.Mixin;
@ -8,6 +7,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(RegistryOps.class)
public interface RegistryOpsAccessor {
@Accessor("registryAccess")
RegistryAccess bcl_getRegistryAccess();
@Accessor("lookupProvider")
RegistryOps.RegistryInfoLookup bcl_getLookupProvider();
}

View file

@ -0,0 +1,28 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.data.registries.VanillaRegistries;
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.CallbackInfo;
@Mixin(VanillaRegistries.class)
public class VanillaRegistriesMixin {
@Shadow
@Final
private static RegistrySetBuilder BUILDER;
@Inject(method = "<clinit>", at = @At(value = "TAIL"))
private static void together_registerSurface(CallbackInfo ci) {
BUILDER.add(
SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
SurfaceRuleRegistry::bootstrap
);
}
}

View file

@ -4,15 +4,16 @@ import org.betterx.worlds.together.levelgen.WorldGenUtil;
import org.betterx.worlds.together.worldPreset.WorldPresets;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.HolderGetter;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import net.minecraft.world.level.levelgen.synth.NormalNoise;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@ -24,29 +25,23 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
public abstract class WorldPresetsBootstrapMixin {
@Shadow
@Final
private Registry<WorldPreset> presets;
private HolderGetter<Biome> biomes;
@Shadow
@Final
private Registry<Biome> biomes;
@Shadow
@Final
private Registry<StructureSet> structureSets;
@Shadow
@Final
private Registry<NormalNoise.NoiseParameters> noises;
@Shadow
@Final
private Holder<DimensionType> netherDimensionType;
@Shadow
@Final
private Holder<NoiseGeneratorSettings> netherNoiseSettings;
@Shadow
@Final
private Holder<DimensionType> endDimensionType;
@Shadow
@Final
private Holder<NoiseGeneratorSettings> endNoiseSettings;
private HolderGetter<StructureSet> structureSets;
@Shadow
@Final
private BootstapContext<WorldPreset> context;
@Shadow
@Final
private HolderGetter<PlacedFeature> placedFeatures;
@Shadow
@Final
private LevelStem netherStem;
@Shadow
@Final
private LevelStem endStem;
//see WorldPresets.register
@Shadow
@ -57,27 +52,38 @@ public abstract class WorldPresetsBootstrapMixin {
@Shadow
@Final
private Registry<NoiseGeneratorSettings> noiseSettings;
private HolderGetter<NoiseGeneratorSettings> noiseSettings;
@ModifyArg(method = "run", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap;registerCustomOverworldPreset(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/LevelStem;)Lnet/minecraft/core/Holder;"))
@ModifyArg(method = "run", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap;registerCustomOverworldPreset(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/LevelStem;)V"))
private LevelStem bcl_getOverworldStem(LevelStem overworldStem) {
Holder<NoiseGeneratorSettings> netherSettings, endSettings;
if (this.netherStem.generator() instanceof NoiseBasedChunkGenerator nether) {
netherSettings = nether.generatorSettings();
} else {
netherSettings = this.noiseSettings.getOrThrow(NoiseGeneratorSettings.NETHER);
}
if (this.endStem.generator() instanceof NoiseBasedChunkGenerator nether) {
endSettings = nether.generatorSettings();
} else {
endSettings = this.noiseSettings.getOrThrow(NoiseGeneratorSettings.END);
}
WorldGenUtil.Context netherContext = new WorldGenUtil.Context(
this.biomes,
this.netherDimensionType,
this.netherStem.type(),
this.structureSets,
this.noises,
this.netherNoiseSettings
netherSettings
);
WorldGenUtil.Context endContext = new WorldGenUtil.Context(
this.biomes,
this.endDimensionType,
this.endStem.type(),
this.structureSets,
this.noises,
this.endNoiseSettings
endSettings
);
WorldPresets.bootstrapPresets(
presets,
context,
overworldStem,
netherContext,
endContext,

View file

@ -2,16 +2,16 @@ package org.betterx.worlds.together.surfaceRules;
import org.betterx.worlds.together.WorldsTogether;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.SurfaceRules;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
import org.jetbrains.annotations.ApiStatus;
@ -21,40 +21,50 @@ public class SurfaceRuleRegistry {
public static final Predicate<ResourceKey<LevelStem>> NON_MANAGED_DIMENSIONS = dim -> dim != LevelStem.NETHER && dim != LevelStem.END;
public static final Predicate<ResourceKey<LevelStem>> ALL_DIMENSIONS = dim -> true;
public static Registry<AssignedSurfaceRule> BUILTIN_SURFACE_RULES;
//public static Registry<AssignedSurfaceRule> BUILTIN_SURFACE_RULES;
private static <T> ResourceKey<Registry<T>> createRegistryKey(ResourceLocation location) {
return ResourceKey.createRegistryKey(location);
}
@ApiStatus.Internal
public static Holder<AssignedSurfaceRule> bootstrap(Registry<AssignedSurfaceRule> registry) {
return BuiltInRegistries.register(
registry,
WorldsTogether.makeID("dummy"),
new AssignedSurfaceRule(
SurfaceRules.state(Blocks.YELLOW_CONCRETE.defaultBlockState()),
WorldsTogether.makeID("none")
)
);
public static void bootstrap(BootstapContext<AssignedSurfaceRule> ctx) {
// ctx.register(
// ResourceKey.create(
// SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
// WorldsTogether.makeID("dummy")
// ),
// new AssignedSurfaceRule(
// SurfaceRules.state(Blocks.YELLOW_CONCRETE.defaultBlockState()),
// WorldsTogether.makeID("none")
// )
// );
for (var entry : KNOWN.entrySet()) {
ctx.register(entry.getKey(), entry.getValue());
}
}
private static Map<ResourceKey<AssignedSurfaceRule>, AssignedSurfaceRule> KNOWN = new HashMap<>();
public static ResourceKey<AssignedSurfaceRule> registerRule(
ResourceLocation ruleID,
SurfaceRules.RuleSource rules,
ResourceLocation biomeID
) {
ResourceKey<AssignedSurfaceRule> key = ResourceKey.create(
final ResourceKey<AssignedSurfaceRule> key = ResourceKey.create(
SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
ruleID
);
Registry.register(SurfaceRuleRegistry.BUILTIN_SURFACE_RULES, key, new AssignedSurfaceRule(
KNOWN.put(
key,
new AssignedSurfaceRule(
SurfaceRules.ifTrue(
SurfaceRules.isBiome(ResourceKey.create(Registries.BIOME, biomeID)),
rules
), biomeID
)
);
return key;
}

View file

@ -19,10 +19,13 @@ import java.util.stream.Collectors;
public class SurfaceRuleUtil {
private static List<SurfaceRules.RuleSource> getRulesForBiome(ResourceLocation biomeID) {
Registry<AssignedSurfaceRule> registry = SurfaceRuleRegistry.BUILTIN_SURFACE_RULES;
Registry<AssignedSurfaceRule> registry = null;
if (WorldBootstrap.getLastRegistryAccess() != null)
registry = WorldBootstrap.getLastRegistryAccess()
.registryOrThrow(SurfaceRuleRegistry.SURFACE_RULES_REGISTRY);
if (registry == null) return List.of();
return registry.stream()
.filter(a -> a != null && a.biomeID != null && a.biomeID.equals(
biomeID))

View file

@ -111,7 +111,7 @@ public class WorldBootstrap {
public static class DedicatedServer {
public static void registryReady(RegistryOps<Tag> regOps) {
if (regOps instanceof RegistryOpsAccessor acc) {
Helpers.onRegistryReady(acc.bcl_getRegistryAccess());
//Helpers.onRegistryReady(acc.bcl_getLookupProvider().);
}
}

View file

@ -14,7 +14,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
@ -30,6 +29,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class TogetherWorldPreset extends WorldPreset {
public final int sortOrder;
@ -152,12 +152,13 @@ public class TogetherWorldPreset extends WorldPreset {
}
}
public static Registry<LevelStem> getDimensions(ResourceKey<WorldPreset> key) {
public static @Nullable Registry<LevelStem> getDimensions(ResourceKey<WorldPreset> key) {
RegistryAccess access = WorldBootstrap.getLastRegistryAccessOrElseBuiltin();
var preset = (access == null
? BuiltInRegistries.WORLD_PRESET
: access.registryOrThrow(Registries.WORLD_PRESET))
.getHolder(key);
if (access == null) {
WorldsTogether.LOGGER.error("No valid registry found!");
return null;
}
var preset = access.registryOrThrow(Registries.WORLD_PRESET).getHolder(key);
if (preset.isEmpty()) return null;
return preset
.get()

View file

@ -9,10 +9,10 @@ import org.betterx.worlds.together.tag.v3.TagRegistry;
import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.WorldPresetTags;
@ -32,8 +32,8 @@ public class WorldPresets {
LevelStem make(BiomeSource biomeSource, Holder<NoiseGeneratorSettings> noiseGeneratorSettings);
}
public static final TagRegistry.Simple<WorldPreset> WORLD_PRESETS =
TagManager.registerType(BuiltInRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
public static final TagRegistry.UnTyped<WorldPreset> WORLD_PRESETS =
TagManager.registerType(Registries.WORLD_PRESET, "tags/worldgen/world_preset");
private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap();
private static ResourceKey<WorldPreset> DEFAULT = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL;
@ -87,23 +87,24 @@ public class WorldPresets {
@ApiStatus.Internal
public static void bootstrapPresets(
Registry<WorldPreset> presets,
BootstapContext<WorldPreset> bootstrapContext,
LevelStem overworldStem,
WorldGenUtil.Context netherContext,
WorldGenUtil.Context endContext,
Registry<NoiseGeneratorSettings> noiseSettings,
HolderGetter<NoiseGeneratorSettings> noiseSettings,
OverworldBuilder noiseBasedOverworld
) {
EntrypointUtil.getCommon(WorldPresetBootstrap.class)
.forEach(e -> e.bootstrapWorldPresets());
for (Map.Entry<ResourceKey<WorldPreset>, PresetBuilder> e : BUILDERS.entrySet()) {
TogetherWorldPreset preset = e.getValue()
.create(
overworldStem, netherContext, endContext,
noiseSettings, noiseBasedOverworld
);
BuiltInRegistries.register(presets, e.getKey(), preset);
//TODO:1.19.3 called out of sync
// TogetherWorldPreset preset = e.getValue()
// .create(
// overworldStem, netherContext, endContext,
// noiseSettings, noiseBasedOverworld
// );
// bootstrapContext.register(e.getKey(), preset);
}
BUILDERS = null;
}
@ -127,7 +128,7 @@ public class WorldPresets {
LevelStem overworldStem,
WorldGenUtil.Context netherContext,
WorldGenUtil.Context endContext,
Registry<NoiseGeneratorSettings> noiseSettings,
HolderGetter<NoiseGeneratorSettings> noiseSettings,
OverworldBuilder noiseBasedOverworld
);
}

View file

@ -7,13 +7,12 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import java.util.Optional;
@Environment(EnvType.CLIENT)
public class WorldPresetsClient {
public static void registerCustomizeUI(ResourceKey<WorldPreset> key, PresetEditor setupScreen) {
if (setupScreen != null) {
PresetEditor.EDITORS.put(Optional.of(key), setupScreen);
//TODO: 1.19.3 this is called out of order
//PresetEditor.EDITORS.put(Optional.of(key), setupScreen);
}
}