Jump to content

DerpDeBouwerXD

Members
  • Posts

    1
  • Joined

  • Last visited

DerpDeBouwerXD's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I made a few custom capabilities for my mod and I'm trying to use the player clone event to make the capabilities persistent between deaths. If I look at the debugger I can see that the oldPlayer variable has the capabilities and the correct values attached to it. But when I try to use getCapability, it just returns a LazyOptional with null as you would expect when it is not found. Also the ifPresent(...) method does not execute the code inside. I have used the getCapability multiple times already in other parts and never ran into any problem. For example, I've supplied a debug 3 variable from my LivingEntity death event (this part is only active on players) and this one works just fine and returns the capability as you would expect. Does anyone see anything I did wrong or a reason as to why it doesn't work and how to fix this issue? Edit: Solved: I needed to reviveCaps() before I could get them. @SubscribeEvent public void onPlayerClone(PlayerEvent.Clone event) { Player oldPlayer = event.getOriginal(); Player newPlayer = event.getEntity(); var debug = oldPlayer.getCapability(UpgradeDataProvider.UPGRADE_DATA); // This returns a LazyOptional with supplier null var debug2 = newPlayer.getCapability(UpgradeDataProvider.UPGRADE_DATA); // This returns a LazyOptional with a valid supplier and works fine oldPlayer.getCapability(PlayerDataProvider.PLAYER_DATA).ifPresent(oldStore -> { newPlayer.getCapability(PlayerDataProvider.PLAYER_DATA).ifPresent(newStore -> { newStore.copyFrom(oldStore); }); }); // this does absolutely nothing oldPlayer.getCapability(UpgradeDataProvider.UPGRADE_DATA).ifPresent(oldStore -> { newPlayer.getCapability(UpgradeDataProvider.UPGRADE_DATA).ifPresent(newStore -> { newStore.copyFrom(oldStore); }); }); // this doesn't either oldPlayer.getCapability(CurrencyDataProvider.CURRENCY_DATA).ifPresent(oldStore -> { newPlayer.getCapability(CurrencyDataProvider.CURRENCY_DATA).ifPresent(newStore -> { newStore.copyFrom(oldStore); }); }); } // neither does this In the LivingDeath event: var debug3 = player.getCapability(UpgradeDataProvider.UPGRADE_DATA); // This works just fine and returns the capability as expected.
×
×
  • Create New...

Important Information

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