Posted April 28, 201312 yr Basically what the title says. I want the player to unlock a certain power, but since everything restarts at startup of the mod, it resets all the integers back to 0. I want to know if there is a way to save something to the configuration file while in game, so it saves it for later. After looking at a bunch of tutorials for configuration, I'm baffled at how I work with configs. Can anyone help me? (Sorry about it sounding so complicated.) -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
April 29, 201312 yr well theres a variety of ways, you could store in a NBTTagCompound and then use CompressedStreamTools.writeCompressed(NBTTagCompound, OutPutStream); you'd have to set up the output stream public void write(NBTTagCompound yourData, String loc) throws Exception; File f = new File(loc + "filename.dat"); if(!f.exists() &&(!f.mkdirs() | !f.createNewFile())) throw new Exception("Failed to write @" + f.getAbsolutePath()); FileOutputStream out = new FileOuputStream(f); CompressedStreamTools.writeCompressed(yourData, out); out.close(); //ALWAYS ALWAYS ALWAYS CLOSE YOUR STREAMS WHEN THEY ARE OPEN or if you want a modifiable value in a text file you can use a BufferedWriter BufferedWriter b = new BufferedWriter(new FileWriter(File yourFile))); b.close();//ALWAYS or you could always use the plain file output stream FileOutputStream out = new FileOutputStream(File yourFile); out.write(ByteBuffer.wrap(new byte[0]).putInt(yourVal).array()); out.close();//AGAIN and theres many more methods of writing you can find. it depends on what you want. you could even go heavy on the sauce and implement Serializable and writing your whole class, of course delegating transient values- though that's a tad overkill here. I think its my java of the variables.
April 29, 201312 yr Author I sort of get what you're saying. Yet, I sort of don't. Let me explain my situation because I think I would be getting even greater help by detailing. In my mod, the player gets this thing called Stamina after mining up the ore. I want to be able to save that data in, maybe, the level.dat or another dat file, so when the world's opened, it has the saved int. Is there a clear method for that? I just want a way to save the int to be opened later. -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
April 29, 201312 yr Why not use IExtendedEntityProperties? you can directly save it into the player then- I think its my java of the variables.
April 29, 201312 yr Author How do I implement that? -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
April 29, 201312 yr Author RANKSHANK, I implemented it on my main class. Here are my methods. Can you tell me if they work? Here they are: (I don't really need a spoiler) @Override public void saveNBTData(NBTTagCompound compound) { compound.setInteger("Special", Special); compound.setInteger("Valiantite", ValiantActivate); } @Override public void loadNBTData(NBTTagCompound compound) { compound.getInteger("Special"); compound.getInteger("Valiantite"); } @Override public void init(Entity entity, World world) { } Would this work? P.S. Special and ValiantActivate are the integers I was talking about for the mod. -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
April 29, 201312 yr public String registerExtendedProperties(String identifier, IExtendedEntityProperties properties) Grab an isntance of the player and use this to bind your properties to them I think its my java of the variables.
April 29, 201312 yr you are using tick handlers to do that? (the stamina thing). BTW, if u have the instance of the player u could just use player.getEntityData(). EX: public int stamina = 0; some void here or method stamina = player.getEntityData().getInteger("lol") > 0 ? player.getEntityData().getInteger("lol") : 0; //code player.getEntityData().setInteger("lol", stamina);
April 29, 201312 yr Author you are using tick handlers to do that? (the stamina thing). BTW, if u have the instance of the player u could just use player.getEntityData(). EX: public int stamina = 0; some void here or method stamina = player.getEntityData().getInteger("lol") > 0 ? player.getEntityData().getInteger("lol") : 0; //code player.getEntityData().setInteger("lol", stamina); You don't know what I'm saying. I want to know how to SAVE the integer for relogging. It sets the Stamina back to 0 after logging out. The method for setting the int seems like a good idea for setting the int, but I need to know how I can save it. -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
April 30, 201312 yr ehh read my code, its sets the integer stamina (int = integer) after u do your code and before it read from nbt, U CANT SAVE WHEN THE PLAYER LOG OUT BECAUSE A PLAYER CAN EASLY DIRECTLY CLOSES MINECRAFT OR CLOSE THE PROCESS.
April 30, 201312 yr Author opssemnik, I meant when a player leaves the game. I see your code and I think that's a great idea! Thank you! -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
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.