mirror of
https://github.com/neoforged/NeoForge.git
synced 2026-10-12 02:19:42 +00:00
Fix several minor issues with the enchanted loot events (#3620)
This commit is contained in:
+4
-2
@@ -1,12 +1,14 @@
|
||||
--- a/net/minecraft/world/level/storage/loot/predicates/BonusLevelTableCondition.java
|
||||
+++ b/net/minecraft/world/level/storage/loot/predicates/BonusLevelTableCondition.java
|
||||
@@ -37,6 +_,10 @@
|
||||
@@ -37,6 +_,12 @@
|
||||
public boolean test(LootContext context) {
|
||||
ItemInstance tool = context.getOptional(LootContextParams.TOOL);
|
||||
int level = tool != null ? EnchantmentHelper.getItemEnchantmentLevel(this.enchantment, tool) : 0;
|
||||
+
|
||||
+ // Neo: Allow mods to modify the enchantment level for loot calculations with relevant context.
|
||||
+ level = net.neoforged.neoforge.event.EventHooks.getBlockLootEnchantmentLevel(tool, this.enchantment, level, context);
|
||||
+ if (tool != null) {
|
||||
+ level = net.neoforged.neoforge.event.EventHooks.getBlockLootEnchantmentLevel(tool, this.enchantment, level, context);
|
||||
+ }
|
||||
+
|
||||
float chance = this.values.get(Math.min(level, this.values.size() - 1));
|
||||
return context.getRandom().nextFloat() < chance;
|
||||
|
||||
@@ -1202,7 +1202,7 @@ public class EventHooks {
|
||||
/// @param enchLevel The original enchantment level. How it gets determined depends on the particular call site. Generally it's the attacker's effective enchantment level.
|
||||
/// @param ctx The loot context for the current entity loot evaluation.
|
||||
public static int getEntityLootEnchantmentLevel(Holder<Enchantment> ench, int enchLevel, LootContext ctx) {
|
||||
Entity entity = ctx.getOptional(LootContextParams.THIS_ENTITY);
|
||||
Entity entity = ctx.getOptional(LootContextParams.ATTACKING_ENTITY);
|
||||
DamageSource src = ctx.getOptional(LootContextParams.DAMAGE_SOURCE);
|
||||
if (src != null && entity instanceof LivingEntity living) {
|
||||
var event = new EnchantedEntityLootEvent(living, src, ench, enchLevel);
|
||||
|
||||
@@ -15,7 +15,6 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceWit
|
||||
import net.neoforged.neoforge.event.entity.living.GetEquipmentDropChanceEvent;
|
||||
import net.neoforged.neoforge.event.entity.living.LivingEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/// Fired on the server when an entity is dropping loot and the level of a specific enchantment is being queried.
|
||||
///
|
||||
@@ -26,7 +25,6 @@ import org.jspecify.annotations.Nullable;
|
||||
///
|
||||
/// If you do not need the additional context of this event, prefer [GetEnchantmentLevelEvent] for managing enchantment levels.
|
||||
public class EnchantedEntityLootEvent extends LivingEvent {
|
||||
@Nullable
|
||||
private final DamageSource damageSource;
|
||||
private final Holder<Enchantment> enchantment;
|
||||
private int enchantmentLevel;
|
||||
|
||||
Reference in New Issue
Block a user