neoforged / NeoForge

Neo Modding API for Minecraft, based on Forge
https://neoforged.net
Other
1.25k stars 179 forks source link

ItemStack do not provide IAttachmentHolder implementation #1630

Closed flying8lack closed 1 month ago

flying8lack commented 1 month ago

Minecraft Version : 1.21.1

Neoforge version: 21.1.69

Github link to mod: https://github.com/flying8lack/HuntedByBounty/tree/main


@Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
        ItemStack item = player.getMainHandItem();
        int amount = item.getData(ModDataAttachment.CHARGES);
        player.sendSystemMessage(Component.literal("Charges: " + amount));
        item.setData(ModDataAttachment.CHARGES, amount + 1);
        return InteractionResultHolder.success(player.getMainHandItem());
    }

As written in the title, It is impossible to get DataAttachment from ItemStack. player already have IAttachmentHolder, which I was able use as shown below:

@Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
        int amount = player.getData(ModDataAttachment.CHARGES);
        player.sendSystemMessage(Component.literal("Charges: " + amount));
        player.setData(ModDataAttachment.CHARGES, amount + 1);
        return InteractionResultHolder.success(player.getMainHandItem());
    }

The documentation has suggested that ItemStack should have an IAttachmentHolder implementation, which seems to be wrong. Is there something I am missing or is this a bug? thank you for the help.

XFactHD commented 1 month ago

ItemStack is no longer an attachment holder since the introduction of data components in vanilla in 1.20.5. The data attachment docs also mention this.

If there is indeed still a place on the docs that mentions ItemStack as an attachment holder, then that needs to be corrected. Can you link where you found this?