Class WorldManager

java.lang.Object
ActiverseUtils.WorldManager

public class WorldManager extends Object
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
  • Constructor Details

    • WorldManager

      public WorldManager()
  • Method Details

    • ensureWorldsDirectory

      public static void ensureWorldsDirectory()
      Creates the Worlds directory if it doesn't exist
    • getWorldList

      public static List<String> getWorldList()
      Gets list of all world names (directories in Worlds/)
    • getWorldPath

      public static String getWorldPath(String worldName)
      Gets the path to a world directory
    • getWorldJsonPath

      public static String getWorldJsonPath(String worldName)
      Gets the path to world.json
    • getPlayerJsonPath

      public static String getPlayerJsonPath(String worldName)
      Gets the path to player.json
    • 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

      public static WorldManager.WorldData loadWorldData(String worldName)
      Loads world data from world.json
    • savePlayerData

      public static void savePlayerData(String worldName, WorldManager.PlayerData playerData)
      Saves player data to player.json
    • loadPlayerData

      public static WorldManager.PlayerData loadPlayerData(String worldName)
      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

      public static Map<String, WorldManager.BlockData> loadModifiedBlocks(String worldName)
      Loads modified blocks
    • getChunksDirectory

      public static File getChunksDirectory(String worldName)
    • getChunkJsonPath

      public static String getChunkJsonPath(String worldName, int cx, int cy)
    • getChunkBinaryPath

      public static String getChunkBinaryPath(String worldName, int cx, int cy)
    • 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 .chunk binary, falls back to legacy .json.
    • isChunkFormatMigrated

      public static boolean isChunkFormatMigrated(String worldName)
      True after legacy blocks.json has been split into chunks/ (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 monolithic blocks.json into per-chunk files and clears the legacy file.