Can't Save Block NBT Tags

Started by JusThatGuy on

Topic category: Help with modding (Java Edition)

Last seen on 20:27, 2. May 2022
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can't Save Block NBT Tags

I am creating a mod to simulate computers in Minecraft. Basically, I have a computer block that takes information from the player, saves this information via NBT tags, then can use that information to open a browser on your computer and connect to a virtual machine hosted on an enterprise virtualization server. The problems I am currently facing are that the data stored in the NBT tags (1) are reset in a single-player world when I quit out of the world and (2) aren't saved to the item when I break the computer block and re-place it.

Here is some of the Mcreator code where I check to make sure each field matches a regular expression (it shows up as REPLACE in Mcreator, but I change it in the source code), then if they all are correct, I save the information in NBT tags:

https://imgur.com/dA42lgL

Now, in this code snippet is where I check to make sure all the NBT tags are filled with data (it was too long to show the whole line in the picture), and then set the guiMessage global variable to the URL that will be opened with the browser on your computer. The second if statement is just checking for a specific item in hand that would open the configuration GUI, otherwise it attempts to connect to the URL (the "Success!" message is replaced in the source code to open the browser and connect to the URL):

https://imgur.com/rrgWVD0

The reason I need this NBT tag data to remain on the block is because I will have many different computer blocks in a world, each connecting to different virtual machines, so their data will each be very different. So, the behavior I would like to occur is that when a specific computer block is broken in the game, I can re-place it and these NBT tags will keep their values that they had before (this would mean that each computer block with NBT tag data could only be in stacks of one). Also, when a player disconnects from a server, or a single-player world, every computer block should keep the NBT tag data that it had before.

How would I go about doing this? Specific mentions to procedure templates in Mcreator would be greatly appreciated! Thanks to everyone who looks at this in advance.

Last seen on 15:52, 9. May 2023
Joined Mar 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Add an update block function…
Thu, 04/27/2023 - 13:25

Add an update block function at the very bottom and make it update an adjacent block (either the one below or above). That's what fixed it for me, I hope it works for you too! :)