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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

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