Player Specific Variable

Started by Ultadoer on Wed, 05/09/2018 - 01:00

Topic category: Help with MCreator software

Last seen on 21:16, 11. Oct 2020
Joined Feb 2018
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Player Specific Variable
Wed, 05/09/2018 - 01:00

How would I make a player specific variable in 1.7.9 mcreator?

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
The way to save any data…
Wed, 05/09/2018 - 15:50

The way to save any data related to a specific player, entity or even ItemStack is definitely capabilities.
First you have to create an interface that will contain all methods that you need for the functioning of your mechanics, but usually, they are just getters/setters for your variables. Then you need another class that implements this interface. Here are the variables declared and modified. Another class you need implements ICapabilitySerializable and it converts the capability to NBT and vice versa, well so does actually also another class that implements IStorage<IExtendedPlayer>. Last class you need is an event handler, where you subscribe for AttachCapabilitiesEvent<Entity> event, check for EntityPlayer and using event.addCapability(ResourceLocation, ICapabilityProvider) you attach the capability to the player.