Posted April 26, 20169 yr What would cause #readFromNBT to not be called? I have a class that extends WorldSavedData and that class overrides both writeToNBT and readFromNBT. get method public static WorldData get(World world) { WorldData data = (WorldData) world.loadItemData(WorldData.class, IDENTITY); if(data == null) { data = new WorldData(); world.setItemData(IDENTITY, data); } return data; } I use the get method and call #markDirty(). It then runs through #writeToNBT and I store data within the nbt. I am fairly certain it is writing data correctly, but for some unknown reason, #readFromNBT is never called. Am I suppose to register my class somewhere or... Thanks!
April 27, 20169 yr In 1.8.0, I used: world.getPerWorldStorage().setData("unique_tag_name", nbttag); I'm not sure if 1.8.9 changed that to just World#setItemData, but it might be worth looking into. http://i.imgur.com/NdrFdld.png[/img]
April 27, 20169 yr Author Just tried what you suggested. Unfortunately, #readFromNBT is still not being called. Here's my class. Maybe I messed up somewhere http://pastebin.com/BzynggZ7
April 27, 20169 yr How do you know it is not being called vs. simply failing? For example, you use NBT.TAG_LIST, but you are not storing a list of lists, you are storing a list of NBTTagCompounds, so you should be using that constant instead (the constant is the type of tag stored in the list, not the list itself). http://i.imgur.com/NdrFdld.png[/img]
April 27, 20169 yr Author While debugging, I have a breakpoint at where #readFromNBT starts. Nothing ever happens for me there. I run it in debug mode. //Instead of this NBTTagList list = nbt.getTagList(IDENTITY, NBT.TAG_LIST); //I should do this? NBTTagList list = nbt.getTagList(IDENTITY, NBT.TAG_COMPOUND); //Because the integer passed is the type of NBT's the list is holding? Thanks for clarifying that bit up, was a little bit confused as to how that worked:)
April 27, 20169 yr Yep, in your case (which is the typical case), you should use NBT.TAG_COMPOUND when retrieving your list. If your #readFromNBT is never getting called, is your static #get method ever called? How about #writeToNBT? Also, I'm a little dubious about your use of long as a storage method for potentially an entire chunk's worth of data... while it may work most of the time if you generally need to store only a few positions per chunk, it seems extremely fragile to me for very little benefit. Of course, I don't know the whole story, so maybe you will only ever have 1 or 2 positions per chunk and that's fine, but something to consider. http://i.imgur.com/NdrFdld.png[/img]
April 27, 20169 yr Author I do call the #get method. After marking it dirty and it saves, #writeToNBT is called. I have a hierarchy of lists within lists... This is saved within nbt in a long. The chunk requires about 48 bits, (22 bits x coord, 22 bits z coord, 4 bits dimension) in order to cover the Minecraft world of chunks and in which dimension they belong. Then, within the chunk, I store the x, y, and z coords (4 bits, 8 bits, 4 bits), taking up a total of 64 bits. (During ram usage) So, in other words, A chunk needs 48 bits, and each block within needs 16. I do see your point on storing a long within the nbt... I'll work on that after getting the #readFromNBT to work. Perhaps I just need to update my forge version. I'll mess around with the code a little bit. Thanks for the help thus far.
April 27, 20169 yr Author Am I suppose to call the get method in order for it to run #readFromNBT? I do call it, but is there a certain place that I'm suppose to do that? Also, I get this error [03:54:14] [server thread/INFO] [FML]: Loading dimension 0 (New World) (net.minecraft.server.integrated.IntegratedServer@359173ac) [03:54:14] [server thread/INFO] [FML]: Loading dimension 1 (New World) (net.minecraft.server.integrated.IntegratedServer@359173ac) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: java.lang.RuntimeException: Failed to instantiate class MCO.World.WorldData [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.world.storage.MapStorage.loadData(MapStorage.java:59) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at MCO.World.WorldData.get(WorldData.java:26) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at MCO.Events.PlayerEvents.worldEvent(PlayerEvents.java:433) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_PlayerEvents_worldEvent_Load.invoke(.dynamic) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:49) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:140) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:100) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:127) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:508) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at java.lang.Thread.run(Unknown Source) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: Caused by: java.lang.NoSuchMethodException: MCO.World.WorldData.<init>(java.lang.String) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: at java.lang.Class.getConstructor0(Unknown Source) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: at java.lang.Class.getConstructor(Unknown Source) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: at net.minecraft.world.storage.MapStorage.loadData(MapStorage.java:55) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: ... 9 more [03:54:14] [server thread/INFO] [FML]: Loading dimension -1 (New World) (net.minecraft.server.integrated.IntegratedServer@359173ac) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: java.lang.RuntimeException: Failed to instantiate class MCO.World.WorldData [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.world.storage.MapStorage.loadData(MapStorage.java:59) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at MCO.World.WorldData.get(WorldData.java:26) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at MCO.Events.PlayerEvents.worldEvent(PlayerEvents.java:433) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_PlayerEvents_worldEvent_Load.invoke(.dynamic) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:49) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:140) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:100) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:127) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:508) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at java.lang.Thread.run(Unknown Source) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: Caused by: java.lang.NoSuchMethodException: MCO.World.WorldData.<init>(java.lang.String) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: at java.lang.Class.getConstructor0(Unknown Source) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: at java.lang.Class.getConstructor(Unknown Source) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: at net.minecraft.world.storage.MapStorage.loadData(MapStorage.java:55) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: ... 9 more [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: java.lang.RuntimeException: Failed to instantiate class MCO.World.WorldData [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.world.storage.MapStorage.loadData(MapStorage.java:59) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at MCO.World.WorldData.get(WorldData.java:26) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at MCO.Events.PlayerEvents.worldEvent(PlayerEvents.java:433) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_PlayerEvents_worldEvent_Load.invoke(.dynamic) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:49) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:140) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:100) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:127) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:508) [03:54:14] [server thread/INFO] [sTDERR]: [net.minecraft.world.storage.MapStorage:loadData:70]: at java.lang.Thread.run(Unknown Source) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: Caused by: java.lang.NoSuchMethodException: MCO.World.WorldData.<init>(java.lang.String) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: at java.lang.Class.getConstructor0(Unknown Source) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: at java.lang.Class.getConstructor(Unknown Source) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: at net.minecraft.world.storage.MapStorage.loadData(MapStorage.java:55) [03:54:14] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: ... 9 more
April 27, 20169 yr Author Thank you! I was missing the constructor you mentioned. That fixed the problem.
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.