Jump to content

[1.19.2] Duplicate Capability Key


Darkorg69

Recommended Posts

I have some problems making a Capability work.

Upon joining a world this happens:

Capture.png

Console says:

Spoiler
[03:57:02] [Server thread/ERROR] [ne.mi.ev.EventBus/EVENTBUS]: Exception caught during firing event: Duplicate Capability Key: levelup:playerclass darkorg.levelup.capability.PlayerClassProvider@7ed5e585
	Index: 2
	Listeners:
		0: NORMAL
		1: ASM: darkorg.levelup.event.CapabilityEvents@5752e08e onAttachCapabilities(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V
		2: ASM: darkorg.levelup.event.CapabilityEvents@33e25462 onAttachCapabilities(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V
		3: ASM: darkorg.levelup.event.CapabilityEvents@115c5e72 onAttachCapabilities(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V
		4: ASM: darkorg.levelup.event.CapabilityEvents@76cc5f97 onAttachCapabilities(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V
		5: ASM: darkorg.levelup.event.CapabilityEvents@2104cf21 onAttachCapabilities(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V
java.lang.IllegalStateException: Duplicate Capability Key: levelup:playerclass darkorg.levelup.capability.PlayerClassProvider@7ed5e585
	at TRANSFORMER/[email protected]/net.minecraftforge.event.AttachCapabilitiesEvent.addCapability(AttachCapabilitiesEvent.java:57)
	at TRANSFORMER/[email protected]/darkorg.levelup.event.CapabilityEvents.onAttachCapabilities(CapabilityEvents.java:22)
	at TRANSFORMER/[email protected]/darkorg.levelup.event.__CapabilityEvents_onAttachCapabilities_AttachCapabilitiesEvent.invoke(.dynamic)
	at MC-BOOTSTRAP/net.minecraftforge.eventbus/net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73)
	at MC-BOOTSTRAP/net.minecraftforge.eventbus/net.minecraftforge.eventbus.EventBus.post(EventBus.java:315)
	at MC-BOOTSTRAP/net.minecraftforge.eventbus/net.minecraftforge.eventbus.EventBus.post(EventBus.java:296)
	at TRANSFORMER/[email protected]/net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:510)
	at TRANSFORMER/[email protected]/net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:504)
	at TRANSFORMER/[email protected]/net.minecraftforge.common.capabilities.CapabilityProvider.doGatherCapabilities(CapabilityProvider.java:72)
	at TRANSFORMER/[email protected]/net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:67)
	at TRANSFORMER/[email protected]/net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:51)
	at TRANSFORMER/[email protected]/net.minecraft.world.entity.Entity.<init>(Entity.java:260)
	at TRANSFORMER/[email protected]/net.minecraft.world.entity.LivingEntity.<init>(LivingEntity.java:236)
	at TRANSFORMER/[email protected]/net.minecraft.world.entity.player.Player.<init>(Player.java:179)
	at TRANSFORMER/[email protected]/net.minecraft.server.level.ServerPlayer.<init>(ServerPlayer.java:246)
	at TRANSFORMER/[email protected]/net.minecraft.server.players.PlayerList.getPlayerForLogin(PlayerList.java:417)
	at TRANSFORMER/[email protected]/net.minecraft.server.network.ServerLoginPacketListenerImpl.handleAcceptedLogin(ServerLoginPacketListenerImpl.java:142)
	at TRANSFORMER/[email protected]/net.minecraft.server.network.ServerLoginPacketListenerImpl.tick(ServerLoginPacketListenerImpl.java:76)
	at TRANSFORMER/[email protected]/net.minecraft.network.Connection.tick(Connection.java:274)
	at TRANSFORMER/[email protected]/net.minecraft.server.network.ServerConnectionListener.tick(ServerConnectionListener.java:160)
	at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:910)
	at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:836)
	at TRANSFORMER/[email protected]/net.minecraft.client.server.IntegratedServer.tickServer(IntegratedServer.java:90)
	at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:672)
	at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:244)
	at java.base/java.lang.Thread.run(Thread.java:833)

