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.

Featured Replies

Posted

Hello, in my mod, I create data with NBTTagCompound and I use the methods: ChuckDataEvent (Save and Load) and ChunkEvent (Unload). Backup works and loading too.

The problem is that when I want to delete the NBT when the player loads the chuck, it works but if the player quits Minecraft and reopens the game. The NBT is added even if it has been deleted during the last connection...

How can I fix this?

 

  • Author

This is my code:

	@SubscribeEvent
	public void saveEnchBlock(ChunkDataEvent.Save data)
	{
		for (NBTTagCompound nbt : this.blockEnchList)
    	{
    		if (nbt != null)
			{
				NBTTagList nbtList = this.getBlockEnchList(nbt);

				for (int y = 0; y < nbtList.tagCount(); y++)
				{
					NBTTagCompound tag = nbtList.getCompoundTagAt(y);
					
					for (int size = 0; size < this.blockEnchList.size(); size++)
					{
						if (tag != null)
						{
							BlockPos pos = new BlockPos(tag.getInteger("x"), tag.getInteger("y"), tag.getInteger("z"));
							IBlockState state = world.getBlockState(pos);
							Block block = state.getBlock();
                          
                            if (block != null && !(block instanceof BlockLiquid) && !(block instanceof BlockFire) && block != Blocks.AIR)
            	        	{
    							data.getData().setTag("Block_ENCH" + "_" + size, tag);
            	        	}
                          
                          	else if (block == null || block instanceof BlockLiquid || block instanceof BlockFire || block == Blocks.AIR)
                            {
                                this.removeBlockEnch(tag);
                            }
                        }
                    }
                }
            }
        }
	}

	@SubscribeEvent
	public void loadEnchBlock(ChunkDataEvent.Load data)
	{
		for (int j = 1; j < data.getData().getSize(); j++)
		{
			if (data.getData().hasKey("Block_ENCH" + "_" + j, 10))
			{
            	NBTTagCompound tag = data.getData().getCompoundTag("Block_ENCH" + "_" + j);

            	if (tag != null && !tag.hasNoTags())
            	{
            		World world = data.getWorld();
            		
            		if (world != null && !world.isRemote && tag.hasKey("x", 99) && tag.hasKey("y", 99) && tag.hasKey("z", 99))
            		{
                    	this.addNBTToList(tag); //This is the method to add the registered nbt to my blockEnchList.
                      	data.getData().removeTag("Block_ENCH" + "_" + j);
                      	this.removeNBTTagCompound(tag); //It's for more security.
                    }
                }
              	else
                {
                 	data.getData().removeTag("Block_ENCH" + "_" + j);
                    this.removeNBTTagCompound(tag); //It's for more security too.
                }
            }
        }
    }

(There are small bugs with the rendering in my code)...

Guest
This topic is now closed to further replies.

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.