Jump to content

Permenantly setting booleans and integers?


GigaNova

Recommended Posts

I have a boolean that is set to false.

An event changes this boolean to true.

But after I close minecraft and restart it, its set back to false.

 

I have this problem with an item and my tameable mob (he stops following me after restart).

 

How can I permenantly set this in a save file?

 

Thanks!

Link to comment
Share on other sites

Basically, NBT is a thing that Notch made to save states of things, if I'm not mistaken. Lots of things use it, like Furnaces. I can't really explain it much further.

 

But has your mob class extended EntityTameable? I think that does it for you.

Thanks...!

Link to comment
Share on other sites

Basically, NBT is a thing that Notch made to save states of things, if I'm not mistaken. Lots of things use it, like Furnaces. I can't really explain it much further.

 

But has your mob class extended EntityTameable? I think that does it for you.

I've looked at your code, but I can't find anything that sets the boolean to true.

When a mob is defeated, the boolean is set to true, allowing an item to do something. But how can I do this with NBT?

 

And yes, I have a tamable entity too, that resets after restarts, even tough it extends EntityTameable.

 

Link to comment
Share on other sites

No, you have a method which sets a boolean to true, and when you exit, it will save the boolean to NBT, and when you enter, it will read it from NBT.

I've edited your code, but it still just reverts back to normal after restart.

Here is how it looks:

 

    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setBoolean("defeat", mobisdefeated);
        NBTTagList nbttaglist = new NBTTagList();

        par1NBTTagCompound.setTag("tag", nbttaglist);
    }

public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        NBTTagList nbttaglist = par1NBTTagCompound.getTagList("tag");

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
            byte slot = nbttagcompound1.getByte("Slot");
        }

        mobisdefeated = par1NBTTagCompound.getBoolean("defeat");
    }

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

×
×
  • Create New...

Important Information

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