Jump to content

Recommended Posts

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?

 

Posted

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.

Announcements



×
×
  • Create New...

Important Information

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