Jump to content

How do you add to a block class without breaking existing worlds?


Lycanus Darkbinder

Recommended Posts

I noticed while debugging and testing that if you add methods to a block's class and then load a world where blocks have already been placed, it will crash:

 

"error while ticking block"

 

I'm not talking about changing block IDs or anything crazy like that, simply adding a few new methods (no, not removing methods). How does one go about updating their mod or adding new features after it's been released to the public without breaking the worlds people have built?

 

I can't put my finger on it yet but sometimes I have to delete my test world or it simply crashes over and over after making changes. I assumed that as long as you weren't deleting methods then it would be fine.

Link to comment
Share on other sites

The worlds only store Block ID's and metadata, unless there are TE's involved :)

 

If you give us the crash logs and a more detailed description of what you are trying to do, then we should be better able to help you :)

 

 

edit: Are you replacing the block entierly or are you manipulating it's class file by ASM?

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

I don't have a crash log at the moment but if I get another I'll definitely post it.

 

I'm not using ASM but there are TileEntities involved. What I did was place a block to see if the TileEntity's fields were set properly, then I quit the game and added a couple new methods to the block's class file and I think one new method to the TileEntity.

 

When I started the world again it crashed instantly with that "error ticking block". I had to delete the world and recreate it.

 

I was under the impression that the TileEntity would still function because Minecraft doesn't save the actual TileEntity but rather it's fields. When you load your world it calls createNewTileEntity which returns a blank TileEntity that is then populated from readNBT(). This should allow you to add new features without breaking existing worlds.

Link to comment
Share on other sites

Well, it is likely that you tried to use or load data that didn't exist the first time you placed the block and saved it.

You would need to catch those cases and save some default value.

 

NBT returns zero on an attempt to retrieve a value for a key that has not been saved. None of the fields in my TileEntity would cause a crash with a value of zero. Worst case is the block would display the wrong texture or light value, or allow someone who is not the block's owner to interact with it.

Link to comment
Share on other sites

I was thinking about List, Map, Arrays or other data structure rather than a simple int.

 

Oh, I don't store anything that complex.

 

I only track the owner of the block (string) so not just anyone can fiddle with it as well as a few integers and floats. That's why I was surprised when it crashed after making a change.

 

More than likely I did something I shouldn't but I'll have to wait until next time because once I remade the world it stopped crashing. I'm certain it had to do with my TileEntity though because the offending class is the only one that makes use of it.

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.