From 82a20911cb3f7292f314e4735afb2f60a8179820 Mon Sep 17 00:00:00 2001 From: Take Weiland Date: Tue, 8 Feb 2022 21:39:01 +0100 Subject: [PATCH] Re-added the patch for LivingExperienceDropEvent and enable it for dragons (#8388) --- .../world/entity/LivingEntity.java.patch | 10 ++++++ .../boss/enderdragon/EnderDragon.java.patch | 32 +++++++++++++++++++ .../living/LivingExperienceDropEvent.java | 12 +++++-- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch b/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch index 45641c4a44..8d34067a9c 100644 --- a/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch @@ -228,6 +228,16 @@ } protected void m_5907_() { +@@ -1306,7 +_,8 @@ + + protected void m_21226_() { + if (this.f_19853_ instanceof ServerLevel && (this.m_6124_() || this.f_20889_ > 0 && this.m_6149_() && this.f_19853_.m_46469_().m_46207_(GameRules.f_46135_))) { +- ExperienceOrb.m_147082_((ServerLevel)this.f_19853_, this.m_20182_(), this.m_6552_(this.f_20888_)); ++ int reward = net.minecraftforge.event.ForgeEventFactory.getExperienceDrop(this, this.f_20888_, this.m_6552_(this.f_20888_)); ++ ExperienceOrb.m_147082_((ServerLevel)this.f_19853_, this.m_20182_(), reward); + } + + } @@ -1322,7 +_,8 @@ ResourceLocation resourcelocation = this.m_5743_(); LootTable loottable = this.f_19853_.m_142572_().m_129898_().m_79217_(resourcelocation); diff --git a/patches/minecraft/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java.patch b/patches/minecraft/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java.patch index 1b767f5ee4..8353cf3faa 100644 --- a/patches/minecraft/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java.patch @@ -1,5 +1,17 @@ --- a/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java +++ b/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java +@@ -150,7 +_,11 @@ + return adouble; + } + ++ @javax.annotation.Nullable private Player unlimitedLastHurtByPlayer = null; + public void m_8107_() { ++ // lastHurtByPlayer is cleared after 100 ticks, capture it indefinitely in unlimitedLastHurtByPlayer for LivingExperienceDropEvent ++ if (this.f_20888_ != null) this.unlimitedLastHurtByPlayer = f_20888_; ++ if (this.unlimitedLastHurtByPlayer != null && this.unlimitedLastHurtByPlayer.m_146910_()) this.unlimitedLastHurtByPlayer = null; + this.m_146874_(); + if (this.f_19853_.f_46443_) { + this.m_21153_(this.m_21223_()); @@ -420,7 +_,7 @@ BlockPos blockpos = new BlockPos(k1, l1, i2); BlockState blockstate = this.f_19853_.m_8055_(blockpos); @@ -9,6 +21,26 @@ flag1 = this.f_19853_.m_7471_(blockpos, false) || flag1; } else { flag = true; +@@ -514,7 +_,8 @@ + + if (this.f_19853_ instanceof ServerLevel) { + if (this.f_31084_ > 150 && this.f_31084_ % 5 == 0 && flag) { +- ExperienceOrb.m_147082_((ServerLevel)this.f_19853_, this.m_20182_(), Mth.m_14143_((float)i * 0.08F)); ++ int award = net.minecraftforge.event.ForgeEventFactory.getExperienceDrop(this, this.unlimitedLastHurtByPlayer, Mth.m_14143_((float)i * 0.08F)); ++ ExperienceOrb.m_147082_((ServerLevel)this.f_19853_, this.m_20182_(), award); + } + + if (this.f_31084_ == 1 && !this.m_20067_()) { +@@ -527,7 +_,8 @@ + this.f_20883_ = this.m_146908_(); + if (this.f_31084_ == 200 && this.f_19853_ instanceof ServerLevel) { + if (flag) { +- ExperienceOrb.m_147082_((ServerLevel)this.f_19853_, this.m_20182_(), Mth.m_14143_((float)i * 0.2F)); ++ int award = net.minecraftforge.event.ForgeEventFactory.getExperienceDrop(this, this.unlimitedLastHurtByPlayer, Mth.m_14143_((float)i * 0.2F)); ++ ExperienceOrb.m_147082_((ServerLevel)this.f_19853_, this.m_20182_(), award); + } + + if (this.f_31073_ != null) { @@ -847,6 +_,16 @@ public boolean m_6072_() { diff --git a/src/main/java/net/minecraftforge/event/entity/living/LivingExperienceDropEvent.java b/src/main/java/net/minecraftforge/event/entity/living/LivingExperienceDropEvent.java index e549625758..5485a55577 100644 --- a/src/main/java/net/minecraftforge/event/entity/living/LivingExperienceDropEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/living/LivingExperienceDropEvent.java @@ -1,6 +1,6 @@ /* * Minecraft Forge - * Copyright (c) 2016-2021. + * Copyright (c) 2016-2022. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -23,6 +23,8 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.eventbus.api.Cancelable; +import javax.annotation.Nullable; + /** * Event for when an entity drops experience on its death, can be used to change * the amount of experience points dropped or completely prevent dropping of experience @@ -31,12 +33,12 @@ import net.minecraftforge.eventbus.api.Cancelable; @Cancelable public class LivingExperienceDropEvent extends LivingEvent { - private final Player attackingPlayer; + @Nullable private final Player attackingPlayer; private final int originalExperiencePoints; private int droppedExperiencePoints; - public LivingExperienceDropEvent(LivingEntity entity, Player attackingPlayer, int originalExperience) + public LivingExperienceDropEvent(LivingEntity entity, @Nullable Player attackingPlayer, int originalExperience) { super(entity); @@ -54,6 +56,10 @@ public class LivingExperienceDropEvent extends LivingEvent this.droppedExperiencePoints = droppedExperience; } + /** + * @return The player that last attacked the entity and thus caused the experience. This can be null, in case the player has since logged out. + */ + @Nullable public Player getAttackingPlayer() { return attackingPlayer;