Move World Storage Handling into ImmersiveHandler
hammy275 opened this issue ยท 4 comments
A new interface, WorldStorageHandler
, will be created that extends ImmersiveHandler
. WorldStorageHandler
will add a bunch of new functions to implement such that the handler now determines how to handle all aspects of World Storage, rather than it being hard-coded.
This will both help code organization and allow the eventual ImmersiveMC API to allow other mods to create immersives backed with world storage.
Note: Due to the changes in 1.5.0, ImmersiveStorage
is now server-side only again, and thus, I'm going to rewrite it as part of this.
The actual plan for implementing this:
WorldStorage
- A new interface,
WorldStorage
will be created, which contains the functions below. This is similar in concept toHandlerStorage
, but for saving to/loading from the world file, rather than for encoding/decoding through the network.load(CompoundTag nbt)
: Loads the NBT tag into this instancesave(CompoundTag nbt)
: Saves this instance to NBT
WorldStorageHandler
- A new interface,
WorldStorageHandler
will be created, extendingImmersiveHandler
. This will now determine whether an immersive uses world storage or not, allowing us to remove theusesWorldStorage()
function. - This interface contains the following new functions that require implementation by those extending this interface:
createNewStorage()
: Returns aWorldStorage
containing no data. This is similar in concept togetEmptyHandler()
(which I should really rename togetEmptyStorage()
).
WorldStorages
- Effectively the replacement for
GetStorage
. Contains the following functions that I will be implementing:getStorageForBlock(BlockPos pos, Level level)
: Gets theWorldStorage
(see above) for the given block at the given position.markDirty()
: Marks the storages dirty, so that saving to disk is performed at next save time.onBreak()
: Called when the immersive is broken to drop items on the ground (or whatever the immersive wants to do). This is always called beforeonStopTracking()
.
Other Changes
- The
TYPE
of the storage is now a dead concept, as instead theResourceLocation
provided byImmersiveHandler#getID()
will double as the identifier on-disk to determine which handler to use. - All parts of the old system (mainly the original
ImmersiveStorage
implementation andGetStorage
) will be removed. ImmersiveMCLevelStorage#load()
should now handle all conversions for all storages at startup, rather than converting on the fly.ImmersiveMCLevelStorage
should load/save a version number,2
. If it's not found, assume it's1
(the storage system up to this point).- The intention here is to increment this number whenever changes are made to the save data format so we can easily detect when we need to upgrade.
- I'll write a class implementation of
WorldStorage
,ItemWorldStorage
that most immersives can use and/or build off of.
Have made a lot of progress. Here's what's left:
- Move the Tinkers' Construct table over to the new system.
- Figure out what to do about the bag crafting storage. The new system is built explicitly around being tied to an
ImmersiveHandler
, so bags go against that. - Delete all the old code.
- Rename
ImmersiveMCLevelStorageV2
toImmersiveMCLevelStorage
- Merge the world storages with the network storages, if possible.
- Version number for player storages.
- Add upgrade code to handle the old saved data structure.
- Add upgrade code for 1.19-->1.20 smithing table.
- Large amounts of testing (especially around upgrade code)
- Cherry pick to other Minecraft versions.
- 1.20.2
- 1.20.1
- 1.19.4
- 1.19.3
- 1.19.2
- 1.18.2
Moving Player Storages (so far just the backpack):
Player storages consist of the following to function on the server-side:
InteractPacket
: For interacting with player storages. C-->S to perform an interaction.FetchPlayerStoragePacket
: For getting player storage. C-->S to request and S-->C with inventory data.- The old
ImmersiveStorage
system.
Note that encoding is currently done by reading/writing NBT into/out of the buffer.
The only goal of this is to remove ImmersiveStorage
, NOT to introduce a flexible system as currently-exists for block-based immersives. With that in mind, here's the plan:
InteractPacket
will be kept, but its support for interacting with block immersives will be removed (it goes unused as of the 1.5.0 dev cycle), and cleaned up, since the file is a bit unintuitive.FetchPlayerStoragePacket
will be renamed toFetchBackpackStoragePacket
andInteractPacket
will be renamed toBackpackInteractPacket
.- String identifiers for the backpack storage in the packets will be removed.
ImmersiveMCPlayerStorage
will use lists of items as the value in the map, rather thanImmersiveStorage
instances.ImmersiveMCPlayerStorage
will store data for bags without making it too inconvenient to add more data in the future, and will store a version number to keep track of save data upgrades.