Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

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
  • Author

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.

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

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/

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.