Prepared Custom WorldPreset UI

This commit is contained in:
Frank 2022-05-20 00:54:18 +02:00
parent 375eb09bb9
commit fdc068f6bb
5 changed files with 190 additions and 168 deletions

View file

@ -0,0 +1,23 @@
package org.betterx.bclib.mixin.common;
import net.minecraft.client.gui.screens.worldselection.PresetEditor;
import com.google.common.collect.Maps;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.Map;
@Mixin(PresetEditor.class)
interface PresetEditorMixin {
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Ljava/util/Map;of(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map;"))
private static <K, V> Map<K, V> bcl_foo(K k1, V v1, K k2, V v2) {
Map<K, V> a = Maps.newHashMap();
a.put(k1, v1);
a.put(k2, v2);
return a;
}
}

View file

@ -1,5 +1,6 @@
package org.betterx.bclib.presets;
import net.minecraft.client.gui.screens.worldselection.PresetEditor;
import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
@ -10,10 +11,13 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.tag.TagAPI;
import org.betterx.bclib.api.tag.TagType;
import org.betterx.bclib.gui.modmenu.MainScreen;
import java.util.Optional;
public class WorldPresets {
public static TagType.Simple<WorldPreset> WORLD_PRESETS =
TagAPI.registerType(BuiltinRegistries.WORLD_PRESET, "tag/worldgen/world_preset");
TagAPI.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
public static ResourceKey<WorldPreset> BCL_WORLD = register(BCLib.makeID("normal"));
@ -21,6 +25,10 @@ public class WorldPresets {
ResourceKey<WorldPreset> key = ResourceKey.create(Registry.WORLD_PRESET_REGISTRY,
loc);
WORLD_PRESETS.addUntyped(WorldPresetTags.NORMAL, key.location());
PresetEditor.EDITORS.put(Optional.of(key),
(createWorldScreen, worldCreationContext) -> new MainScreen(createWorldScreen));
return key;
}