Replicated WorldPreset and FlatLevelPreset Registry

This commit is contained in:
Frank 2022-07-01 11:13:22 +02:00
parent 753d0dd658
commit 6419e11414
28 changed files with 269 additions and 142 deletions

View file

@ -9,8 +9,8 @@ import net.minecraft.core.DefaultedRegistry;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.tags.TagLoader;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.ItemLike;
@ -19,7 +19,6 @@ import net.minecraft.world.level.block.Block;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
@ -254,9 +253,9 @@ public class TagAPI {
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public static <T> Map<ResourceLocation, List<TagLoader.EntryWithSource>> apply( public static <T> Map<ResourceLocation, Tag.Builder> apply(
String directory, String directory,
Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap Map<ResourceLocation, Tag.Builder> tagsMap
) { ) {
TagType<?> type = TYPES.get(directory); TagType<?> type = TYPES.get(directory);
if (type != null) { if (type != null) {

View file

@ -8,18 +8,15 @@ import net.minecraft.core.DefaultedRegistry;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagEntry; import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.tags.TagLoader;
import net.minecraft.tags.TagManager; import net.minecraft.tags.TagManager;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -113,7 +110,7 @@ public class TagType<T> {
} }
public final String directory; public final String directory;
private final Map<ResourceLocation, Set<TagEntry>> tags = Maps.newConcurrentMap(); private final Map<ResourceLocation, Set<Tag.Entry>> tags = Maps.newConcurrentMap();
public final ResourceKey<? extends Registry<T>> registryKey; public final ResourceKey<? extends Registry<T>> registryKey;
private final Function<T, ResourceLocation> locationProvider; private final Function<T, ResourceLocation> locationProvider;
@ -131,11 +128,11 @@ public class TagType<T> {
getSetForTag(tagID); getSetForTag(tagID);
} }
public Set<TagEntry> getSetForTag(ResourceLocation tagID) { public Set<Tag.Entry> getSetForTag(ResourceLocation tagID) {
return tags.computeIfAbsent(tagID, k -> Sets.newHashSet()); return tags.computeIfAbsent(tagID, k -> Sets.newHashSet());
} }
public Set<TagEntry> getSetForTag(TagKey<T> tag) { public Set<Tag.Entry> getSetForTag(TagKey<T> tag) {
if (tag == null) { if (tag == null) {
return new HashSet<>(); return new HashSet<>();
} }
@ -171,10 +168,10 @@ public class TagType<T> {
public void addUntyped(TagKey<T> tagID, ResourceLocation... elements) { public void addUntyped(TagKey<T> tagID, ResourceLocation... elements) {
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID); Set<Tag.Entry> set = getSetForTag(tagID);
for (ResourceLocation id : elements) { for (ResourceLocation id : elements) {
if (id != null) { if (id != null) {
set.add(TagEntry.element(id)); set.add(new Tag.ElementEntry(id));
} }
} }
} }
@ -187,11 +184,11 @@ public class TagType<T> {
public void addOtherTags(TagKey<T> tagID, TagKey<T>... tags) { public void addOtherTags(TagKey<T> tagID, TagKey<T>... tags) {
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID); Set<Tag.Entry> set = getSetForTag(tagID);
for (TagKey<T> tag : tags) { for (TagKey<T> tag : tags) {
ResourceLocation id = tag.location(); ResourceLocation id = tag.location();
if (id != null) { if (id != null) {
set.add(TagEntry.tag(id)); set.add(new Tag.TagEntry(id));
} }
} }
} }
@ -204,11 +201,11 @@ public class TagType<T> {
*/ */
protected void add(TagKey<T> tagID, T... elements) { protected void add(TagKey<T> tagID, T... elements) {
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID); Set<Tag.Entry> set = getSetForTag(tagID);
for (T element : elements) { for (T element : elements) {
ResourceLocation id = locationProvider.apply(element); ResourceLocation id = locationProvider.apply(element);
if (id != null) { if (id != null) {
set.add(TagEntry.element(id)); set.add(new Tag.ElementEntry(id));
} }
} }
} }
@ -222,11 +219,11 @@ public class TagType<T> {
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
protected void add(ResourceLocation tagID, T... elements) { protected void add(ResourceLocation tagID, T... elements) {
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID); Set<Tag.Entry> set = getSetForTag(tagID);
for (T element : elements) { for (T element : elements) {
ResourceLocation id = locationProvider.apply(element); ResourceLocation id = locationProvider.apply(element);
if (id != null) { if (id != null) {
set.add(TagEntry.element(id)); set.add(new Tag.ElementEntry(id));
} }
} }
} }
@ -238,23 +235,23 @@ public class TagType<T> {
} }
} }
public void forEach(BiConsumer<ResourceLocation, Set<TagEntry>> consumer) { public void forEach(BiConsumer<ResourceLocation, Set<Tag.Entry>> consumer) {
tags.forEach(consumer); tags.forEach(consumer);
} }
public void apply(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap) { public void apply(Map<ResourceLocation, Tag.Builder> tagsMap) {
if (Registry.BIOME_REGISTRY.equals(registryKey)) InternalBiomeAPI._runBiomeTagAdders(); if (Registry.BIOME_REGISTRY.equals(registryKey)) InternalBiomeAPI._runBiomeTagAdders();
//this.isFrozen = true; //this.isFrozen = true;
this.forEach((id, ids) -> apply(id, tagsMap.computeIfAbsent(id, key -> Lists.newArrayList()), ids)); this.forEach((id, ids) -> apply(id, tagsMap.computeIfAbsent(id, unused -> new Tag.Builder()), ids));
} }
private static List<TagLoader.EntryWithSource> apply( private static Tag.Builder apply(
ResourceLocation id, ResourceLocation id,
List<TagLoader.EntryWithSource> builder, Tag.Builder builder,
Set<TagEntry> ids Set<Tag.Entry> ids
) { ) {
ids.forEach(value -> builder.add(new TagLoader.EntryWithSource(value, BCLib.MOD_ID))); ids.forEach(value -> builder.add(new Tag.BuilderEntry(value, BCLib.MOD_ID)));
return builder; return builder;
} }
} }

