Posted October 5, 20177 yr Hello. Lately I have been experimenting with all sort of things. After getting an idea about adding "abilities" I wanted to start working for it right away. What I want to do, is, to give each player an "ability" or more like a "profession". For example: Each player starts at level 0 at Alchemy. And the level progresses as the player completes different tasks and unlocks new things.And of course it will be more than one ability. So how I would go about adding a variable which holds the level of a specific "profession" to every player who connects in the world? I think with the old way you had to do something with ExtendedEntityProperties (Something along the lines of that), but forge has changed so much in the last couple of MC versions, I don't even know where to start. Someone can point me out the right way, or maybe can link me to an example, I would greatly appreciate it. Thank you for your time!
October 5, 20177 yr I think you'd want to use capabilities. The docs have some basic information on it. But basically, you create a custom capability class which handles the readNBT and writeNBT functions to save/load. Then create a class handler that catches the event attachCapability. Register handler with the bus to receive events (mod pre-init?). A search on github should provide some examples of actual use.
October 5, 20177 yr just dug this one up from one I bookmarked awhile ago. Think most of it is current. https://www.planetminecraft.com/blog/forge-tutorial-capability-system/
October 5, 20177 yr I have tutorial on capabilities here as well: http://jabelarminecraft.blogspot.com/p/minecraft-17x.html Check out my tutorials here: http://jabelarminecraft.blogspot.com/
October 6, 20177 yr Author Well, thank you so much for your help guys, I will surely try this out now. I am also sorry for the late response, I was busy last day and didn't have time to get into Forge. EDIT: After having a quick look into @jabelar tutorial, I have one question to ask. In my case, If i were to add more than one "profession", (e.g: Mining, Enchanting), can I do this in one single interface, or do I need to create different interfaces and capabilities for each and every profession. Edited October 6, 20177 yr by Cerandior Added a question
October 6, 20177 yr Think either, just a question of proper serialization and deserization of the data when you readNBT and writeNBT in the capabilities. Personally, I'd go for a single Profession capability that held a map<profession,level> or keep it in a NBTTagList that held NBTTagCompounds (String profession,int level). iterate through list during readNBT, writeNBT. storing data in NBTList might make reading and writing easy. Probably create a public on the capability that handles the lookup for you. public int getProfessionLevel(String profession){ //find level via map or list and return }
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.