Paper/patches/unapplied/server/0984-Properly-handle-experience-dropping-on-block-break.patch

95 lines
7.0 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Sat, 30 Dec 2023 15:00:06 -0500
Subject: [PATCH] Properly handle experience dropping on block break
This causes spawnAfterBreak to spawn xp by default, removing the need to manually add xp wherever this method is used.
For classes that use custom xp amounts, they can drop the resources with disabling
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
Updated Upstream (Bukkit/CraftBukkit) (#10379) Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: f02baa38 PR-988: Add World#getIntersectingChunks(BoundingBox) 9321d665 Move getItemInUse up to LivingEntity 819eef73 PR-959: Add access to current item's remaining ticks c4fdadb0 SPIGOT-7601: Add AbstractArrow#getItem be8261ca Add support for Java 22 26119676 PR-979: Add more translation keys 66753362 PR-985: Correct book maximum pages and characters per page documentation c8be92fa PR-980: Improve getArmorContents() documentation f1120ee2 PR-983: Expose riptide velocity to PlayerRiptideEvent CraftBukkit Changes: dfaa89bbe PR-1369: Add World#getIntersectingChunks(BoundingBox) 51bbab2b9 Move getItemInUse up to LivingEntity 668e09602 PR-1331: Add access to current item's remaining ticks a639406d1 SPIGOT-7601: Add AbstractArrow#getItem 0398930fc SPIGOT-7602: Allow opening in-world horse and related inventories ffd15611c SPIGOT-7608: Allow empty lists to morph to any PDT list 2188dcfa9 Add support for Java 22 45d6a609f SPIGOT-7604: Revert "SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime" 06d915943 SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime ca3bc3707 PR-1361: Add more translation keys 366c3ca80 SPIGOT-7600: EntityChangeBlockEvent is not fired for frog eggs 06d0f9ba8 SPIGOT-7593: Fix sapling growth physics / client-side updates 45c2608e4 PR-1366: Expose riptide velocity to PlayerRiptideEvent 29b6bb79b SPIGOT-7587: Remove fixes for now-resolved MC-142590 and MC-109346
2024-04-06 21:53:39 +02:00
index e881ed9de9d864e0522e1f7f97dc3debf57cf4b6..cedde2235227eb5820beefb98549994e1cca1198 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2024-02-01 10:15:57 +01:00
@@ -625,7 +625,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
if (drop) {
BlockEntity tileentity = iblockdata.hasBlockEntity() ? this.getBlockEntity(pos) : null;
- Block.dropResources(iblockdata, this, pos, tileentity, breakingEntity, ItemStack.EMPTY);
+ Block.dropResources(iblockdata, this, pos, tileentity, breakingEntity, ItemStack.EMPTY, false); // Paper - Properly handle xp dropping
+ iblockdata.getBlock().popExperience((ServerLevel) this, pos, xp, breakingEntity); // Paper - Properly handle xp dropping; custom amount
}
boolean flag1 = this.setBlock(pos, fluid.createLegacyBlock(), 3, maxUpdateDepth);
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
2024-02-01 10:15:57 +01:00
index c4bf01177b2dfcc88f6992dc85de216d448a79f8..6896d46fce2e466ebee23ac2dc00312ec1beefdb 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
2024-02-01 10:15:57 +01:00
@@ -321,23 +321,31 @@ public class Block extends BlockBehaviour implements ItemLike {
for (ItemStack drop : Block.getDrops(state, serverLevel, pos, blockEntity)) {
items.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(drop));
}
+ Block block = state.getBlock(); // Paper - Properly handle xp dropping
2024-02-01 10:15:57 +01:00
io.papermc.paper.event.block.BlockBreakBlockEvent event = new io.papermc.paper.event.block.BlockBreakBlockEvent(org.bukkit.craftbukkit.block.CraftBlock.at(levelAccessor, pos), org.bukkit.craftbukkit.block.CraftBlock.at(levelAccessor, source), items);
+ event.setExpToDrop(block.getExpDrop(state, serverLevel, pos, net.minecraft.world.item.ItemStack.EMPTY, true)); // Paper - Properly handle xp dropping
event.callEvent();
2024-02-01 10:15:57 +01:00
for (org.bukkit.inventory.ItemStack drop : event.getDrops()) {
popResource(serverLevel, pos, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(drop));
}
2024-02-01 10:15:57 +01:00
- state.spawnAfterBreak(serverLevel, pos, ItemStack.EMPTY, true);
+ state.spawnAfterBreak(serverLevel, pos, ItemStack.EMPTY, false); // Paper - Properly handle xp dropping
+ block.popExperience(serverLevel, pos, event.getExpToDrop()); // Paper - Properly handle xp dropping
}
return true;
}
// Paper end - Add BlockBreakBlockEvent
public static void dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack tool) {
+ // Paper start - Properly handle xp dropping
+ dropResources(state, world, pos, blockEntity, entity, tool, true);
+ }
+ public static void dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack tool, boolean dropExperience) {
+ // Paper end - Properly handle xp dropping
if (world instanceof ServerLevel) {
Block.getDrops(state, (ServerLevel) world, pos, blockEntity, entity, tool).forEach((itemstack1) -> {
Block.popResource(world, pos, itemstack1);
});
- state.spawnAfterBreak((ServerLevel) world, pos, tool, true);
+ state.spawnAfterBreak((ServerLevel) world, pos, tool, dropExperience); // Paper - Properly handle xp dropping
}
}
2024-02-01 10:15:57 +01:00
@@ -421,7 +429,7 @@ public class Block extends BlockBehaviour implements ItemLike {
player.awardStat(Stats.BLOCK_MINED.get(this));
player.causeFoodExhaustion(0.005F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.BLOCK_MINED); // CraftBukkit - EntityExhaustionEvent
if (includeDrops) { // Paper - fix drops not preventing stats/food exhaustion
- Block.dropResources(state, world, pos, blockEntity, player, tool);
+ Block.dropResources(state, world, pos, blockEntity, player, tool, dropExp); // Paper - Properly handle xp dropping
} // Paper - fix drops not preventing stats/food exhaustion
}
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
2024-02-01 10:15:57 +01:00
index e57e3a26b0fb856e1ab693df5783fe8b9bee9719..64300077fce6eb28b6bddd42b3467eaa4c80c9f5 100644
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -1183,6 +1183,7 @@ public abstract class BlockBehaviour implements FeatureElement {
public void spawnAfterBreak(ServerLevel world, BlockPos pos, ItemStack tool, boolean dropExperience) {
this.getBlock().spawnAfterBreak(this.asState(), world, pos, tool, dropExperience);
+ if (dropExperience) {getBlock().popExperience(world, pos, this.getBlock().getExpDrop(asState(), world, pos, tool, true));} // Paper - Properly handle xp dropping
}
public List<ItemStack> getDrops(LootParams.Builder builder) {
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
index 461a66c323a74db5a70981fafc5fa20f54f0f40d..ac11f18690434922179b61ffcc3036dea025b0cb 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
@@ -509,7 +509,7 @@ public class CraftBlock implements Block {
// Modelled off EntityHuman#hasBlock
if (block != Blocks.AIR && (item == null || !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata))) {
- net.minecraft.world.level.block.Block.dropResources(iblockdata, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem);
+ net.minecraft.world.level.block.Block.dropResources(iblockdata, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem, false); // Paper - Properly handle xp dropping
// Paper start - improve Block#breanNaturally
if (triggerEffect) {
if (iblockdata.getBlock() instanceof net.minecraft.world.level.block.BaseFireBlock) {