Jump to content

[1.8.9] WorldSavedData not executing readFromNBT [SOLVED]


Atijaf

Recommended Posts

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!

Link to comment
Share on other sites

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:)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.