3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-24 15:20:11 +01:00
Paper/nms-patches/PlayerInventory.patch

124 Zeilen
4.1 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/PlayerInventory.java
+++ b/net/minecraft/server/PlayerInventory.java
@@ -5,6 +5,13 @@
2019-04-23 04:00:00 +02:00
import java.util.List;
2018-07-15 02:00:00 +02:00
import java.util.function.Predicate;
+// CraftBukkit start
2016-11-17 02:41:03 +01:00
+import java.util.ArrayList;
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
+
2019-04-23 04:00:00 +02:00
public class PlayerInventory implements IInventory, INamableTileEntity {
2016-11-17 02:41:03 +01:00
public final NonNullList<ItemStack> items;
@@ -16,6 +23,54 @@
2016-02-29 22:32:46 +01:00
private ItemStack carried;
2017-05-19 13:00:13 +02:00
private int h;
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;
+
2016-11-17 02:41:03 +01:00
+ public List<ItemStack> getContents() {
+ List<ItemStack> combined = new ArrayList<ItemStack>(items.size() + armor.size() + extraSlots.size());
2017-05-19 13:00:13 +02:00
+ for (List<net.minecraft.server.ItemStack> sub : this.f) {
2016-11-17 02:41:03 +01:00
+ combined.addAll(sub);
+ }
+
+ return combined;
+ }
+
2016-11-17 02:41:03 +01:00
+ public List<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();
+ }
+
2019-04-23 04:00:00 +02:00
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ 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-11-17 02:41:03 +01:00
this.items = NonNullList.a(36, ItemStack.a);
this.armor = NonNullList.a(4, ItemStack.a);
2019-06-09 00:49:28 +02:00
@@ -41,6 +96,28 @@
2018-07-15 02:00:00 +02:00
return itemstack.getItem() == itemstack1.getItem() && ItemStack.equals(itemstack, itemstack1);
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - Watch method above! :D
+ public int canHold(ItemStack itemstack) {
2016-11-17 02:41:03 +01:00
+ int remains = itemstack.getCount();
+ for (int i = 0; i < this.items.size(); ++i) {
+ ItemStack itemstack1 = this.getItem(i);
+ if (itemstack1.isEmpty()) return itemstack.getCount();
+
+ if (this.a(itemstack1, itemstack)) { // PAIL rename isSimilarAndNotFull
2016-11-17 02:41:03 +01:00
+ remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.getCount();
+ }
2016-11-17 02:41:03 +01:00
+ if (remains <= 0) return itemstack.getCount();
+ }
+ ItemStack offhandItemStack = this.getItem(this.items.size() + this.armor.size());
+ if (this.a(offhandItemStack, itemstack)) {
+ remains -= (offhandItemStack.getMaxStackSize() < this.getMaxStackSize() ? offhandItemStack.getMaxStackSize() : this.getMaxStackSize()) - offhandItemStack.getCount();
+ }
+ if (remains <= 0) return itemstack.getCount();
+
2016-11-17 02:41:03 +01:00
+ return itemstack.getCount() - remains;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
public int getFirstEmptySlotIndex() {
2016-11-17 02:41:03 +01:00
for (int i = 0; i < this.items.size(); ++i) {
if (((ItemStack) this.items.get(i)).isEmpty()) {
2019-06-09 00:49:28 +02:00
@@ -513,8 +590,9 @@
2019-04-23 04:00:00 +02:00
ItemStack itemstack = (ItemStack) this.armor.get(i);
2019-04-23 04:00:00 +02:00
if (itemstack.getItem() instanceof ItemArmor) {
+ int finalI = i; // CraftBukkit - decompile error
itemstack.damage((int) f, this.player, (entityhuman) -> {
- entityhuman.c(EnumItemSlot.a(EnumItemSlot.Function.ARMOR, i));
+ entityhuman.c(EnumItemSlot.a(EnumItemSlot.Function.ARMOR, finalI)); // CraftBukkit - decompile error
});
}
}
2019-06-09 00:49:28 +02:00
@@ -550,6 +628,11 @@
2016-11-17 02:41:03 +01:00
}
public ItemStack getCarried() {
+ // CraftBukkit start
2016-11-17 02:41:03 +01:00
+ if (this.carried.isEmpty()) {
+ this.setCarried(ItemStack.a);
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
return this.carried;
}