From 5c4895f757e57852b6219a29218a0441f90f1ba1 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Tue, 5 Jan 2021 12:07:56 +0300 Subject: [PATCH] Ability to swap Overworld and End --- .../mixin/common/MinecraftServerMixin.java | 22 +++++++++++++++++++ .../world/generator/GeneratorOptions.java | 6 +++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java index 14b87a78..960f7ee4 100644 --- a/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java @@ -1,8 +1,10 @@ package ru.betterend.mixin.common; import java.util.Collection; +import java.util.Map; import java.util.concurrent.CompletableFuture; +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; @@ -13,13 +15,21 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.resource.ServerResourceManager; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.World; import ru.betterend.recipe.EndRecipeManager; import ru.betterend.registry.EndBiomes; +import ru.betterend.world.generator.GeneratorOptions; @Mixin(MinecraftServer.class) public class MinecraftServerMixin { @Shadow private ServerResourceManager serverResourceManager; + + @Final + @Shadow + private Map, ServerWorld> worlds; @Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true) private void beOnReload(Collection collection, CallbackInfoReturnable> info) { @@ -31,6 +41,18 @@ public class MinecraftServerMixin { beInjectRecipes(); EndBiomes.initRegistry((MinecraftServer) (Object) this); } + + @Inject(method = "getOverworld", at = @At(value = "HEAD"), cancellable = true) + private final void beGetOverworld(CallbackInfoReturnable info) { + if (GeneratorOptions.swapOverworldToEnd()) { + ServerWorld world = worlds.get(World.END); + if (world == null) { + world = worlds.get(World.OVERWORLD); + } + info.setReturnValue(world); + info.cancel(); + } + } private void beInjectRecipes() { if (FabricLoader.getInstance().isModLoaded("kubejs")) { diff --git a/src/main/java/ru/betterend/world/generator/GeneratorOptions.java b/src/main/java/ru/betterend/world/generator/GeneratorOptions.java index c12b6441..5df80e81 100644 --- a/src/main/java/ru/betterend/world/generator/GeneratorOptions.java +++ b/src/main/java/ru/betterend/world/generator/GeneratorOptions.java @@ -8,6 +8,7 @@ public class GeneratorOptions { private static boolean hasPortal; private static boolean hasPillars; private static boolean hasDragonFights; + private static boolean swapOverworldToEnd; public static void init() { biomeSizeLand = Configs.GENERATOR_CONFIG.getIntRoot("biomeSizeLand", 256); @@ -15,6 +16,7 @@ public class GeneratorOptions { hasPortal = Configs.GENERATOR_CONFIG.getBooleanRoot("hasPortal", true); hasPillars = Configs.GENERATOR_CONFIG.getBooleanRoot("hasPillars", true); hasDragonFights = Configs.GENERATOR_CONFIG.getBooleanRoot("hasDragonFights", true); + swapOverworldToEnd = Configs.GENERATOR_CONFIG.getBooleanRoot("swapOverworldToEnd", false); } public static int getBiomeSizeLand() { @@ -36,4 +38,8 @@ public class GeneratorOptions { public static boolean hasDragonFights() { return hasDragonFights; } + + public static boolean swapOverworldToEnd() { + return swapOverworldToEnd; + } }