View file

@ -1,10 +1,10 @@
package org.betterx.bclib.presets; package org.betterx.bclib.presets;
import org.betterx.worlds.together.flatLevel.FlatLevelGeneratorPreset;
import org.betterx.worlds.together.tag.v3.TagRegistry; import org.betterx.worlds.together.tag.v3.TagRegistry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorPreset;
/** /**
* @deprecated Use {@link org.betterx.worlds.together.flatLevel.FlatLevelPresets} instead * @deprecated Use {@link org.betterx.worlds.together.flatLevel.FlatLevelPresets} instead

View file

@ -0,0 +1,23 @@
package org.betterx.worlds.together.flatLevel;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryFileCodec;
import net.minecraft.resources.RegistryFixedCodec;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorSettings;
public record FlatLevelGeneratorPreset(Holder<Item> displayItem, FlatLevelGeneratorSettings settings) {
public static final Codec<FlatLevelGeneratorPreset> DIRECT_CODEC = RecordCodecBuilder.create(instance -> instance
.group(
RegistryFixedCodec.create(Registry.ITEM_REGISTRY).fieldOf("display").forGetter(o -> o.displayItem),
FlatLevelGeneratorSettings.CODEC.fieldOf("settings").forGetter(o -> o.settings)
).apply(instance, FlatLevelGeneratorPreset::new)
);
public static final Codec<Holder<FlatLevelGeneratorPreset>> CODEC = RegistryFileCodec.create(
FlatLevelPresets.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
DIRECT_CODEC
);
}

View file

@ -0,0 +1,11 @@
package org.betterx.worlds.together.flatLevel;
import org.betterx.worlds.together.WorldsTogether;
import net.minecraft.tags.TagKey;
public class FlatLevelGeneratorPresetTags {
public static final TagKey<FlatLevelGeneratorPreset> VISIBLE = FlatLevelPresets.FLAT_LEVEL_PRESETS.makeTag(
WorldsTogether.makeID("visible")
);
}

View file

@ -1,18 +1,23 @@
package org.betterx.worlds.together.flatLevel; package org.betterx.worlds.together.flatLevel;
import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.tag.v3.TagManager; import org.betterx.worlds.together.tag.v3.TagManager;
import org.betterx.worlds.together.tag.v3.TagRegistry; import org.betterx.worlds.together.tag.v3.TagRegistry;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.FlatLevelGeneratorPresetTags;
import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorPreset;
public class FlatLevelPresets { public class FlatLevelPresets {
static final ResourceKey<Registry<FlatLevelGeneratorPreset>> FLAT_LEVEL_GENERATOR_PRESET_REGISTRY
= ResourceKey.createRegistryKey(WorldsTogether.makeID("worldgen/flat_level_generator_preset"));
public static final Registry<FlatLevelGeneratorPreset> FLAT_LEVEL_GENERATOR_PRESET
= Registry.registerSimple(FLAT_LEVEL_GENERATOR_PRESET_REGISTRY, (registry) -> null);
public static TagRegistry.Simple<FlatLevelGeneratorPreset> FLAT_LEVEL_PRESETS = public static TagRegistry.Simple<FlatLevelGeneratorPreset> FLAT_LEVEL_PRESETS =
TagManager.registerType( TagManager.registerType(
Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY, FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
"tags/worldgen/flat_level_generator_preset", "tags/worldgen/flat_level_generator_preset",
(b) -> null (b) -> null
); );
@ -20,7 +25,7 @@ public class FlatLevelPresets {
public static ResourceKey<FlatLevelGeneratorPreset> register(ResourceLocation loc) { public static ResourceKey<FlatLevelGeneratorPreset> register(ResourceLocation loc) {
ResourceKey<FlatLevelGeneratorPreset> key = ResourceKey.create( ResourceKey<FlatLevelGeneratorPreset> key = ResourceKey.create(
Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY, FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
loc loc
); );
FLAT_LEVEL_PRESETS.addUntyped(FlatLevelGeneratorPresetTags.VISIBLE, key.location()); FLAT_LEVEL_PRESETS.addUntyped(FlatLevelGeneratorPresetTags.VISIBLE, key.location());

View file

@ -7,10 +7,10 @@ import org.betterx.worlds.together.chunkgenerator.EnforceableChunkGenerator;
import org.betterx.worlds.together.world.BiomeSourceWithSeed; import org.betterx.worlds.together.world.BiomeSourceWithSeed;
import org.betterx.worlds.together.world.WorldConfig; import org.betterx.worlds.together.world.WorldConfig;
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset; import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
import org.betterx.worlds.together.worldPreset.WorldPreset;
import org.betterx.worlds.together.worldPreset.WorldPresets; import org.betterx.worlds.together.worldPreset.WorldPresets;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
@ -37,7 +37,7 @@ public class WorldGenUtil {
boolean generateBonusChest boolean generateBonusChest
) { ) {
WorldGenSettings settings = registryAccess WorldGenSettings settings = registryAccess
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY) .registryOrThrow(WorldPresets.WORLD_PRESET_REGISTRY)
.getHolderOrThrow(preset) .getHolderOrThrow(preset)
.value() .value()
.createWorldGenSettings(seed, generateStructures, generateBonusChest); .createWorldGenSettings(seed, generateStructures, generateBonusChest);

View file

@ -2,13 +2,13 @@ package org.betterx.worlds.together.mixin.client;
import org.betterx.worlds.together.levelgen.WorldGenUtil; import org.betterx.worlds.together.levelgen.WorldGenUtil;
import org.betterx.worlds.together.world.event.WorldBootstrap; import org.betterx.worlds.together.world.event.WorldBootstrap;
import org.betterx.worlds.together.worldPreset.WorldPreset;
import org.betterx.worlds.together.worldPreset.WorldPresets; import org.betterx.worlds.together.worldPreset.WorldPresets;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen; import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent; import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.WorldLoader; import net.minecraft.server.WorldLoader;

View file

@ -1,9 +1,9 @@
package org.betterx.worlds.together.mixin.client; package org.betterx.worlds.together.mixin.client;
import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor; import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor;
import org.betterx.worlds.together.worldPreset.WorldPreset;
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent; import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;

View file

@ -2,6 +2,7 @@ package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry; import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
@ -12,8 +13,18 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.function.Supplier;
@Mixin(BuiltinRegistries.class) @Mixin(BuiltinRegistries.class)
public class BuiltinRegistriesMixin { public abstract class BuiltinRegistriesMixin {
@Shadow
static protected <T> Registry<T> registerSimple(
ResourceKey<? extends Registry<T>> resourceKey,
Supplier<? extends Holder<? extends T>> supplier
) {
throw new RuntimeException("Shadowed Call");
}
@Inject(method = "<clinit>", at = @At(value = "INVOKE", target = "Ljava/util/Map;forEach(Ljava/util/function/BiConsumer;)V")) @Inject(method = "<clinit>", at = @At(value = "INVOKE", target = "Ljava/util/Map;forEach(Ljava/util/function/BiConsumer;)V"))
private static void together_registerSurface(CallbackInfo ci) { private static void together_registerSurface(CallbackInfo ci) {
@ -23,10 +34,4 @@ public class BuiltinRegistriesMixin {
); );
} }
@Shadow
static protected <T> Registry<T> registerSimple(
ResourceKey<? extends Registry<T>> resourceKey, BuiltinRegistries.RegistryBootstrap<T> registryBootstrap
) {
throw new RuntimeException("Shadowed Call");
}
} }

View file

@ -3,6 +3,7 @@ package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.tag.v3.TagManager; import org.betterx.worlds.together.tag.v3.TagManager;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagLoader; import net.minecraft.tags.TagLoader;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@ -11,7 +12,6 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyArg;
import java.util.List;
import java.util.Map; import java.util.Map;
@Mixin(TagLoader.class) @Mixin(TagLoader.class)
@ -21,7 +21,7 @@ public class TagLoaderMixin {
private String directory; private String directory;
@ModifyArg(method = "loadAndBuild", at = @At(value = "INVOKE", target = "Lnet/minecraft/tags/TagLoader;build(Ljava/util/Map;)Ljava/util/Map;")) @ModifyArg(method = "loadAndBuild", at = @At(value = "INVOKE", target = "Lnet/minecraft/tags/TagLoader;build(Ljava/util/Map;)Ljava/util/Map;"))
public Map<ResourceLocation, List<TagLoader.EntryWithSource>> be_modifyTags(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap) { public Map<ResourceLocation, Tag.Builder> be_modifyTags(Map<ResourceLocation, Tag.Builder> tagsMap) {
return TagManager.apply(directory, tagsMap); return TagManager.apply(directory, tagsMap);
} }
} }

View file

@ -1,19 +1,22 @@
package org.betterx.worlds.together.mixin.common; package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.worldPreset.WorldPreset;
import org.betterx.worlds.together.worldPreset.WorldPresets; import org.betterx.worlds.together.worldPreset.WorldPresets;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.dedicated.DedicatedServerProperties; import net.minecraft.server.dedicated.DedicatedServerProperties;
import com.google.gson.JsonObject;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(DedicatedServerProperties.WorldGenProperties.class) @Mixin(DedicatedServerProperties.WorldGenProperties.class)
public class WorldGenPropertiesMixin { public class WorldGenPropertiesMixin {
@ModifyArg(method = "create", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/presets/WorldPreset;createWorldGenSettings(JZZ)Lnet/minecraft/world/level/levelgen/WorldGenSettings;")) @Inject(method = "<init>", at = @At(value = "TAIL"))
public long bcl_create(long seed) { private static void bcl_create(String string, JsonObject jsonObject, boolean bl, String string2, CallbackInfo ci) {
return seed; return seed;
} }

View file

@ -1,6 +1,7 @@
package org.betterx.worlds.together.mixin.common; package org.betterx.worlds.together.mixin.common;
import net.minecraft.client.gui.screens.worldselection.WorldPreset; import org.betterx.worlds.together.worldPreset.WorldPreset;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;

View file

@ -1,11 +1,11 @@
package org.betterx.worlds.together.mixin.common; package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset; import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
import org.betterx.worlds.together.worldPreset.WorldPreset;
import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;

View file

@ -1,73 +1,66 @@
package org.betterx.worlds.together.mixin.common; package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.levelgen.WorldGenUtil; import org.betterx.worlds.together.levelgen.WorldGenUtil;
import org.betterx.worlds.together.worldPreset.WorldPreset;
import org.betterx.worlds.together.worldPreset.WorldPresets; import org.betterx.worlds.together.worldPreset.WorldPresets;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.structure.StructureSet; import net.minecraft.world.level.levelgen.structure.StructureSet;
import net.minecraft.world.level.levelgen.synth.NormalNoise; import net.minecraft.world.level.levelgen.synth.NormalNoise;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(net.minecraft.world.level.levelgen.presets.WorldPresets.Bootstrap.class) @Mixin(WorldPreset.class)
public abstract class WorldPresetsBootstrapMixin { public abstract class WorldPresetsBootstrapMixin {
@Shadow
@Final
private Registry<WorldPreset> presets;
@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;
//see WorldPresets.register //see WorldPresets.register
@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;")) @Inject(method = "<clinit>", at = @At(value = "TAIL"))
private LevelStem bcl_getOverworldStem(LevelStem overworldStem) { private static void bcl_getOverworldStem(CallbackInfo ci) {
Registry<org.betterx.worlds.together.worldPreset.WorldPreset> presets = WorldPresets.WORLD_PRESET;
Registry<DimensionType> dimensionTypes = BuiltinRegistries.ACCESS.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
Registry<Biome> biomes = BuiltinRegistries.BIOME;
Registry<StructureSet> structureSets = BuiltinRegistries.STRUCTURE_SETS;
Registry<NoiseGeneratorSettings> noiseSettings = BuiltinRegistries.NOISE_GENERATOR_SETTINGS;
Registry<NormalNoise.NoiseParameters> noises = BuiltinRegistries.NOISE;
Holder<DimensionType> overworldDimensionType = dimensionTypes.getOrCreateHolder(DimensionType.OVERWORLD_LOCATION);
Holder<DimensionType> netherDimensionType = dimensionTypes.getOrCreateHolder(DimensionType.NETHER_LOCATION);
Holder<NoiseGeneratorSettings> netherNoiseSettings = noiseSettings.getOrCreateHolder(NoiseGeneratorSettings.NETHER);
Holder<DimensionType> endDimensionType = dimensionTypes.getOrCreateHolder(DimensionType.END_LOCATION);
Holder<NoiseGeneratorSettings> endNoiseSettings = noiseSettings.getOrCreateHolder(NoiseGeneratorSettings.END);
LevelStem overworldStem = new LevelStem(
overworldDimensionType,
WorldGenSettings.makeDefaultOverworld(BuiltinRegistries.ACCESS, 0)
);
WorldGenUtil.Context netherContext = new WorldGenUtil.Context( WorldGenUtil.Context netherContext = new WorldGenUtil.Context(
this.biomes, biomes,
this.netherDimensionType, netherDimensionType,
this.structureSets, structureSets,
this.noises, noises,
this.netherNoiseSettings netherNoiseSettings
); );
WorldGenUtil.Context endContext = new WorldGenUtil.Context( WorldGenUtil.Context endContext = new WorldGenUtil.Context(
this.biomes, biomes,
this.endDimensionType, endDimensionType,
this.structureSets, structureSets,
this.noises, noises,
this.endNoiseSettings endNoiseSettings
); );
WorldPresets.bootstrapPresets(presets, overworldStem, netherContext, endContext); WorldPresets.bootstrapPresets(presets, overworldStem, netherContext, endContext);
return overworldStem;
} }
} }

View file

@ -27,9 +27,9 @@ public class SurfaceRuleRegistry {
} }
@ApiStatus.Internal @ApiStatus.Internal
public static Holder<AssignedSurfaceRule> bootstrap(Registry<AssignedSurfaceRule> registry) { public static Holder<AssignedSurfaceRule> bootstrap() {
return BuiltinRegistries.register( return BuiltinRegistries.register(
registry, BUILTIN_SURFACE_RULES,
WorldsTogether.makeID("dummy"), WorldsTogether.makeID("dummy"),
new AssignedSurfaceRule( new AssignedSurfaceRule(
SurfaceRules.state(Blocks.YELLOW_CONCRETE.defaultBlockState()), SurfaceRules.state(Blocks.YELLOW_CONCRETE.defaultBlockState()),

View file

@ -9,14 +9,13 @@ import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.tags.TagLoader;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
@ -101,9 +100,9 @@ public class TagManager {
* @return The {@code tagsMap} Parameter. * @return The {@code tagsMap} Parameter.
*/ */
@ApiStatus.Internal @ApiStatus.Internal
public static <T> Map<ResourceLocation, List<TagLoader.EntryWithSource>> apply( public static <T> Map<ResourceLocation, Tag.Builder> apply(
String directory, String directory,
Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap Map<ResourceLocation, Tag.Builder> tagsMap
) { ) {
tagsMap = TagAPI.apply(directory, tagsMap); tagsMap = TagAPI.apply(directory, tagsMap);

View file

@ -7,20 +7,17 @@ import net.minecraft.core.DefaultedRegistry;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagEntry; import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.tags.TagLoader;
import net.minecraft.tags.TagManager; import net.minecraft.tags.TagManager;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -87,7 +84,7 @@ public class TagRegistry<T> {
return makeTag(modID, "has_structure/" + name); return makeTag(modID, "has_structure/" + name);
} }
public void apply(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap) { public void apply(Map<ResourceLocation, Tag.Builder> tagsMap) {
InternalBiomeAPI._runBiomeTagAdders(); InternalBiomeAPI._runBiomeTagAdders();
super.apply(tagsMap); super.apply(tagsMap);
} }
@ -124,7 +121,7 @@ public class TagRegistry<T> {
} }
public final String directory; public final String directory;
private final Map<ResourceLocation, Set<TagEntry>> tags = Maps.newConcurrentMap(); private final Map<ResourceLocation, Set<Tag.Entry>> tags = Maps.newConcurrentMap();
public final ResourceKey<? extends Registry<T>> registryKey; public final ResourceKey<? extends Registry<T>> registryKey;
private final Function<T, ResourceLocation> locationProvider; private final Function<T, ResourceLocation> locationProvider;
@ -142,11 +139,11 @@ public class TagRegistry<T> {
getSetForTag(tagID); getSetForTag(tagID);
} }
public Set<TagEntry> getSetForTag(ResourceLocation tagID) { public Set<Tag.Entry> getSetForTag(ResourceLocation tagID) {
return tags.computeIfAbsent(tagID, k -> Sets.newHashSet()); return tags.computeIfAbsent(tagID, k -> Sets.newHashSet());
} }
public Set<TagEntry> getSetForTag(TagKey<T> tag) { public Set<Tag.Entry> getSetForTag(TagKey<T> tag) {
if (tag == null) { if (tag == null) {
return new HashSet<>(); return new HashSet<>();
} }
@ -192,10 +189,10 @@ public class TagRegistry<T> {
public void addUntyped(TagKey<T> tagID, ResourceLocation... elements) { public void addUntyped(TagKey<T> tagID, ResourceLocation... elements) {
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID); Set<Tag.Entry> set = getSetForTag(tagID);
for (ResourceLocation id : elements) { for (ResourceLocation id : elements) {
if (id != null) { if (id != null) {
set.add(TagEntry.element(id)); set.add(new Tag.ElementEntry(id));
} }
} }
} }
@ -208,11 +205,11 @@ public class TagRegistry<T> {
public void addOtherTags(TagKey<T> tagID, TagKey<T>... tags) { public void addOtherTags(TagKey<T> tagID, TagKey<T>... tags) {
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID); Set<Tag.Entry> set = getSetForTag(tagID);
for (TagKey<T> tag : tags) { for (TagKey<T> tag : tags) {
ResourceLocation id = tag.location(); ResourceLocation id = tag.location();
if (id != null) { if (id != null) {
set.add(TagEntry.tag(id)); set.add(new Tag.TagEntry(id));
} }
} }
} }
@ -225,11 +222,11 @@ public class TagRegistry<T> {
*/ */
protected void add(TagKey<T> tagID, T... elements) { protected void add(TagKey<T> tagID, T... elements) {
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID); Set<Tag.Entry> set = getSetForTag(tagID);
for (T element : elements) { for (T element : elements) {
ResourceLocation id = locationProvider.apply(element); ResourceLocation id = locationProvider.apply(element);
if (id != null) { if (id != null) {
set.add(TagEntry.element(id)); set.add(new Tag.ElementEntry(id));
} }
} }
} }
@ -243,11 +240,11 @@ public class TagRegistry<T> {
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
protected void add(ResourceLocation tagID, T... elements) { protected void add(ResourceLocation tagID, T... elements) {
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen."); if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID); Set<Tag.Entry> set = getSetForTag(tagID);
for (T element : elements) { for (T element : elements) {
ResourceLocation id = locationProvider.apply(element); ResourceLocation id = locationProvider.apply(element);
if (id != null) { if (id != null) {
set.add(TagEntry.element(id)); set.add(new Tag.ElementEntry(id));
} }
} }
} }
@ -259,22 +256,22 @@ public class TagRegistry<T> {
} }
} }
public void forEach(BiConsumer<ResourceLocation, Set<TagEntry>> consumer) { public void forEach(BiConsumer<ResourceLocation, Set<Tag.Entry>> consumer) {
tags.forEach(consumer); tags.forEach(consumer);
} }
public void apply(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap) { public void apply(Map<ResourceLocation, Tag.Builder> tagsMap) {
//this.isFrozen = true; //this.isFrozen = true;
this.forEach((id, ids) -> apply(id, tagsMap.computeIfAbsent(id, key -> Lists.newArrayList()), ids)); this.forEach((id, ids) -> apply(id, tagsMap.computeIfAbsent(id, key -> new Tag.Builder()), ids));
} }
private static List<TagLoader.EntryWithSource> apply( private static Tag.Builder apply(
ResourceLocation id, ResourceLocation id,
List<TagLoader.EntryWithSource> builder, Tag.Builder builder,
Set<TagEntry> ids Set<Tag.Entry> ids
) { ) {
ids.forEach(value -> builder.add(new TagLoader.EntryWithSource(value, BCLib.MOD_ID))); ids.forEach(value -> builder.add(new Tag.BuilderEntry(value, BCLib.MOD_ID)));
return builder; return builder;
} }
} }

