Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

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.

  • Author

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?

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.