Class WorldManager
java.lang.Object
ActiverseUtils.WorldManager
WorldManager - Handles saving and loading world data
Manages world.json and player.json files in Worlds/[WorldName]/ directories.
The Worlds directory is now resolved relative to either the current working directory or its parent. This allows the typical layout:
project-root/
Worlds/
src/
While still supporting cases where the game is launched with the working
directory set to either the project root or the src directory.
This is a significantly harder class to implement than the others, so don't mess with it unless you know what you're doing- Version:
- 1.4.1
- Author:
- Knivier
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidCreates the Worlds directory if it doesn't existstatic StringgetChunkBinaryPath(String worldName, int cx, int cy) static StringgetChunkJsonPath(String worldName, int cx, int cy) static FilegetChunksDirectory(String worldName) static StringgetPlayerJsonPath(String worldName) Gets the path to player.jsonstatic StringgetWorldJsonPath(String worldName) Gets the path to world.jsonGets list of all world names (directories in Worlds/)static StringgetWorldPath(String worldName) Gets the path to a world directorystatic booleanisChunkFormatMigrated(String worldName) True after legacyblocks.jsonhas been split intochunks/(or no edits existed).static Map<Long, WorldManager.BlockData> loadChunkEditsLong(String worldName, int cx, int cy) Loads chunk edits: prefers.chunkbinary, falls back to legacy.json.static Map<String, WorldManager.BlockData> loadModifiedBlocks(String worldName) Loads modified blocksstatic WorldManager.PlayerDataloadPlayerData(String worldName) Loads player data from player.jsonstatic WorldManager.WorldDataloadWorldData(String worldName) Loads world data from world.jsonstatic voidmergeChunkEditOnDisk(String worldName, int tileSize, int chunkTiles, WorldManager.BlockData bd) Merges one edit when the chunk is not currently loaded (rare edge case).static voidmigrateLegacyBlocksJsonToChunkFiles(String worldName, int tileSize, int chunkTiles) Splits monolithicblocks.jsoninto per-chunk files and clears the legacy file.static voidsaveChunkEditsLongMapBinary(String worldName, int cx, int cy, Map<Long, WorldManager.BlockData> edits) Saves chunk edits as compact binary (.chunk).static voidsaveChunkEditsMap(String worldName, int cx, int cy, Map<String, WorldManager.BlockData> edits) Saves edits for one chunk as binary (.chunk).static voidsaveModifiedBlocks(String worldName, Map<String, WorldManager.BlockData> modifiedBlocks) Saves modified blocks (terrain tiles that were placed/destroyed)static voidsavePlayerData(String worldName, WorldManager.PlayerData playerData) Saves player data to player.jsonstatic voidsaveWorldData(String worldName, long seed, int tileSize, int worldWidth, int worldHeight) Saves world data to world.jsonstatic voidsaveWorldData(String worldName, long seed, int tileSize, int worldWidth, int worldHeight, long totalGameTicks) Saves world data to world.json, including total game ticks elapsed.static voidsaveWorldData(String worldName, long seed, int tileSize, int worldWidth, int worldHeight, long totalGameTicks, boolean infinite, int chunkTiles) Saves world.json including infinite-world flags and chunk size (tiles per chunk edge).
-
Constructor Details
-
WorldManager
public WorldManager()
-
-
Method Details
-
ensureWorldsDirectory
public static void ensureWorldsDirectory()Creates the Worlds directory if it doesn't exist -
getWorldList
-
getWorldPath
-
getWorldJsonPath
-
getPlayerJsonPath
-
saveWorldData
public static void saveWorldData(String worldName, long seed, int tileSize, int worldWidth, int worldHeight) Saves world data to world.json -
saveWorldData
public static void saveWorldData(String worldName, long seed, int tileSize, int worldWidth, int worldHeight, long totalGameTicks) Saves world data to world.json, including total game ticks elapsed. -
saveWorldData
public static void saveWorldData(String worldName, long seed, int tileSize, int worldWidth, int worldHeight, long totalGameTicks, boolean infinite, int chunkTiles) Saves world.json including infinite-world flags and chunk size (tiles per chunk edge). -
loadWorldData
Loads world data from world.json -
savePlayerData
Saves player data to player.json -
loadPlayerData
Loads player data from player.json -
saveModifiedBlocks
public static void saveModifiedBlocks(String worldName, Map<String, WorldManager.BlockData> modifiedBlocks) Saves modified blocks (terrain tiles that were placed/destroyed) -
loadModifiedBlocks
Loads modified blocks -
getChunksDirectory
-
getChunkJsonPath
-
getChunkBinaryPath
-
saveChunkEditsLongMapBinary
public static void saveChunkEditsLongMapBinary(String worldName, int cx, int cy, Map<Long, WorldManager.BlockData> edits) Saves chunk edits as compact binary (.chunk). -
loadChunkEditsLong
public static Map<Long, WorldManager.BlockData> loadChunkEditsLong(String worldName, int cx, int cy) Loads chunk edits: prefers.chunkbinary, falls back to legacy.json. -
isChunkFormatMigrated
True after legacyblocks.jsonhas been split intochunks/(or no edits existed). -
saveChunkEditsMap
public static void saveChunkEditsMap(String worldName, int cx, int cy, Map<String, WorldManager.BlockData> edits) Saves edits for one chunk as binary (.chunk). Accepts legacy string-key map for migration helpers. -
mergeChunkEditOnDisk
public static void mergeChunkEditOnDisk(String worldName, int tileSize, int chunkTiles, WorldManager.BlockData bd) Merges one edit when the chunk is not currently loaded (rare edge case). -
migrateLegacyBlocksJsonToChunkFiles
public static void migrateLegacyBlocksJsonToChunkFiles(String worldName, int tileSize, int chunkTiles) Splits monolithicblocks.jsoninto per-chunk files and clears the legacy file.
-