Jump to content

Strange Itemstack NBT behaviour


Quarg

Recommended Posts

I have a staff item that I want to have drain energy on usage, the current way I have it set up is that this function in the staff class is called via a tickhandler:

public float doDrawEnergy(ItemStack item, EntityPlayer player, float energy)
    {
        if(item.getTagCompound().getFloat("charge") > energy)
        {
            item.setTagInfo("charge", new NBTTagFloat("charge",item.getTagCompound().getFloat("charge") - energy));
            return energy;
        }
        else
        {
            float out = item.getTagCompound().getFloat("charge");
            item.setTagInfo("charge", new NBTTagFloat("charge",0));
            return out;
        }
    }

The problem is that the "charge" nbt value doesn't always change, specifically it only that the getFloat function only returns the latest set value after opening a GUI (ie: it only seems to upate the value after opening a GUI), and I have absoluetly no idea why or how this happens.

Link to comment
Share on other sites

  • 2 months later...

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

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

Announcements



×
×
  • Create New...

Important Information

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