Open Shadows-of-Fire opened 3 months ago
Note that not only EnchantedCountIncreaseFunction#run
would need to be patched for such an event, but also LootItemRandomChanceWithEnchantedBonusCondition#test
. (For example, see the loot table for Zombies.)
EnchantmentHelper::processEquipmentDropChance
also would need a patch specifically checking for looting. This is the method responsible for the chances for dropping e.g. armor worn by monsters.
Since in the first both cases EnchantmentHelper#getEnchantmentLevel
is called and said method now has context to the entity (i.e. player), wouldn't it be possible to add an event there to modify any enchantment level?
The fortune one seems to call the getItemEnchantmentLevel(Holder<Enchantment> holder, ItemStack itemStack)
one
So maybe add the event there and potentially set an entity context in getEnchantmentLevel(Holder<Enchantment> holder, LivingEntity livingEntity)
(which calls the itemstack one)
Meaning the event may or may not have an entity context, depending from where it's called
That might be worth looking into for a separate event. The entity in LootingLevelEvent
is the attacked entity, not the attacker which is passed to getEnchantmentLevel(Holder<Enchantment> holder, LivingEntity livingEntity)
. Also the DamageSource context of LootingLevelEvent
is important (at least I have used it).
So I just implemented a replacement for LootingLevelEvent
in my own library renamed as ComputeEnchantedLootBonusEvent.
I'd much appreciate if someone could just copy / adapt my code to NeoForge, I'm not really familiar with the contribution workflow unfortunately.
Here is the short documentation:
/**
* Called just before a {@link LivingEntity} drops all its loot for determining the level of a loot bonus enchantment
* such as {@link net.minecraft.world.item.enchantment.Enchantments#LOOTING} that should be applied to the drops.
* <p>
* Specifically the event allows for controlling the enchantment level when applying the:
* <ul>
* <li>loot item function <code>minecraft:enchanted_count_increase</code></li>
* <li>loot item condition <code>minecraft:random_chance_with_enchanted_bonus</code></li>
* <li>enchantment effect component <code>minecraft:equipment_drops</code></li>
* </ul>
* <p>
* This event is fired on the {@link NeoForge#EVENT_BUS}.
*/
Key differences from the old event are:
minecraft:looting
, as the relevant loot function / condition now allows for specifying any enchantment, therefore the enchantment holder is passed to the event together with the enchantment levelLivingEntity
(including null
). I have a use case for this where I have a spike block that can have enchantments and should apply those including looting when damaging entities, so in that case the attacker is indeed null
. the event then starts out with an enchantment level of zeroImplementing the event requires these three hooks:
As part of the data-driven Enchantment changes, the way that the original
LootingLevelEvent
worked was inoperable, and as such, the event was dropped.However, there is an opportunity to implement a similar event within
EnchantedCountIncreaseFunction#run
, though it will have to be more broad as this function can be executed with an arbitrary enchantment, instead of being restricted only to Looting.Additionally, we could have this new event cover both fortune and looting, by also firing it from
ApplyBonusCount#run
.