Jump to content

Recommended Posts

Posted

The only thing I want is to save a custom number on the player. The only way that I can think of that works is by using capabilities. The only problem is that I don't know how they work. I took a look at the EnergyStorage class to see what things I need. The things that I have is an interface to store the data, a class that implements that interface and INBTSerializable, and a class to register the capability, just like in EnergyStorage. But I still don't understand what classes I'm missing to attach it to the player. Anyone can help?

Posted

Eya!

That's my capabilities system: https://github.com/Zanckor/Dragon-Ball-Z/tree/main/src/main/java/com/zanckor/capabilities

I think, you can keep Capabilities.class like already is.
On IMyCapability, you need to put your values, like:

int getNumber();
void setNumer(int NUM); #to set your value to X
void addNumber(int value); #to add X to your value

 

On MyCapabilityAttacher.class just put your MODID
On MyCapabilityImplementation.class delete my values and put yours
 

I hope that can help you

Posted

Thanks @Zanckor for your reply. It turns out I still needed a CapabilityProvider to provide an instance of the capability. I don't really know why this has to be a LazyOptional, but it works as long as I keep my checking code in the IfPresent method. However, I want the data to remain after a player dies. Inside the forge documentations they already pointed out to do it using the PlayerEvent$Clone event, but I still don't get enough context. Is there a needly way to copy the data over to the respawned player.

Posted (edited)
  On 6/27/2022 at 9:27 AM, Migats said:

However, I want the data to remain after a player dies. Inside the forge documentations they already pointed out to do it using the PlayerEvent$Clone event, but I still don't get enough context. Is there a needly way to copy the data over to the respawned player.

Expand  

*Don't read that, is not about capabilities

 

Ya, you need to use Clone event, so, where you are registrying your data, you need to add an PlayerEventClone and add your data.

For example, I've a class called "assignStat.java", here I've a method called "assignStatsOnLoggin" and "assignStatsOnClone", both method have the same code, but "assignStatsOnClone" is PlayerEvent.Clone

That's because when you die or teleport all your data is deleted and recreated in a new entity, so, you need to put your data again

Edited by Zanckor
Posted
  On 6/27/2022 at 9:40 AM, Zanckor said:

For example, I've a class called "assignStat.java", here I've a method called "assignStatsOnLoggin" and "assignStatsOnClone", both method have the same code, but "assignStatsOnClone" is PlayerEvent.Clone

Expand  

I still don't get what is going on. The assignStatsOnClone method is modifying the attributes, but I couldn't find a reference to the capabilities itself.

I tried a not so needly code by getting both capabilities and using a variable. It doesn't work. For some reason the capabilities are declared as invalidated during the PlayerEvent.Clone, and I can't figure out how to fix that.

Posted (edited)
  On 6/27/2022 at 12:11 PM, Migats said:

I still don't get what is going on. The assignStatsOnClone method is modifying the attributes, but I couldn't find a reference to the capabilities itself.

I tried a not so needly code by getting both capabilities and using a variable. It doesn't work. For some reason the capabilities are declared as invalidated during the PlayerEvent.Clone, and I can't figure out how to fix that.

Expand  

Oh wait, my bad lmao, try calling your data inside a CloneEvent to assign them again

Like docs say: "reading the data from the original entity and assigning it to the new entity"

 

Thats a CapabilityProvider that maybe can help you: https://github.com/MinecraftForge/MinecraftForge/blob/1.18.x/src/main/java/net/minecraftforge/common/capabilities/CapabilityProvider.java

 

And a 1.17 topic with the same question:

 

Edited by Zanckor
Posted

It works. The mistake that I made in the first place, is that I didn't know what player instance needs to revive its capabilities. The method is called after the new player is created and so the old player needs to have the capabilities revived and not the new one. It makes a lot of sense now that I understand it.

  • Like 1

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi! I've been running a server on Minecraft using the Prodigium Reforged pack on curse forge using the site exaroton. It was working fine until randomly encountering this error every time anyone tries to connect to the server, I've already reloaded backups and deleted json files  Here is the crash report https://mclo.gs/EwKw51q. Thanks for the help in advance
    • nevermind i figured out the issue  
    • I was trying to host a server with the 1.21.1 cobbleverse forge mod, but when I tried starting it, it kept giving me this error. Crash report here: https://pastebin.com/AsE1X5QY   Thanks
    • This mod lets you choose an element power, Earth, Wind, Fire, or Water. Also two secret element powers Light and Darkness. Each power gives good a bad things, Earth lets you dig through anything but ores and bedrock, Wind lets you jump high in the air every three seconds, Fir lets you throw fire balls and you are immune to any flame/lava but you can't go into water or else you take damage, Water you swim and break blocks under water quicker and you can get rid of water like a sponge but you take more damage when in fire/lava, Light makes you faster at day but slower at night you are able to throw light spears that do four hearts and can go through any armor, Darkness let's you be faster at night but slower at day mobs don't harm you but peaceful mobs run away from you you are able to spawn ink creatures around you that are like dogs but are stronger. another thing in the mod is that there are other dimensions that can get you ores to make better armor and weapons, each dimensions are are good for a certain element though each dimension has a boss depending on which dimension one dimension has more than one boss, each elements are required to defeat the bosses with each others help.
    • Read the posts above yours, it tells you exactly how to do it, instructions are the same if it's making a forge installation or a vanilla one, just make a new folder for the game directory.
  • Topics

×
×
  • Create New...

Important Information

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