[03:57:02] [Server thread/ERROR] [minecraft/ServerLoginPacketListenerImpl]: Couldn't place player in world
java.lang.IllegalStateException: Duplicate Capability Key: levelup:playerclass darkorg.levelup.capability.PlayerClassProvider@7ed5e585
	at net.minecraftforge.event.AttachCapabilitiesEvent.addCapability(AttachCapabilitiesEvent.java:57) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23182%23189!/:?] {re:classloading,pl:eventbus:A}
	at darkorg.levelup.event.CapabilityEvents.onAttachCapabilities(CapabilityEvents.java:22) ~[%23188!/:?] {re:classloading}
	at darkorg.levelup.event.__CapabilityEvents_onAttachCapabilities_AttachCapabilitiesEvent.invoke(.dynamic) ~[%23188!/:?] {re:classloading,pl:eventbus:B}
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.3.jar%23107!/:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.3.jar%23107!/:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.3.jar%23107!/:?] {}
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:510) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23182%23189!/:?] {re:classloading}
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:504) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23182%23189!/:?] {re:classloading}
	at net.minecraftforge.common.capabilities.CapabilityProvider.doGatherCapabilities(CapabilityProvider.java:72) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23182%23189!/:?] {re:classloading}
	at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:67) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23182%23189!/:?] {re:classloading}
	at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:51) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23182%23189!/:?] {re:classloading}
	at net.minecraft.world.entity.Entity.<init>(Entity.java:260) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.entity.LivingEntity.<init>(LivingEntity.java:236) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading}
	at net.minecraft.world.entity.player.Player.<init>(Player.java:179) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.level.ServerPlayer.<init>(ServerPlayer.java:246) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.players.PlayerList.getPlayerForLogin(PlayerList.java:417) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading}
	at net.minecraft.server.network.ServerLoginPacketListenerImpl.handleAcceptedLogin(ServerLoginPacketListenerImpl.java:142) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.network.ServerLoginPacketListenerImpl.tick(ServerLoginPacketListenerImpl.java:76) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.network.Connection.tick(Connection.java:274) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading}
	at net.minecraft.server.network.ServerConnectionListener.tick(ServerConnectionListener.java:160) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:910) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:836) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.server.IntegratedServer.tickServer(IntegratedServer.java:90) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:672) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:244) ~[forge-1.19.2-43.1.3_mapped_parchment_2022.08.14-1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:833) [?:?] {}

 

This is my Capability class:

Spoiler
@AutoRegisterCapability
public class PlayerClassCapability implements IPlayerClassCapability {
    IPlayerClass playerClass;

    @Override
    public IPlayerClass getPlayerClass() {
        return this.playerClass;
    }

    @Override
    public void setPlayerClass(IPlayerClass pPlayerClass) {
        this.playerClass = pPlayerClass;
    }

    @Override
    public void resetPlayerClass() {
        this.playerClass = null;
    }

    @Override
    public void saveNBTData(@NotNull CompoundTag nbt) {
        if (this.playerClass != null) {
            nbt.putString("descriptionId", playerClass.getName());
            nbt.putBoolean("isActive", playerClass.isActive());
        }
    }

    @Override
    public void readNBTData(@NotNull CompoundTag nbt) {
        playerClass = PlayerClassUtil.getClassFromString(nbt.getString("pClass"));
        if (playerClass != null) {
            playerClass.setActive(nbt.getBoolean("isActive"));
        }
    }
}

 

This is my CapabilityProvider:

Spoiler
public class PlayerClassProvider implements ICapabilitySerializable<CompoundTag> {
    public static Capability<PlayerClassCapability> PLAYER_CLASS = CapabilityManager.get(new CapabilityToken<>() {
    });

    private PlayerClassCapability playerClassCapability = null;
    private final LazyOptional<PlayerClassCapability> optional = LazyOptional.of(this::createPlayerClass);

    private PlayerClassCapability createPlayerClass() {
        if (this.playerClassCapability == null) {
            this.playerClassCapability = new PlayerClassCapability();
        }
        return this.playerClassCapability;
    }

    @Override
    public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
        if (cap == PLAYER_CLASS) {
            return optional.cast();
        }
        return LazyOptional.empty();
    }

    @Override
    public CompoundTag serializeNBT() {
        CompoundTag nbt = new CompoundTag();
        createPlayerClass().saveNBTData(nbt);
        return nbt;
    }

    @Override
    public void deserializeNBT(CompoundTag nbt) {
        createPlayerClass().readNBTData(nbt);
    }
}

 

AttachCapabilities event:

Spoiler
        @SubscribeEvent
        public void onAttachCapabilities(@NotNull AttachCapabilitiesEvent<Entity> event) {
            if (event.getObject() instanceof Player player) {
                if (!player.getCapability(PlayerClassProvider.PLAYER_CLASS).isPresent()) {
                    event.addCapability(new ResourceLocation(LevelUp.MOD_ID, "playerclass"), new PlayerClassProvider());
                }
            }
        }

 

Edited by Darkorg69
Add image
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.