Skip to content

Commit fa36104

Browse files
authored
Get world by resource location (#316)
1 parent e6548ad commit fa36104

File tree

16 files changed

+105
-0
lines changed

16 files changed

+105
-0
lines changed

implementations/fabric-1.15.2/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ public Optional<ServerWorld> getWorld(Object world) {
149149
if (world instanceof Path)
150150
return getWorld((Path) world);
151151

152+
if (world instanceof String) {
153+
Identifier identifier = Identifier.tryParse((String) world);
154+
if (identifier != null) world = identifier;
155+
}
156+
152157
if (world instanceof Identifier) {
153158
DimensionType dimensionType = DimensionType.byId((Identifier) world);
154159
if (dimensionType != null) world = dimensionType;

implementations/fabric-1.16.1/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
4444
import net.minecraft.server.MinecraftServer;
4545
import net.minecraft.server.network.ServerPlayerEntity;
46+
import net.minecraft.util.Identifier;
47+
import net.minecraft.util.registry.Registry;
4648
import net.minecraft.util.registry.RegistryKey;
4749
import net.minecraft.world.World;
4850
import org.apache.logging.log4j.LogManager;
@@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
150152
if (world instanceof Path)
151153
return getWorld((Path) world);
152154

155+
if (world instanceof String) {
156+
Identifier identifier = Identifier.tryParse((String) world);
157+
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.DIMENSION, identifier));
158+
}
159+
153160
if (world instanceof RegistryKey) {
154161
try {
155162
world = serverInstance.getWorld((RegistryKey<World>) world);

implementations/fabric-1.16.2/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
4444
import net.minecraft.server.MinecraftServer;
4545
import net.minecraft.server.network.ServerPlayerEntity;
46+
import net.minecraft.util.Identifier;
47+
import net.minecraft.util.registry.Registry;
4648
import net.minecraft.util.registry.RegistryKey;
4749
import net.minecraft.world.World;
4850
import org.apache.logging.log4j.LogManager;
@@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
150152
if (world instanceof Path)
151153
return getWorld((Path) world);
152154

155+
if (world instanceof String) {
156+
Identifier identifier = Identifier.tryParse((String) world);
157+
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.DIMENSION, identifier));
158+
}
159+
153160
if (world instanceof RegistryKey) {
154161
try {
155162
world = serverInstance.getWorld((RegistryKey<World>) world);

implementations/fabric-1.17/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
4444
import net.minecraft.server.MinecraftServer;
4545
import net.minecraft.server.network.ServerPlayerEntity;
46+
import net.minecraft.util.Identifier;
47+
import net.minecraft.util.registry.Registry;
4648
import net.minecraft.util.registry.RegistryKey;
4749
import net.minecraft.world.World;
4850
import org.apache.logging.log4j.LogManager;
@@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
150152
if (world instanceof Path)
151153
return getWorld((Path) world);
152154

155+
if (world instanceof String) {
156+
Identifier identifier = Identifier.tryParse((String) world);
157+
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.WORLD_KEY, identifier));
158+
}
159+
153160
if (world instanceof RegistryKey) {
154161
try {
155162
world = serverInstance.getWorld((RegistryKey<World>) world);

implementations/fabric-1.18/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
4444
import net.minecraft.server.MinecraftServer;
4545
import net.minecraft.server.network.ServerPlayerEntity;
46+
import net.minecraft.util.Identifier;
47+
import net.minecraft.util.registry.Registry;
4648
import net.minecraft.util.registry.RegistryKey;
4749
import net.minecraft.world.World;
4850
import org.apache.logging.log4j.LogManager;
@@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
150152
if (world instanceof Path)
151153
return getWorld((Path) world);
152154

155+
if (world instanceof String) {
156+
Identifier identifier = Identifier.tryParse((String) world);
157+
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.WORLD_KEY, identifier));
158+
}
159+
153160
if (world instanceof RegistryKey) {
154161
try {
155162
world = serverInstance.getWorld((RegistryKey<World>) world);

implementations/fabric-1.19/src/main/java/de/bluecolored/bluemap/fabric/FabricMod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
4444
import net.minecraft.server.MinecraftServer;
4545
import net.minecraft.server.network.ServerPlayerEntity;
46+
import net.minecraft.util.Identifier;
47+
import net.minecraft.util.registry.Registry;
4648
import net.minecraft.util.registry.RegistryKey;
4749
import net.minecraft.world.World;
4850
import org.apache.logging.log4j.LogManager;
@@ -150,6 +152,11 @@ public Optional<ServerWorld> getWorld(Object world) {
150152
if (world instanceof Path)
151153
return getWorld((Path) world);
152154

155+
if (world instanceof String) {
156+
Identifier identifier = Identifier.tryParse((String) world);
157+
if (identifier != null) world = serverInstance.getWorld(RegistryKey.of(Registry.WORLD_KEY, identifier));
158+
}
159+
153160
if (world instanceof RegistryKey) {
154161
try {
155162
world = serverInstance.getWorld((RegistryKey<World>) world);

implementations/forge-1.14.4/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ public Optional<ServerWorld> getWorld(Object world) {
162162
if (world instanceof Path)
163163
return getWorld((Path) world);
164164

165+
if (world instanceof String) {
166+
ResourceLocation resourceLocation = ResourceLocation.tryCreate((String) world);
167+
DimensionType dimensionType = null;
168+
if (resourceLocation != null) dimensionType = DimensionType.byName(resourceLocation);
169+
if (dimensionType != null) world = serverInstance.getWorld(dimensionType);
170+
}
171+
165172
if (world instanceof ResourceLocation) {
166173
DimensionType dimensionType = DimensionType.byName((ResourceLocation) world);
167174
if (dimensionType != null) world = dimensionType;

implementations/forge-1.15.2/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ public Optional<ServerWorld> getWorld(Object world) {
162162
if (world instanceof Path)
163163
return getWorld((Path) world);
164164

165+
if (world instanceof String) {
166+
ResourceLocation resourceLocation = ResourceLocation.tryCreate((String) world);
167+
DimensionType dimensionType = null;
168+
if (resourceLocation != null) dimensionType = DimensionType.byName(resourceLocation);
169+
if (dimensionType != null) world = serverInstance.getWorld(dimensionType);
170+
}
171+
165172
if (world instanceof ResourceLocation) {
166173
DimensionType dimensionType = DimensionType.byName((ResourceLocation) world);
167174
if (dimensionType != null) world = dimensionType;

implementations/forge-1.16.2/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import net.minecraft.entity.player.ServerPlayerEntity;
4040
import net.minecraft.server.MinecraftServer;
4141
import net.minecraft.util.RegistryKey;
42+
import net.minecraft.util.ResourceLocation;
43+
import net.minecraft.util.registry.Registry;
4244
import net.minecraft.world.World;
4345
import net.minecraftforge.common.MinecraftForge;
4446
import net.minecraftforge.event.TickEvent.ServerTickEvent;
@@ -163,6 +165,11 @@ public Optional<ServerWorld> getWorld(Object world) {
163165
if (world instanceof Path)
164166
return getWorld((Path) world);
165167

168+
if (world instanceof String) {
169+
ResourceLocation resourceLocation = ResourceLocation.tryCreate((String) world);
170+
if (resourceLocation != null) world = serverInstance.getWorld(RegistryKey.func_240903_a_(Registry.field_239699_ae_, resourceLocation));
171+
}
172+
166173
if (world instanceof RegistryKey) {
167174
try {
168175
world = serverInstance.getWorld((RegistryKey<World>) world);

implementations/forge-1.17.1/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
import de.bluecolored.bluemap.core.BlueMap;
3636
import de.bluecolored.bluemap.core.MinecraftVersion;
3737
import de.bluecolored.bluemap.core.logger.Logger;
38+
import net.minecraft.core.Registry;
3839
import net.minecraft.resources.ResourceKey;
40+
import net.minecraft.resources.ResourceLocation;
3941
import net.minecraft.server.MinecraftServer;
4042
import net.minecraft.server.level.ServerLevel;
4143
import net.minecraft.server.level.ServerPlayer;
@@ -162,6 +164,11 @@ public Optional<ServerWorld> getWorld(Object world) {
162164
if (world instanceof Path)
163165
return getWorld((Path) world);
164166

167+
if (world instanceof String) {
168+
ResourceLocation resourceLocation = ResourceLocation.tryParse((String) world);
169+
if (resourceLocation != null) world = serverInstance.getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, resourceLocation));
170+
}
171+
165172
if (world instanceof ResourceKey) {
166173
try {
167174
world = serverInstance.getLevel((ResourceKey<Level>) world);

0 commit comments

Comments
 (0)