3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-21 05:50:05 +01:00
Paper/nms-patches/PlayerInventory.patch

101 Zeilen
3.0 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/PlayerInventory.java
+++ b/net/minecraft/server/PlayerInventory.java
@@ -2,6 +2,13 @@
import java.util.concurrent.Callable;
+// CraftBukkit start
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class PlayerInventory implements IInventory {
public ItemStack[] items = new ItemStack[36];
2015-02-26 23:41:06 +01:00
@@ -11,6 +18,39 @@
private ItemStack f;
public boolean e;
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+
+ public ItemStack[] getContents() {
+ return this.items;
+ }
+
+ public ItemStack[] getArmorContents() {
+ return this.armor;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner() {
+ return this.player.getBukkitEntity();
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
public PlayerInventory(EntityHuman entityhuman) {
this.player = entityhuman;
2015-02-26 23:41:06 +01:00
}
@@ -43,6 +83,22 @@
return -1;
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - Watch method above! :D
+ public int canHold(ItemStack itemstack) {
+ int remains = itemstack.count;
+ for (int i = 0; i < this.items.length; ++i) {
+ if (this.items[i] == null) return itemstack.count;
+
+ // Taken from firstPartial(ItemStack)
+ if (this.items[i] != null && this.items[i].getItem() == itemstack.getItem() && this.items[i].isStackable() && this.items[i].count < this.items[i].getMaxStackSize() && this.items[i].count < this.getMaxStackSize() && (!this.items[i].usesData() || this.items[i].getData() == itemstack.getData()) && ItemStack.equals(this.items[i], itemstack)) {
+ remains -= (this.items[i].getMaxStackSize() < this.getMaxStackSize() ? this.items[i].getMaxStackSize() : this.getMaxStackSize()) - this.items[i].count;
+ }
+ if (remains <= 0) return itemstack.count;
+ }
+ return itemstack.count - remains;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
public int getFirstEmptySlotIndex() {
for (int i = 0; i < this.items.length; ++i) {
2015-02-26 23:41:06 +01:00
if (this.items[i] == null) {
@@ -390,7 +446,7 @@
}
public int getMaxStackSize() {
- return 64;
+ return maxStack; // CraftBukkit
}
public boolean b(Block block) {
2015-02-26 23:41:06 +01:00
@@ -466,6 +522,11 @@
}
public ItemStack getCarried() {
+ // CraftBukkit start
+ if (this.f != null && this.f.count == 0) {
+ this.setCarried(null);
+ }
+ // CraftBukkit end
return this.f;
}