Hunternif Posted December 17, 2015 Posted December 17, 2015 I call world.loadItemData(clazz, dataID) in an item's onUpdate() to load and render some data attached to the item. In 1.7.10 it used to work fine, but in 1.8 it would suddenly return null for the same dataID after I walk into a Nether portal. Does anyone know what changed in the logic of WorldSavedData and world.loadItemData()? I've yet to look deeper into this issue, I'm just asking in case anyone has already figured out how WorldSavedData works. Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
Hunternif Posted December 17, 2015 Author Posted December 17, 2015 The code is probably a bit too long and convoluted to post as is, let me try to explain one more time what is happening on an abstract level. My item is basically a map that updates constantly based on your surroundings. The data is saved to a WorldSavedData instance with the current world. As long as I stay in one dimension (e.g. overworld) all the data is saved correctly, and is correctly loaded when I log out and back in. On each tick in Item.onUpdate() and GuiScreen.updateScreen() I call world.loadItemData() to update its content and load it for rendering. If world.loadItemData() returns null, I assume I have never visited this dimension before, and create a new WorldSavedData instance and save it by calling world.setItemData(). However, in 1.8 something strange happens when I change dimensions. As soon as I load in a new world, even if I have previously visited it before and have saved some data (which is evident by the presence of the corresponding <data_key>.dat file in the world data folder), world.loadItemData() returns null. I don't know if it would eventually "remember" the old WorldSavedData it had, because I immediately replace it with a new instance, as explained in the previous paragraph. This only happens on the client side, and it doesn't happen with identical code in 1.7.10. If I log out and back in, the old WorldSaveData of the current dimension is loaded correctly again. If I change dimensions, the data gets lost on the client until the end of this session. Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
Hunternif Posted December 17, 2015 Author Posted December 17, 2015 I probably decided to use world.loadItemData because this data pertains to a particular item, like it does with Minecraft maps. Should I still prefer world.perWorldStorage if I'm using it for data tied to an item? UPDATE: I switched to perWorldStorage, and the same issue is still present. Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
Hunternif Posted December 17, 2015 Author Posted December 17, 2015 I think I'm starting to understand it a little better. I store all data for one map for all dimensions at once in one WorldSavedData instance. So I expect the same instance to be loaded from within any dimension. I think I prefer to have it like this in one file, as opposed to saving a new file per each dimension for each map. UPDATE: Naturally, I don't expect the client to actually save any data locally on its own. When the player first logs in, the server sends the data over in a packet. The packet would contain map data for all dimensions at once, and the client would show the corresponding portion depending on where the player currently is. Now I tried a little cheat, to re-send all this data again when the player changes dimensions, and voila, it is now loaded correctly. Although all the actual data for this dimension has already been sent to the client with the first packet, and loads correctly without additional "reminders" of this sort in 1.7.10. Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
Hunternif Posted December 17, 2015 Author Posted December 17, 2015 I see. Somehow I did experience a different behavior when debugging 1.7.10, but I can see now that it was not intended. If I mean to have keep one instance of WorldSavedData for all dimensions at once, do you think it would be a good idea to have a cache for it on the client, and store the data instance once it is first loaded? Thank you for you help! Quote I made Moses Mod, Dota 2 Items Mod, Rings of Power and Antique Atlas.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.