From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Mon, 28 Apr 2025 22:51:32 +0800 Subject: [PATCH] Leaves: Fix SculkCatalyst exp skip Co-authored by: violetc <58360096+s-yh-china@users.noreply.github.com> As part of: Leaves (https://github.com/LeavesMC/Leaves/blob/f553c53e4230aa032e54a69b6479f1959ed24a60/leaves-server/minecraft-patches/features/0120-Fix-SculkCatalyst-exp-skip.patch) Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java index af0a5766ff344bdaa602a6ee35726fef41fbb95d..05e8a20cbba8bbba6062cba9076555ba384335e0 100644 --- a/net/minecraft/server/level/ServerPlayer.java +++ b/net/minecraft/server/level/ServerPlayer.java @@ -1300,7 +1300,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc } // SPIGOT-5478 must be called manually now - if (event.shouldDropExperience()) this.dropExperience(this.level(), cause.getEntity()); // Paper - tie to event + if (shouldDropExperience(event.shouldDropExperience(), event.forceUseEventDropStatus())) this.dropExperience(this.level(), cause.getEntity()); // Paper - tie to event // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory. if (!event.getKeepInventory()) { // Paper start - PlayerDeathEvent#getItemsToKeep @@ -1347,6 +1347,15 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc this.setClientLoaded(false); } + // Leaves start - exp fix + private boolean shouldDropExperience(boolean eventResult, boolean forceUseEvent) { + if (forceUseEvent) { + return eventResult; + } + return wasExperienceConsumed() ? false : eventResult; + } + // Leaves end - exp fix + private void tellNeutralMobsThatIDied() { AABB aabb = new AABB(this.blockPosition()).inflate(32.0, 10.0, 32.0); this.level() diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java index 5f58cbbc48045dfeb418e3b604e6172b4c39249d..1f41c14a146c9e412fe6f6d9d362208ddbd40e6c 100644 --- a/net/minecraft/world/entity/LivingEntity.java +++ b/net/minecraft/world/entity/LivingEntity.java @@ -277,6 +277,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin private Waypoint.Icon locatorBarIcon = new Waypoint.Icon(); // CraftBukkit start public int expToDrop; + public int expToReward; // Leaves - exp fix public List drops = new java.util.ArrayList<>(); // Paper - Restore vanilla drops behavior public final org.bukkit.craftbukkit.attribute.CraftAttributeMap craftAttributes; public boolean collides = true; @@ -1879,6 +1880,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin entity.killedEntity((ServerLevel) this.level(), this); } this.gameEvent(GameEvent.ENTITY_DIE); + if (!this.wasExperienceConsumed()) this.dropExperience((ServerLevel) this.level(), damageSource.getEntity()); // Leaves - exp fix } else { this.dead = false; this.setHealth((float) deathEvent.getReviveHealth()); @@ -1952,7 +1954,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin this.drops = new java.util.ArrayList<>(); // this.dropEquipment(level); // CraftBukkit - moved up // CraftBukkit end - this.dropExperience(level, damageSource.getEntity()); + // this.dropExperience(level, damageSource.getEntity()); // Leaves - exp fix return deathEvent; // Paper } diff --git a/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java b/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java index 91ddb30cd98b11f70b196a108e7cc11d39ca1a71..ebc8d936d8796f869dfe264c0f4523115389fea8 100644 --- a/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java +++ b/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java @@ -96,8 +96,7 @@ public class SculkCatalystBlockEntity extends BlockEntity implements GameEventLi public boolean handleGameEvent(ServerLevel level, Holder gameEvent, GameEvent.Context context, Vec3 pos) { if (gameEvent.is(GameEvent.ENTITY_DIE) && context.sourceEntity() instanceof LivingEntity livingEntity) { if (!livingEntity.wasExperienceConsumed()) { - DamageSource lastDamageSource = livingEntity.getLastDamageSource(); - int experienceReward = livingEntity.getExperienceReward(level, Optionull.map(lastDamageSource, DamageSource::getEntity)); + int experienceReward = livingEntity.expToReward; // Leaves - exp fix if (livingEntity.shouldDropExperience() && experienceReward > 0) { this.sculkSpreader.addCursors(BlockPos.containing(pos.relative(Direction.UP, 0.5)), experienceReward); this.tryAwardItSpreadsAdvancement(level, livingEntity);