Jump to content

[1.12] Add a variable for all the players


Cerandior

Recommended Posts

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!

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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 by Cerandior
Added a question
Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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