View file

@ -1,6 +1,7 @@
package org.betterx.worlds.together.world.event; package org.betterx.worlds.together.world.event;
import net.minecraft.client.gui.screens.worldselection.WorldPreset; import org.betterx.worlds.together.worldPreset.WorldPreset;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.levelgen.WorldGenSettings;

View file

@ -1,6 +1,7 @@
package org.betterx.worlds.together.world.event; package org.betterx.worlds.together.world.event;
import net.minecraft.client.gui.screens.worldselection.WorldPreset; import org.betterx.worlds.together.worldPreset.WorldPreset;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.levelgen.WorldGenSettings;

View file

@ -9,12 +9,11 @@ import org.betterx.worlds.together.surfaceRules.SurfaceRuleUtil;
import org.betterx.worlds.together.world.WorldConfig; import org.betterx.worlds.together.world.WorldConfig;
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset; import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor; import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor;
import org.betterx.worlds.together.worldPreset.WorldPreset;
import org.betterx.worlds.together.worldPreset.WorldPresets; import org.betterx.worlds.together.worldPreset.WorldPresets;
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent; import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.BuiltinRegistries;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
@ -96,7 +95,7 @@ public class WorldBootstrap {
var presetKey = currentPreset.get().unwrapKey(); var presetKey = currentPreset.get().unwrapKey();
if (presetKey.isPresent()) { if (presetKey.isPresent()) {
Optional<Holder<WorldPreset>> newPreset = LAST_REGISTRY_ACCESS Optional<Holder<WorldPreset>> newPreset = LAST_REGISTRY_ACCESS
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY) .registryOrThrow(WorldPresets.WORLD_PRESET_REGISTRY)
.getHolder(presetKey.get()); .getHolder(presetKey.get());
if (newPreset.isPresent()) currentPreset = newPreset; if (newPreset.isPresent()) currentPreset = newPreset;
} }

