GigaNova Posted May 6, 2013 Share Posted May 6, 2013 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! Quote Link to comment Share on other sites More sharing options...
ZL123 Posted May 6, 2013 Share Posted May 6, 2013 Use an NBT Tag. I think this should work: http://paste.minecraftforge.net/view/432625b0 Quote Thanks...! Link to comment Share on other sites More sharing options...
GigaNova Posted May 6, 2013 Author Share Posted May 6, 2013 Use an NBT Tag. I think this should work: http://paste.minecraftforge.net/view/432625b0 Ehm, sorry if I have to ask, but could you explain that for me? I have this boolean called "DefeatedMob" that is set to true. Quote Link to comment Share on other sites More sharing options...
ZL123 Posted May 6, 2013 Share Posted May 6, 2013 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. Quote Thanks...! Link to comment Share on other sites More sharing options...
GigaNova Posted May 6, 2013 Author Share Posted May 6, 2013 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. Quote Link to comment Share on other sites More sharing options...
ZL123 Posted May 6, 2013 Share Posted May 6, 2013 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. Quote Thanks...! Link to comment Share on other sites More sharing options...
GigaNova Posted May 6, 2013 Author Share Posted May 6, 2013 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"); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.