Posted June 3, 201411 yr 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.
June 3, 201411 yr 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
June 4, 201411 yr 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.
June 4, 201411 yr 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.
June 4, 201411 yr 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.
June 5, 201411 yr 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
June 5, 201411 yr I think this tutorial might be help: http://www.minecraftforum.net/topic/1952901-172164-eventhandler-and-iextendedentityproperties/ I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
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.