View file

@ -9,7 +9,6 @@ import org.betterx.worlds.together.world.event.WorldBootstrap;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.Dynamic; import com.mojang.serialization.Dynamic;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -25,7 +24,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class TogetherWorldPreset extends WorldPreset { public class TogetherWorldPreset extends org.betterx.worlds.together.worldPreset.WorldPreset {
public final int sortOrder; public final int sortOrder;
private static int NEXT_IN_SORT_ORDER = 1000; private static int NEXT_IN_SORT_ORDER = 1000;

View file

@ -1,6 +1,5 @@
package org.betterx.worlds.together.worldPreset; package org.betterx.worlds.together.worldPreset;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import java.util.Optional; import java.util.Optional;

View file

@ -0,0 +1,16 @@
package org.betterx.worlds.together.worldPreset;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.level.chunk.ChunkGenerator;
public class WorldPreset {
private final net.minecraft.client.gui.screens.worldselection.WorldPreset parent;
public WorldPreset(net.minecraft.client.gui.screens.worldselection.WorldPreset parent) {
this.parent = parent;
}
protected ChunkGenerator generator(RegistryAccess registryAccess, long l) {
return null;
}
}

View file

@ -0,0 +1,9 @@
package org.betterx.worlds.together.worldPreset;
import org.betterx.worlds.together.WorldsTogether;
import net.minecraft.tags.TagKey;
public class WorldPresetTags {
public static final TagKey<WorldPreset> NORMAL = WorldPresets.WORLD_PRESETS.makeTag(WorldsTogether.makeID("normal"));
}

View file

@ -7,14 +7,12 @@ import org.betterx.worlds.together.tag.v3.TagManager;
import org.betterx.worlds.together.tag.v3.TagRegistry; import org.betterx.worlds.together.tag.v3.TagRegistry;
import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient; import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.WorldPresetTags;
import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.dimension.LevelStem;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@ -23,15 +21,43 @@ import java.util.Map;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
public class WorldPresets { public class WorldPresets {
public static final ResourceKey<Registry<WorldPreset>> WORLD_PRESET_REGISTRY
= ResourceKey.createRegistryKey(WorldsTogether.makeID("worldgen/world_preset"));
public static final Registry<WorldPreset> WORLD_PRESET
= Registry.registerSimple(WORLD_PRESET_REGISTRY, (registry) -> null);
public static final TagRegistry.Simple<WorldPreset> WORLD_PRESETS = public static final TagRegistry.Simple<WorldPreset> WORLD_PRESETS =
TagManager.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset"); TagManager.registerType(WORLD_PRESET, "tags/worldgen/world_preset");
private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap(); private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap();
private static ResourceKey<WorldPreset> DEFAULT = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL;
private static ResourceKey<WorldPreset> NORMAL = ResourceKey.create(
WORLD_PRESET_REGISTRY,
WorldsTogether.makeID("vanilla_normal")
);
private static ResourceKey<WorldPreset> LARGE_BIOMES = ResourceKey.create(
WORLD_PRESET_REGISTRY,
WorldsTogether.makeID("vanilla_large_biomes")
);
private static ResourceKey<WorldPreset> AMPLIFIED = ResourceKey.create(
WORLD_PRESET_REGISTRY,
WorldsTogether.makeID("vanilla_amplified")
);
private static ResourceKey<WorldPreset> FLAT = ResourceKey.create(
WORLD_PRESET_REGISTRY,
WorldsTogether.makeID("vanilla_flat")
);
private static ResourceKey<WorldPreset> SINGLE_BIOME_SURFACE = ResourceKey.create(
WORLD_PRESET_REGISTRY,
WorldsTogether.makeID("vanilla_single_biome_surface")
);
private static ResourceKey<WorldPreset> DEFAULT = NORMAL;
public static Holder<WorldPreset> get(RegistryAccess access, ResourceKey<WorldPreset> key) { public static Holder<WorldPreset> get(RegistryAccess access, ResourceKey<WorldPreset> key) {
return ((access != null) ? access : BuiltinRegistries.ACCESS) return ((access != null) ? access : BuiltinRegistries.ACCESS)
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY) .registryOrThrow(WORLD_PRESET_REGISTRY)
.getHolderOrThrow(key); .getHolderOrThrow(key);
} }
@ -46,9 +72,9 @@ public class WorldPresets {
* @return The key you may use to reference your new Preset * @return The key you may use to reference your new Preset
*/ */
private static ResourceKey<WorldPreset> register(ResourceLocation loc, boolean visibleInUI) { private static ResourceKey<WorldPreset> register(ResourceLocation loc, boolean visibleInUI) {
ResourceKey<WorldPreset> key = ResourceKey.create(Registry.WORLD_PRESET_REGISTRY, loc); ResourceKey<WorldPreset> key = ResourceKey.create(WORLD_PRESET_REGISTRY, loc);
if (visibleInUI) { if (visibleInUI) {
if (!didExplicitlySetDefault && DEFAULT == net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL) { if (!didExplicitlySetDefault && DEFAULT == NORMAL) {
DEFAULT = key; DEFAULT = key;
} }
WORLD_PRESETS.addUntyped(WorldPresetTags.NORMAL, key.location()); WORLD_PRESETS.addUntyped(WorldPresetTags.NORMAL, key.location());
@ -113,4 +139,39 @@ public class WorldPresets {
WorldGenUtil.Context endContext WorldGenUtil.Context endContext
); );
} }
static {
Registry.register(
WORLD_PRESET,
NORMAL,
new WorldPreset(net.minecraft.client.gui.screens.worldselection.WorldPreset.NORMAL)
);
Registry.register(
WORLD_PRESET,
LARGE_BIOMES,
new WorldPreset(net.minecraft.client.gui.screens.worldselection.WorldPreset.LARGE_BIOMES)
);
Registry.register(
WORLD_PRESET,
AMPLIFIED,
new WorldPreset(net.minecraft.client.gui.screens.worldselection.WorldPreset.AMPLIFIED)
);
Registry.register(
WORLD_PRESET,
FLAT,
new WorldPreset(net.minecraft.client.gui.screens.worldselection.WorldPreset.FLAT)
);
Registry.register(
WORLD_PRESET,
SINGLE_BIOME_SURFACE,
new WorldPreset(net.minecraft.client.gui.screens.worldselection.WorldPreset.SINGLE_BIOME_SURFACE)
);
}
} }

View file

@ -1,8 +1,8 @@
package org.betterx.worlds.together.worldPreset.client; package org.betterx.worlds.together.worldPreset.client;
import org.betterx.bclib.registry.PresetsRegistryClient; import org.betterx.bclib.registry.PresetsRegistryClient;
import org.betterx.worlds.together.worldPreset.WorldPreset;
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;

View file

@ -8,13 +8,22 @@ accessible class net/minecraft/world/level/levelgen/SurfaceRules$SurfaceRule
accessible class net/minecraft/world/level/levelgen/SurfaceRules$LazyXZCondition accessible class net/minecraft/world/level/levelgen/SurfaceRules$LazyXZCondition
accessible class net/minecraft/world/level/levelgen/SurfaceRules$LazyCondition accessible class net/minecraft/world/level/levelgen/SurfaceRules$LazyCondition
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource
accessible class net/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap
extendable class net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator extendable class net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator
accessible class net/minecraft/data/BuiltinRegistries$RegistryBootstrap
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource
accessible class net/minecraft/core/Registry$RegistryBootstrap
accessible class net/minecraft/tags/Tag$ElementEntry
accessible class net/minecraft/tags/Tag$TagEntry
#Methods #Methods
accessible method net/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent updateSettings (Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext$Updater;)V
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 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
accessible method net/minecraft/world/entity/ai/village/poi/PoiTypes register (Lnet/minecraft/core/Registry;Lnet/minecraft/resources/ResourceKey;Ljava/util/Set;II)Lnet/minecraft/world/entity/ai/village/poi/PoiType; accessible method net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource <init> (Ljava/util/List;)V
accessible method net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource <init> (Ljava/util/List;)V accessible method net/minecraft/core/Registry registerSimple (Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/core/Registry$RegistryBootstrap;)Lnet/minecraft/core/Registry;
#Fields
accessible field net/minecraft/client/gui/screens/worldselection/WorldPreset FLAT Lnet/minecraft/client/gui/screens/worldselection/WorldPreset;
accessible field net/minecraft/client/gui/screens/worldselection/WorldPreset LARGE_BIOMES Lnet/minecraft/client/gui/screens/worldselection/WorldPreset;
accessible field net/minecraft/client/gui/screens/worldselection/WorldPreset AMPLIFIED Lnet/minecraft/client/gui/screens/worldselection/WorldPreset;
accessible field net/minecraft/client/gui/screens/worldselection/WorldPreset SINGLE_BIOME_SURFACE Lnet/minecraft/client/gui/screens/worldselection/WorldPreset;
accessible field net/minecraft/client/gui/screens/worldselection/WorldPreset PRESETS Ljava/util/List;
accessible field net/minecraft/client/gui/screens/worldselection/WorldPreset EDITORS Ljava/util/Map;