Jump to content

[1.12.2 -> 1.13.x] Replacing a removed block (with variants) in the saved world


anothertime

Recommended Posts

Hi!

 

Let's say that in the current version of my mod I have an "ore" block with three blockstate variants: copper (meta==0), tin (meta==1) and lead (meta==2)

 

I want to go ahaed and flatten the block in the next version of the mod to prepare for 1.13 so I will remove the ore block and add the three variants as new blocks.

 

How could I replace the blocks in the actual world save file on loading? 

 

I know I should remap or remove the missing ore block with the MissingMappings event and also that there is a DataFixer for the chunks but from what I can understand in the NBT data I get to datafix there is only the numerical Id of the old ore block along side the meta data corresponding to the blockstate. Is there a way to get the numerical Id of the removed/replaced ore block before my DataFixer run so I could know what Id I should replace with the correct one for one of the new blocks?
 

Thank you!

 

Edit: I checked again the mapping event and there is and Id field in the Mapping class that could be the Id I'm looking for uhm...

Edited by anothertime
Link to comment
Share on other sites

I've actually just implemented a DataFixer for this myself, see this commit of TestMod3.

 

It uses a list of flattening definitions that specify the old registry name and metadata to look for, a function to get the replacement state and a function to modify or remove the saved TileEntity. It then iterates through each block in the chunk NBT looking for ones that match a flattening definition before running the state/TileEntity functions and updating the block.

 

I also have a separate class (Remapper) that handles the MissingMappings event and tells FML to leave the missing IDs in the save, allowing them to be accessed in the DataFixer.

 

There might be better ways to do this, but I'm fairly confident that it works.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

24 minutes ago, anothertime said:

Thank you!

 

So, if my MissingMappings  handler chose to remove the old mapping I wan't be able to see it in the data fixer?

 

Looking at the event and the code around it more closely, I'm not sure you can remove the mapping. I haven't confirmed this, but it looks like the old name and ID remain in the registry even if you choose remap the missing entry. Remapping adds an alias from the old name to the new one that the modder-facing IForgeRegistry methods appear to respect; but the internal ForgeRegistry#getID methods don't appear to.

 

You may want to confirm this yourself.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.