mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-24 00:33:49 -07:00
See the corresponding Bukkit commit for details. Implementation details: - Any packets that include an itemstack will send air stacks as null; maybe this will even eliminate the client crash that occurs if the client receives an air stack - Better handling of null itemstacks in general (ie less converting them to air stacks) - Inventory.setContents() can now take an array smaller than the inventory without error - Player.updateInventory() should now correctly update the result slot in a crafting inventory Some small credit goes to Afforess (initial implementation of openInventory() methods) and Drakia (initial implementation of InventoryOpenEvent and InventoryCloseEvent).
121 lines
2.8 KiB
Java
121 lines
2.8 KiB
Java
package net.minecraft.server;
|
|
|
|
// CraftBukkit start
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
import org.bukkit.entity.HumanEntity;
|
|
import org.bukkit.event.inventory.InventoryType;
|
|
import org.bukkit.inventory.InventoryHolder;
|
|
// CraftBukkit end
|
|
|
|
public class InventoryCrafting implements IInventory {
|
|
|
|
private ItemStack[] items;
|
|
private int b;
|
|
private Container c;
|
|
|
|
// CraftBukkit start
|
|
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
|
public CraftingRecipe currentRecipe;
|
|
public IInventory resultInventory;
|
|
|
|
public ItemStack[] getContents() {
|
|
return this.items;
|
|
}
|
|
|
|
public void onOpen(CraftHumanEntity who) {
|
|
transaction.add(who);
|
|
}
|
|
|
|
public InventoryType getInvType() {
|
|
return items.length == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH;
|
|
}
|
|
|
|
public void onClose(CraftHumanEntity who) {
|
|
transaction.remove(who);
|
|
}
|
|
|
|
public List<HumanEntity> getViewers() {
|
|
return transaction;
|
|
}
|
|
|
|
public InventoryHolder getOwner() {
|
|
return null; // TODO: Crafting grids don't really have an owner? Maybe they should?
|
|
}
|
|
// CraftBukkit end
|
|
|
|
public InventoryCrafting(Container container, int i, int j) {
|
|
int k = i * j;
|
|
|
|
this.items = new ItemStack[k];
|
|
this.c = container;
|
|
this.b = i;
|
|
}
|
|
|
|
public int getSize() {
|
|
return this.items.length;
|
|
}
|
|
|
|
public ItemStack getItem(int i) {
|
|
return i >= this.getSize() ? null : this.items[i];
|
|
}
|
|
|
|
public ItemStack b(int i, int j) {
|
|
if (i >= 0 && i < this.b) {
|
|
int k = i + j * this.b;
|
|
|
|
return this.getItem(k);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public String getName() {
|
|
return "Crafting";
|
|
}
|
|
|
|
public ItemStack splitStack(int i, int j) {
|
|
if (this.items[i] != null) {
|
|
ItemStack itemstack;
|
|
|
|
if (this.items[i].count <= j) {
|
|
itemstack = this.items[i];
|
|
this.items[i] = null;
|
|
this.c.a((IInventory) this);
|
|
return itemstack;
|
|
} else {
|
|
itemstack = this.items[i].a(j);
|
|
if (this.items[i].count == 0) {
|
|
this.items[i] = null;
|
|
}
|
|
|
|
this.c.a((IInventory) this);
|
|
return itemstack;
|
|
}
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public void setItem(int i, ItemStack itemstack) {
|
|
this.items[i] = itemstack;
|
|
this.c.a((IInventory) this);
|
|
}
|
|
|
|
public int getMaxStackSize() {
|
|
return 64;
|
|
}
|
|
|
|
public void update() {}
|
|
|
|
public boolean a(EntityHuman entityhuman) {
|
|
return true;
|
|
}
|
|
|
|
public void f() {}
|
|
|
|
public void g() {}
|
|
}
|