Ability to swap Overworld and End

This commit is contained in:
paulevsGitch 2021-01-05 12:07:56 +03:00
parent 02d43cb670
commit 5c4895f757
2 changed files with 28 additions and 0 deletions

View file

@ -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,14 +15,22 @@ 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<RegistryKey<World>, ServerWorld> worlds;
@Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true)
private void beOnReload(Collection<String> collection, CallbackInfoReturnable<CompletableFuture<Void>> info) {
beInjectRecipes();
@ -32,6 +42,18 @@ public class MinecraftServerMixin {
EndBiomes.initRegistry((MinecraftServer) (Object) this);
}
@Inject(method = "getOverworld", at = @At(value = "HEAD"), cancellable = true)
private final void beGetOverworld(CallbackInfoReturnable<ServerWorld> 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")) {
RecipeManagerAccessor accessor = (RecipeManagerAccessor) serverResourceManager.getRecipeManager();

View file

@ -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;
}
}