Posted June 26, 20223 yr 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?
June 26, 20223 yr 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
June 27, 20223 yr Author 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.
June 27, 20223 yr 2 hours ago, 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. *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 June 27, 20223 yr by Zanckor
June 27, 20223 yr Author 2 hours ago, 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 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.
June 27, 20223 yr 27 minutes ago, 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. 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 June 27, 20223 yr by Zanckor
June 27, 20223 yr Author 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.
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.