#Bundle enchantment

4 messages · Page 1 of 1 (latest)

rose iron
#

I am making an enchantment for the bundle which would allow it to store items. To do this, I am using a ModifyReturnValue into getWeight() of BundleContents. I need to check the level of the enchantment on the item within that method, however, to get a Holder<Enchantment>, I need the Level. Is there a way I can access the level from BundleContents?

@ModifyReturnValue(method = "getWeight", at = @At("RETURN"))
    private static Fraction getWeight(Fraction original, ItemStack item) {
        int capacityLevel = item.getEnchantments().getLevel(ModEnchantmentHelper.getHolder(ModEnchantments.CAPACITY.getKey(), LEVEL));
        return original.divideBy(Fraction.getFraction(capacityLevel > 0 ? capacityLevel / 2f : 1));
    }
prisma plume
#
int enchantLevel = stack.getOrDefault(
  DataComponentTypes.ENCHANTMENTS,
  ItemEnchantmentsComponent.DEFAULT)
.getEnchantmentEntries()
.stream()
.filter(entry->entry.getKey().matchesId(YOURENCHANTMENTID))
.findFirst()
.orElse(0);

alternatively, could use matchesKey
also, this is yarn mapping

rose iron
#

Turns out this is a lot more complicated than I thought

#

I need to add to BundleContents codec an float capacityMultiplier and set it when the component is first created