Class CustomPlayerSave
- All Implemented Interfaces:
IPlayerLoadListener,IPlayerSaveListener
Some benefits of this approach include:
- No risk of corrupting vanilla player data.
- Custom data survives player respawn.
- Custom data survives mod being uninstalled temporarily.
This implementation will invoke savePlayer(Player) when the vanilla player data is written to disk. You can
use this method to pull data from your own in-memory sources and store it in the resulting NBT tag. Once this tag is
generated it will be saved to the disk as a compressed NBT file. A backup save file will also be generated and
maintained to help players rollback their data in the event of corruption or other adverse circumstances. Loading
your custom data is done in loadPlayer(Player, CompoundTag) which is invoked after vanilla has loaded their
player data. You can use this method to restore your in-memory player data.
Files will be saved within subdirectories of the vanilla player folder. These subdirectories are based on the
handlerId provided when constructing your implementation.
-
Field Summary
Fields inherited from interface com.faux.customentitydata.api.playersaves.IPlayerLoadListener
EVENTFields inherited from interface com.faux.customentitydata.api.playersaves.IPlayerSaveListener
EVENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidloadPlayer(net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag saveData) Loads custom data for a player from NBT.voidloadPlayerData(net.minecraft.world.entity.player.Player player, Path saveDir) Called when a player's data is loaded directly from the disk.abstract net.minecraft.nbt.CompoundTagsavePlayer(net.minecraft.world.entity.player.Player player) Saves custom data for a player as an NBT.voidsavePlayerData(net.minecraft.world.entity.player.Player player, Path saveDir) Called when a player's data is saved directly to the disk.
-
Constructor Details
-
CustomPlayerSave
public CustomPlayerSave(net.minecraft.resources.Identifier handlerId)
-
-
Method Details
-
savePlayer
public abstract net.minecraft.nbt.CompoundTag savePlayer(net.minecraft.world.entity.player.Player player) Saves custom data for a player as an NBT. This is invoked after the vanilla player data has been saved.- Parameters:
player- The player being saved.- Returns:
- The data to save for the player.
-
loadPlayer
public abstract void loadPlayer(net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag saveData) Loads custom data for a player from NBT. This is invoked after the vanilla player data has been loaded.- Parameters:
player- The player being loaded.saveData- The data for the player. If the player has no existing data an empty tag will be provided.
-
loadPlayerData
Description copied from interface:IPlayerLoadListenerCalled when a player's data is loaded directly from the disk.- Specified by:
loadPlayerDatain interfaceIPlayerLoadListener- Parameters:
player- The player that is being loaded.saveDir- The save folder.
-
savePlayerData
Description copied from interface:IPlayerSaveListenerCalled when a player's data is saved directly to the disk.- Specified by:
savePlayerDatain interfaceIPlayerSaveListener- Parameters:
player- The player that is being saved.saveDir- The save folder.
-