Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Problems with FluidTank NBT read/write


grand_mind1
 Share

Recommended Posts

I ran into some trouble when using the NBT read/write methods of FluidTank. The writeToNBT() method creates a string tag with the key "Empty" if the fluid being saved is null. However, this tag is never removed if the same compound is written to with fluid present. This means that the first time the tank saves while empty, it will never be able to be read from properly again, because the readFromNBT() method simply sets the fluid to null if the "Empty" tag is present. I understand that I can solve this problem by creating a new tag every time I write and save all of my other data to it as well, however this problem seems like an oversight.

Link to comment
Share on other sites

I don't think that's true.

public FluidTank readFromNBT(NBTTagCompound nbt)
    {
        if (!nbt.hasKey("Empty"))
        {
            FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt);
            setFluid(fluid);
        }
        else
        {
            setFluid(null);
        }
        return this;
    }

    public NBTTagCompound writeToNBT(NBTTagCompound nbt)
    {
        if (fluid != null)
        {
            fluid.writeToNBT(nbt);
        }
        else
        {
            nbt.setString("Empty", "");
        }
        return nbt;
    }

Link to comment
Share on other sites

I think you're misunderstanding. That code is entirely relevant, it's the two methods this post is about in the first place. You're claiming that they function in a way they do not.

Yes, the fluidstack the tank creates will be null, because the "empty" tag is present. You are correct in saying that the data saved to the compound in writeToNBT() will not be null, however that is irrelevant as it will never be read.

Link to comment
Share on other sites

It will never be read because the "Empty" tag is present. It doesn't matter what other data is there, if the "Empty" tag is present, the fluid is set to null.

The "Empty" tag is created in writeToNBT() of FluidTank if there is no fluid. Meaning that if I ever save the tank while it is empty, it will never be read from properly again. This is because the "Empty" tag is not removed if I write with fluid present.

Link to comment
Share on other sites

You really don't understand. I am using one NBTTagCompound. Let's say I write some tank data to it while the tank has some water in it. This works fine and can be read later. Now, I remove the water and save. Because the fluid was null, the "empty" tag was added to the compound. If I add water again and write, it will still be read as empty because the tag was not removed on write.

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.

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Your report is very hard to actually understand. Your best bet is to stop trying to 'describe' the issue and provide the actual tag files and  what you are expecting to happen. Because all of our tests in tags work just fine. Also, there is no 'registering' of tag in the sense you're talking about. All tags are 'registered' when they are read from disc in one pass. So ya, provide us a test case of your tags and we'll see if it's a real issue or not.
    • Minecraft Version: 1.16.5 Forge Version: 36.2.0 Description of issue: A loaded mod containing data pack tag registries, which creates new tags and references the new tags to further register the items in existing tags fails to register anything in the existing tags. Example: Tinkers Construct v3.1.2.265 contains Json files to register: forge:ingots/cobalt as a new tag containing cobalt_ingot and add to previously registered tag forge:ingots. In the file for forge:ingots, values of "tconstruct:seared_brick", "tconstruct:scorched_brick", "#forge:ingots/copper", "#forge:ingots/cobalt", etc. are indicated. In-game, none of the items listed as values are tagged under forge:ingots, however the new tags including forge:ingots/cobalt include the items tagged in those files. Further, copying the json file for forge:ingots and placing in a later applied datapack, such as Kubejs, and reloading, properly registers the forge:ingots tags. This would appear to be an issue with timing of registering the new tags. Before copying the json file to a datapack, the existing tag (forge:ingots) appears to be handled first, which containing references to new tags that are not yet processed (forge:ingots/cobalt) fails and does not register any of the appended values. But in the second instance because the copied json file is processed after the mod jar file as a whole, the new tags exist and the appending of the new values succeeds. While I have given Tinkers construct as an example I have viewed the same issue with multiple mods, each of which uses references to new tags in an appending of an existing tag. Likewise, mods that do not exhibit this behavior use explicit item listings rather than referencing a new tag. I looked through the log files and did not identify any error or other message relating to the registration of tags in general or specifically these exemplar tags.
    • Debug.log here: https://gist.github.com/DexTGS/4f33065cbe2ad844b76ed1b1890fd069 . Game crashing once I die.
    • I'm making a mob like zombified piglin except instead of all the mobs getting mad at you I want to make it do they all go into a panic. How can I do this?
    • What. Just register your events in your mod constructor or use the class annotation.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.