Jump to content

Capability disappearing/not reattaching


AMOnDuck

Recommended Posts

I have a cooldown capability that I want to attach to items with specific enchants and it attaches fine when loading in but when you drop the item or enchant an existing item with the target enchant it won't attach.
Here's the relevant code

    @Mod.EventBusSubscriber(modid = PondWeaponMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
    public static class Events {
        @SubscribeEvent
        public static void attachCapabilityEnchantedItemEvent(AttachCapabilitiesEvent<ItemStack> event) {
            if(event.getObject() instanceof ItemStack) {
                if (!event.getObject().getStack().getEnchantmentTagList().isEmpty()){
                    System.out.println(event.getObject().getStack().getEnchantmentTagList());
                    if (EnchantmentHelper.getEnchantments(event.getObject().getStack()).get(ModEnchantments.thunder) != null) {
                        event.addCapability(new ResourceLocation(PondWeaponMod.MODID, "cooldown"), new CooldownCapability());
                    }
                }
            }
        }
    }

Any ideas on how to properly handle this?

Edited by AMOnDuck
spelling error
Link to comment
Share on other sites

  • AMOnDuck changed the title to Capability disappearing/not reattaching

Note that enchanting an existing item does not call AttachCapabilities because it's adding data to an existing item stack, not creating a new one.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.