Jump to content

my int is resetted after closing minecraft in eclipse


knokko

Recommended Posts

hello,

 

I am trying to add mana(magic) to my mod.

I have used "public static int mana" (without the quotes).

I made a block that can show my mana without any problems.

But if I restart minecraft in and outside eclipse, the mana is resetted to 0.

Does anybody know why it resets after I restart minecraft?

Link to comment
Share on other sites

Are you using NBT to save the integer?

-Mitchellbrine

 

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

I don't want your charity, I want your information
Link to comment
Share on other sites

this is not NBT I think.

 

this is written in my main file (Enderpower.class):

 

public static int mana;

 

in one of my wand files(BlastWand.class) is written :

@Override

public ItemStack onItemRightClick(ItemStack itemstack, World world,EntityPlayer player) {

if(Enderpower.mana >= 99){

world.spawnEntityInWorld(new BlastBall(world, player));

Enderpower.mana = Enderpower.mana - 50;

}

 

 

return itemstack;

 

           

        }

 

I hope you understand how it works now.

I dont think this is saved in NBT.

Link to comment
Share on other sites

No it's not (and I'd suggest using spoilers when displaying your code).

 

NBT stands for Named Binary Tags. NBT is Minecraft's way of saving objects. That's how all of the information of your player is saved. That's how TileEntity's save information. There's a good tutorial to look at here. It will show you how to save extra information with the player, so it will persist.

 

I hope this helps!

-Mitchellbrine

 

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

I don't want your charity, I want your information
Link to comment
Share on other sites

To explain the basics a bit more -- Minecraft will only save the stuff it expects to save (in the save game files) unless you add things to save.  A field that you just create in your code will not save automatically since that is never true for programs unless you specifically save and load them to some file.  You're not saving your field to a file, so why would you expect it to be saved?

 

Forge has various methods to help you save.  For example if you're adding values to any entity, including the player, you can use the extended properties which will be saved and loaded for you (if you set it up right).  The tutorial that knokko linked uses this and in fact I think the example used is mana for a player so should be perfect for your case.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.

Announcements



×
×
  • Create New...

Important Information

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