Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/nms-patches/PlayerInventory.patch

111 Zeilen
3.7 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/PlayerInventory.java
+++ b/net/minecraft/server/PlayerInventory.java
2016-02-29 22:32:46 +01:00
@@ -3,6 +3,14 @@
import java.util.Arrays;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+import java.util.List;
2016-02-29 22:32:46 +01:00
+import org.bukkit.Location;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class PlayerInventory implements IInventory {
2016-02-29 22:32:46 +01:00
public final ItemStack[] items = new ItemStack[36];
@@ -14,6 +22,48 @@
2016-02-29 22:32:46 +01:00
private ItemStack carried;
public boolean f;
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() {
+ ItemStack[] combined = new ItemStack[items.length + armor.length + extraSlots.length];
+ System.arraycopy(items, 0, combined, 0, items.length);
+ System.arraycopy(armor, 0, combined, items.length, armor.length);
+ System.arraycopy(extraSlots, 0, combined, items.length + armor.length, extraSlots.length);
+ return combined;
+ }
+
+ 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;
+ }
2016-02-29 22:32:46 +01:00
+
+ @Override
+ public Location getLocation() {
+ return player.getBukkitEntity().getLocation();
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
public PlayerInventory(EntityHuman entityhuman) {
2016-02-29 22:32:46 +01:00
this.g = new ItemStack[][] { this.items, this.armor, this.extraSlots};
this.player = entityhuman;
2016-05-10 13:47:39 +02:00
@@ -36,6 +86,22 @@
2016-02-29 22:32:46 +01:00
return itemstack.getItem() == itemstack1.getItem() && (!itemstack.usesData() || itemstack.getData() == itemstack1.getData()) && ItemStack.equals(itemstack, itemstack1);
}
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) {
2016-05-10 13:47:39 +02:00
@@ -459,7 +525,7 @@
}
public int getMaxStackSize() {
- return 64;
+ return maxStack; // CraftBukkit
}
2016-02-29 22:32:46 +01:00
public boolean b(IBlockData iblockdata) {
2016-05-10 13:47:39 +02:00
@@ -516,6 +582,11 @@
2016-05-10 13:47:39 +02:00
@Nullable
public ItemStack getCarried() {
+ // CraftBukkit start
2016-02-29 22:32:46 +01:00
+ if (this.carried != null && this.carried.count == 0) {
+ this.setCarried(null);
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
return this.carried;
}