Get world by resource location (#316)

This commit is contained in:
pop4959 2022-08-03 03:15:55 -07:00 committed by GitHub
parent e6548adf2b
commit fa361043c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 105 additions and 0 deletions

View File

@ -149,6 +149,11 @@ public class FabricMod implements ModInitializer, ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
Identifier identifier = Identifier.tryParse((String) world);
if (identifier != null) world = identifier;
}
if (world instanceof Identifier) {
DimensionType dimensionType = DimensionType.byId((Identifier) world);
if (dimensionType != null) world = dimensionType;

View File

@ -43,6 +43,8 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public class FabricMod implements ModInitializer, ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
Identifier identifier = Identifier.tryParse((String) world);
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.DIMENSION, identifier));
}
if (world instanceof RegistryKey) {
try {
world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -43,6 +43,8 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public class FabricMod implements ModInitializer, ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
Identifier identifier = Identifier.tryParse((String) world);
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.DIMENSION, identifier));
}
if (world instanceof RegistryKey) {
try {
world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -43,6 +43,8 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public class FabricMod implements ModInitializer, ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
Identifier identifier = Identifier.tryParse((String) world);
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.WORLD_KEY, identifier));
}
if (world instanceof RegistryKey) {
try {
world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -43,6 +43,8 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public class FabricMod implements ModInitializer, ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
Identifier identifier = Identifier.tryParse((String) world);
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.WORLD_KEY, identifier));
}
if (world instanceof RegistryKey) {
try {
world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -43,6 +43,8 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
@ -150,6 +152,11 @@ public class FabricMod implements ModInitializer, ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
Identifier identifier = Identifier.tryParse((String) world);
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.WORLD_KEY, identifier));
}
if (world instanceof RegistryKey) {
try {
world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -162,6 +162,13 @@ public class ForgeMod implements ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
ResourceLocation resourceLocation = ResourceLocation.tryCreate((String) world);
DimensionType dimensionType = null;
if (resourceLocation != null) dimensionType = DimensionType.byName(resourceLocation);
if (dimensionType != null) world = serverInstance.getWorld(dimensionType);
}
if (world instanceof ResourceLocation) {
DimensionType dimensionType = DimensionType.byName((ResourceLocation) world);
if (dimensionType != null) world = dimensionType;

View File

@ -162,6 +162,13 @@ public class ForgeMod implements ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
ResourceLocation resourceLocation = ResourceLocation.tryCreate((String) world);
DimensionType dimensionType = null;
if (resourceLocation != null) dimensionType = DimensionType.byName(resourceLocation);
if (dimensionType != null) world = serverInstance.getWorld(dimensionType);
}
if (world instanceof ResourceLocation) {
DimensionType dimensionType = DimensionType.byName((ResourceLocation) world);
if (dimensionType != null) world = dimensionType;

View File

@ -39,6 +39,8 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent.ServerTickEvent;
@ -163,6 +165,11 @@ public class ForgeMod implements ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
ResourceLocation resourceLocation = ResourceLocation.tryCreate((String) world);
if (resourceLocation != null) world = serverInstance.getWorld(RegistryKey.func_240903_a_(Registry.field_239699_ae_, resourceLocation));
}
if (world instanceof RegistryKey) {
try {
world = serverInstance.getWorld((RegistryKey<World>) world);

View File

@ -35,7 +35,9 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@ -162,6 +164,11 @@ public class ForgeMod implements ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
if (resourceLocation != null) world = serverInstance.getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, resourceLocation));
}
if (world instanceof ResourceKey) {
try {
world = serverInstance.getLevel((ResourceKey<Level>) world);

View File

@ -35,7 +35,9 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@ -162,6 +164,11 @@ public class ForgeMod implements ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
if (resourceLocation != null) world = serverInstance.getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, resourceLocation));
}
if (world instanceof ResourceKey) {
try {
world = serverInstance.getLevel((ResourceKey<Level>) world);

View File

@ -35,7 +35,9 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@ -162,6 +164,11 @@ public class ForgeMod implements ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
if (resourceLocation != null) world = serverInstance.getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, resourceLocation));
}
if (world instanceof ResourceKey) {
try {
world = serverInstance.getLevel((ResourceKey<Level>) world);

View File

@ -35,7 +35,9 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@ -162,6 +164,11 @@ public class ForgeMod implements ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
if (resourceLocation != null) world = serverInstance.getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, resourceLocation));
}
if (world instanceof ResourceKey) {
try {
world = serverInstance.getLevel((ResourceKey<Level>) world);

View File

@ -34,6 +34,7 @@ import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.util.Key;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.World;
@ -200,6 +201,11 @@ public class BukkitPlugin extends JavaPlugin implements ServerInterface, Listene
if (serverWorld != null) world = serverWorld;
}
if (world instanceof String) {
var serverWorld = Bukkit.getWorld(new Key((String) world).getValue());
if (serverWorld != null) world = serverWorld;
}
if (world instanceof UUID) {
var serverWorld = Bukkit.getWorld((UUID) world);
if (serverWorld != null) world = serverWorld;

View File

@ -232,6 +232,11 @@ public class SpongePlugin implements ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
ResourceKey resourceKey = ResourceKey.resolve((String) world);
if (resourceKey != null) world = resourceKey;
}
if (world instanceof ResourceKey) {
var serverWorld = Sponge.server().worldManager().world((ResourceKey) world).orElse(null);
if (serverWorld != null) world = serverWorld;

View File

@ -232,6 +232,11 @@ public class SpongePlugin implements ServerInterface {
if (world instanceof Path)
return getWorld((Path) world);
if (world instanceof String) {
ResourceKey resourceKey = ResourceKey.resolve((String) world);
if (resourceKey != null) world = resourceKey;
}
if (world instanceof ResourceKey) {
var serverWorld = Sponge.server().worldManager().world((ResourceKey) world).orElse(null);
if (serverWorld != null) world = serverWorld;