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

Well i want to save a variable that even after user quit the game it remain the same.So how could i make a file in which i could save it.

Have you searched?  this is well documented.  There is also good examples in the bukkit community that could be cross referenced.

 

After you have done all that, let us know what you had trouble with.

Long time Bukkit & Forge Programmer

Happy to try and help

  • Author

As always: It depends™.

Where does that variable belong to?

To a Block? Use a TileEntity or metadata (only 4 bits, most likely not enough if you say "variable").

To an Item? Use the NBTTagCompound attached to every ItemStack.

To an Entity? Use writeToNBT / readFromNBT or IExtendedEntityProperties in case it is not your entity.

To a specific world (=dimension)? Use WorldSavedData with World#perWorldStorage.

To a save file? Use WorldSavedData with World.mapStorage.

To the Mod in general? Use the Configuration class provided by forge, or just a normal file for more complex data (you can use the normal Java file writing mechanics here).

 

I want to do it on an food item.

Can you give an example on how can i do this.

  • Author

Thanks i am able to add data to nbt but how can i take data from there.

I want to use the if statement for the data in TickHandler.

I dont know how can i check that. If that nbt key have the proper data saved in it.

  • Author

To get the data from the ItemStack you need to get the ItemStack first of course. Where do you want that to be? In the players inventory? Somewhere else?

Well as it is a food item so i wanna check if player has ever eaten this which i am storing in the nbt then on tickhandler i wanna check that if the player has ever eaten that and if true then the process carry on if false than break.

 

Actually i am trying to make an infinite potioneffect for the food. That can last even after the player die or close the game or drink milk. I will add a new item which will break this process.

  • Author

Then... the variable doesn't belong to the Item, because the Item is eaten. -.-

You need to store it into the Player, use IExtendedEntityProperties.

Can you give example on how to use that

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.