3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00
Paper/patches/api/0421-Allow-proper-checking-of-empty-item-stacks.patch
Bjarne Koll e1c0033552
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:
2b4b6d14 PR-1023: Convert InventoryView to interface

CraftBukkit Changes:
68603b1c1 Use expanded interaction ranges for traced interact events
eae9f760c PR-1414: Convert InventoryView to interface
ee9eafe67 Fix Implementation for DamageSource#isIndirect for internal custom causing entity
2024-06-16 17:23:42 +02:00

37 Zeilen
1.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aeltumn <daniel@goossens.ch>
Date: Mon, 28 Aug 2023 13:41:09 +0200
Subject: [PATCH] Allow proper checking of empty item stacks
This adds a method to check if an item stack is empty or not. This mirrors vanilla's implementation of the same method.
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index db128d14931ec2afea5205faa58fb5410ec9a54c..9d397c395d777f337a421fac8fea064680065661 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -1017,5 +1017,24 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
public @NotNull ItemStack damage(int amount, @NotNull org.bukkit.entity.LivingEntity livingEntity) {
return livingEntity.damageItemStack(this, amount);
}
+
+ /**
+ * Returns an empty item stack, consists of an air material and a stack size of 0.
+ *
+ * Any item stack with a material of air or a stack size of 0 is seen
+ * as being empty by {@link ItemStack#isEmpty}.
+ */
+ @NotNull
+ public static ItemStack empty() {
+ return new ItemStack();
+ }
+
+ /**
+ * Returns whether this item stack is empty and contains no item. This means
+ * it is either air or the stack has a size of 0.
+ */
+ public boolean isEmpty() {
+ return type.isAir() || amount <= 0;
+ }
// Paper end
}