• Forums

Navigation

  • Home
  • Style Guide
  • Getting Started
    • Home
    • Structuring Your Mod
    • Forge Update Checker
    • Debug Profiler
  • Concepts
    • Sides
    • Resources
    • Data
    • Registries
    • Mod Lifecycle
    • Internationalization and localization
  • Blocks
    • Home
    • Blockstates
    • Interaction
  • Tile Entities
    • Home
    • Renderer
  • Items
    • Home
    • Loot Modification
  • Models
    • Intro to Models
    • Model Files
    • Blockstates
      • Intro to Blockstate JSONs
    • Coloring Textures
    • Item Property Overrides
    • Advanced Models
      • IBakedModel
      • Perspective
      • ItemOverrideList
  • Rendering
    • ItemStackTileEntityRenderer
  • Data Generation
    • Introduction
    • Model Providers
  • Events
    • Basic Usage
  • Networking
    • Home
    • Overview
    • SimpleImpl
    • Entities
  • Data Storage
    • Capabilities
    • World Saved Data
      • Declaration
      • Attaching to a World
  • Utilities
    • Recipes
    • Tags
  • Effects
    • Particles
    • Sounds
  • Conventions
    • Versioning
    • Locations
  • Advanced Topics
    • Access Transformers
  • Contributing to Forge
    • Getting Started
    • PR Guidelines
  • Legacy Versions
    • Home
    • Porting to 1.16

World Saved Data

The World Saved Data (WSD) system is an alternative to world capabilities that can attach data per world.

Declaration

Each WSD implementation must subtype the WorldSavedData class. There are three important methods to be aware of:

  • save: Allows the implementation to write NBT data to the world.
  • load: Allows the implementation to read previously saved NBT data.
  • setDirty: A method that must be called after changing the data, to notify the game that there are changes that need to be written. If not called, #save will not get called and the existing data will persist.

The constructor of the class also requires a String. This is the name of the .dat file stored within the data folder for the implemented world. For example, if a WSD was named “example” within the Nether, then a file would be created at ./<level_folder>/DIM-1/data/example.dat.

Attaching to a World

Any WorldSavedData is loaded and/or attached to a world dynamically. As such, if one is never created on a world, then it will not exist.

WorldSavedDatas are created and loaded from the DimensionSavedDataManager, which can be accessed by either ServerChunkProvider#getDataStorage or ServerWorld#getChunkSource. From there, you can get or create an instance of your WSD by calling DimensionSavedDataManager#computeIfAbsent. This will attempt to get the current instance of the WSD if present or create a new one and load all available data.

To persist a WSD across worlds, a WSD should be attached to the Overworld dimension, which can be obtained from MinecraftServer#overworld. The Overworld is the only dimension that is never fully unloaded and as such makes it perfect to store multi-world data on.

Built with MkDocs using a custom theme. Hosted by Read the Docs.
Enable Dark Theme