3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/patches/server/0903-Add-getDrops-to-BlockState-and-isPreferredTool-to-Bl.patch
Nassim Jahnke dcc290167f
Updated Upstream (Bukkit/CraftBukkit/Spigot)
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:
dea9ce0a SPIGOT-7198: Add Sittable interface to Camel

CraftBukkit Changes:
eecb4c0dc SPIGOT-7196: Exception loading alternate worlds
0ff61e8fa SPIGOT-7198: Add Sittable interface to Camel
676441aac PR-1121: Handle additional missing SpawnEggs in MetaSpawnEgg
e85280e02 Handle missing SpawnEggs in MetaSpawnEgg

Spigot Changes:
d90018e0 SPIGOT-7199: NPE loading or creating world with custom chunk generator
2022-12-08 11:53:14 +01:00

62 Zeilen
2.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MelnCat <melncatuwu@gmail.com>
Date: Fri, 12 Aug 2022 23:24:37 -0700
Subject: [PATCH] Add getDrops to BlockState and isPreferredTool to BlockData
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
index 966ac60daebb7bb211ab8096fc0c5f33db67320a..a8ab1d3ee81664193be39d2735d6495136e0e310 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
@@ -330,5 +330,33 @@ public class CraftBlockState implements BlockState {
public boolean isCollidable() {
return this.data.getBlock().hasCollision;
}
+
+ @Override
+ public java.util.Collection<org.bukkit.inventory.ItemStack> getDrops() {
+ return this.getDrops(null);
+ }
+
+ @Override
+ public java.util.Collection<org.bukkit.inventory.ItemStack> getDrops(org.bukkit.inventory.ItemStack item) {
+ return this.getDrops(item, null);
+ }
+
+ @Override
+ public java.util.Collection<org.bukkit.inventory.ItemStack> getDrops(org.bukkit.inventory.ItemStack item, org.bukkit.entity.Entity entity) {
+ net.minecraft.world.item.ItemStack nms = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(item);
+
+ // Modelled off EntityHuman#hasBlock
+ if (item == null || !data.requiresCorrectToolForDrops() || nms.isCorrectToolForDrops(data)) {
+ return net.minecraft.world.level.block.Block.getDrops(
+ data,
+ world.getHandle(),
+ position,
+ world.getHandle().getBlockEntity(position), entity == null ? null :
+ ((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandle(), nms
+ ).stream().map(org.bukkit.craftbukkit.inventory.CraftItemStack::asBukkitCopy).toList();
+ } else {
+ return java.util.Collections.emptyList();
+ }
+ }
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
index 6f7ee97e381e80d6e8cf6b9c3f40b5e25f6bf64b..1fefe185800dd48dd328697127405e0844543e5e 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
@@ -623,4 +623,12 @@ public class CraftBlockData implements BlockData {
return this.state.isRandomlyTicking();
}
// Paper end
+
+ // Paper start - Preferred tool API
+ @Override
+ public boolean isPreferredTool(org.bukkit.inventory.ItemStack item) {
+ net.minecraft.world.item.ItemStack nms = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(item);
+ return !state.requiresCorrectToolForDrops() || nms.isCorrectToolForDrops(state);
+ }
+ // Paper end
}