Posted November 19, 20213 yr 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 November 19, 20213 yr by AMOnDuck spelling error
November 19, 20213 yr Always attach the capability provider to the item and add the check to the getCapability method of the provider instead. AttachCapabilitiesEvent is only fired when items are created
November 19, 20213 yr You should attach it to any itemstacks which might use it at any point in the future (so if is based on an enchantment, you only have to attach it to items which can be affected by that enchantment for example)
November 20, 20213 yr 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.
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.