1
- package fr.unreal852.quantum ;
2
-
3
- import fr.unreal852.quantum.world.QuantumWorld;
4
- import fr.unreal852.quantum.world.QuantumWorldData;
5
- import fr.unreal852.quantum.world.QuantumWorldPersistentState;
6
- import net.minecraft.registry.RegistryKey;
7
- import net.minecraft.registry.RegistryKeys;
8
- import net.minecraft.server.MinecraftServer;
9
- import net.minecraft.util.Identifier;
10
- import net.minecraft.world.GameRules;
11
- import xyz.nucleoid.fantasy.Fantasy;
12
- import xyz.nucleoid.fantasy.RuntimeWorldConfig;
13
-
14
- import java.util.Map;
15
- import java.util.concurrent.ConcurrentHashMap;
16
-
17
- public final class QuantumManager
18
- {
19
- private static final Map <Identifier , QuantumWorld > WORLDS = new ConcurrentHashMap <> ();
20
-
21
- public static QuantumWorld getWorld(Identifier identifier)
22
- {
23
- return WORLDS .get(identifier);
1
+ package fr.unreal852.quantum
2
+
3
+ import fr.unreal852.quantum.world.QuantumWorld
4
+ import fr.unreal852.quantum.world.QuantumWorldData
5
+ import fr.unreal852.quantum.world.QuantumWorldPersistentState
6
+ import net.minecraft.registry.RegistryKey
7
+ import net.minecraft.registry.RegistryKeys
8
+ import net.minecraft.server.MinecraftServer
9
+ import net.minecraft.util.Identifier
10
+ import net.minecraft.world.GameRules
11
+ import xyz.nucleoid.fantasy.Fantasy
12
+ import xyz.nucleoid.fantasy.RuntimeWorldConfig
13
+ import java.util.concurrent.ConcurrentHashMap
14
+
15
+ object QuantumManager {
16
+ private val WORLDS : MutableMap <Identifier , QuantumWorld > = ConcurrentHashMap ()
17
+
18
+ @JvmStatic
19
+ fun getWorld (identifier : Identifier ): QuantumWorld ? {
20
+ return WORLDS [identifier]
24
21
}
25
22
26
- public static QuantumWorld getWorld( String worldName)
27
- {
28
- return getWorld(Identifier .of(" quantum" , worldName));
23
+ @JvmStatic
24
+ fun getWorld ( worldName : String ): QuantumWorld ? {
25
+ return getWorld(Identifier .of(" quantum" , worldName))
29
26
}
30
27
31
- public static QuantumWorld getOrOpenPersistentWorld(MinecraftServer server, QuantumWorldData worldData, boolean saveToDisk)
32
- {
33
- if (WORLDS .containsKey(worldData.getWorldId()))
34
- return WORLDS .get(worldData.getWorldId());
28
+ @JvmStatic
29
+ fun getOrOpenPersistentWorld (
30
+ server : MinecraftServer ,
31
+ worldData : QuantumWorldData ,
32
+ saveToDisk : Boolean
33
+ ): QuantumWorld ? {
34
+ if (WORLDS .containsKey(worldData.worldId)) return WORLDS [worldData.worldId]
35
35
36
- var fantasy = Fantasy .get(server);
37
- var runtimeWorldConfig = getOrCreateRuntimeWorldConfig(server, worldData);
38
- var runtimeWorldHandle = fantasy.getOrOpenPersistentWorld(worldData.getWorldId() , runtimeWorldConfig);
36
+ val fantasy = Fantasy .get(server)
37
+ val runtimeWorldConfig = getOrCreateRuntimeWorldConfig(server, worldData)
38
+ val runtimeWorldHandle = fantasy.getOrOpenPersistentWorld(worldData.worldId , runtimeWorldConfig)
39
39
40
40
// TODO: CustomPortalsMod.dims.put(worldConfig.getWorldId(), runtimeWorldHandle.getRegistryKey());
41
+ val world = QuantumWorld (runtimeWorldHandle, worldData)
42
+ WORLDS [worldData.worldId] = world
41
43
42
- QuantumWorld world = new QuantumWorld (runtimeWorldHandle, worldData);
43
- WORLDS .put(worldData.getWorldId(), world);
44
+ if (saveToDisk) QuantumWorldPersistentState .getQuantumState(server).addWorldData(worldData)
44
45
45
- if (saveToDisk)
46
- QuantumWorldPersistentState .getQuantumState(server).addWorldData(worldData);
47
-
48
- return world;
46
+ return world
49
47
}
50
48
51
- public static RuntimeWorldConfig getOrCreateRuntimeWorldConfig(MinecraftServer server, QuantumWorldData worldData)
52
- {
53
- if (worldData.getRuntimeWorldConfig() != null )
54
- return worldData.getRuntimeWorldConfig();
49
+ fun getOrCreateRuntimeWorldConfig (server : MinecraftServer , worldData : QuantumWorldData ): RuntimeWorldConfig {
50
+ if (worldData.runtimeWorldConfig != null ) return worldData.runtimeWorldConfig
55
51
56
- var runtimeWorldConfig = new RuntimeWorldConfig ();
57
- var serverWorld = server.getWorld(RegistryKey .of(RegistryKeys .WORLD , worldData.getDimensionId()));
52
+ val runtimeWorldConfig = RuntimeWorldConfig ()
53
+ val serverWorld = server.getWorld(RegistryKey .of(RegistryKeys .WORLD , worldData.dimensionId))
58
54
59
- if (serverWorld != null )
60
- {
55
+ if (serverWorld != null ) {
61
56
runtimeWorldConfig
62
- .setDimensionType(serverWorld.getDimensionEntry() )
63
- .setGenerator(serverWorld.getChunkManager().getChunkGenerator());
57
+ .setDimensionType(serverWorld.dimensionEntry )
58
+ .setGenerator(serverWorld.chunkManager.chunkGenerator)
64
59
}
65
60
66
- if (runtimeWorldConfig.getGenerator() == null )
67
- {
68
- runtimeWorldConfig.setGenerator(server.getOverworld().getChunkManager().getChunkGenerator());
69
- Quantum .LOGGER .warn(" The config has no generator, setting the generator to the default one." );
61
+ if (runtimeWorldConfig.generator == null ) {
62
+ runtimeWorldConfig.setGenerator(server.overworld.chunkManager.chunkGenerator)
63
+ Quantum .LOGGER .warn(" The config has no generator, setting the generator to the default one." )
70
64
}
71
65
72
- runtimeWorldConfig.setGameRule(GameRules .DO_DAYLIGHT_CYCLE , true );
66
+ runtimeWorldConfig.setGameRule(GameRules .DO_DAYLIGHT_CYCLE , true )
73
67
74
- return runtimeWorldConfig;
68
+ return runtimeWorldConfig
75
69
}
76
70
77
- public static void loadExistingWorlds(MinecraftServer server)
78
- {
79
- var state = QuantumWorldPersistentState .getQuantumState(server);
71
+ fun loadExistingWorlds (server : MinecraftServer ) {
72
+ val state = QuantumWorldPersistentState .getQuantumState(server)
80
73
81
- for (var world : state.getWorlds())
82
- {
74
+ for (world in state.getWorlds()) {
83
75
if (! world.isEnabled())
84
- continue ;
85
- getOrOpenPersistentWorld(server, world, false );
86
- Quantum .LOGGER .info(" Found enabled world '{}', loading it." , world.getWorldId());
76
+ continue
77
+ getOrOpenPersistentWorld(server, world, false )
78
+ Quantum .LOGGER .info(" Found enabled world '{}', loading it." , world.worldId)
87
79
}
88
- }
89
-
90
- // Old Portal code. =====================================
80
+ } // Old Portal code. =====================================
91
81
// public static PortalLink createPortal(MinecraftServer server, QuantumWorldPortalConfig portalConfig, boolean saveToDisk) {
92
82
// class_1792 item = (class_1792)class_2378.field_11142.method_10223(portalConfig.getPortalIgniteItemId());
93
83
// CustomPortalBuilder portalBuilder = CustomPortalBuilder.beginPortal().destDimID(portalConfig.getDestinationId()).frameBlock(portalConfig.getPortalBlockId()).tintColor(portalConfig.getPortalColor());
@@ -107,7 +97,6 @@ public final class QuantumManager
107
97
//
108
98
// return portalLink;
109
99
// }
110
-
111
100
// public static void loadPortals(MinecraftServer server) {
112
101
// try {
113
102
// File directory = PORTAL_FOLDER.toFile();
0 commit comments