2012-02-26 05:56:31 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
2013-03-13 23:33:27 +01:00
|
|
|
import java.util.Iterator;
|
2012-02-26 05:56:31 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2012-02-29 19:56:35 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
|
|
|
import org.bukkit.inventory.InventoryView;
|
|
|
|
// CraftBukkit end
|
2012-02-26 05:56:31 +01:00
|
|
|
|
2012-02-29 19:56:35 +01:00
|
|
|
public abstract class Container {
|
2012-02-29 22:31:04 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public List b = new ArrayList();
|
2012-11-06 13:05:28 +01:00
|
|
|
public List c = new ArrayList();
|
2012-02-26 05:56:31 +01:00
|
|
|
public int windowId = 0;
|
2012-11-06 13:05:28 +01:00
|
|
|
private short a = 0;
|
2013-03-13 23:33:27 +01:00
|
|
|
private int f = -1;
|
|
|
|
private int g = 0;
|
|
|
|
private final Set h = new HashSet();
|
2012-02-26 05:56:31 +01:00
|
|
|
protected List listeners = new ArrayList();
|
2013-03-13 23:33:27 +01:00
|
|
|
private Set i = new HashSet();
|
2012-02-26 05:56:31 +01:00
|
|
|
|
2012-02-29 19:56:35 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
public boolean checkReachable = true;
|
|
|
|
public abstract InventoryView getBukkitView();
|
2012-07-22 08:18:00 +02:00
|
|
|
public void transferTo(Container other, org.bukkit.craftbukkit.entity.CraftHumanEntity player) {
|
2012-02-29 19:56:35 +01:00
|
|
|
InventoryView source = this.getBukkitView(), destination = other.getBukkitView();
|
2012-02-29 22:31:04 +01:00
|
|
|
((CraftInventory) source.getTopInventory()).getInventory().onClose(player);
|
|
|
|
((CraftInventory) source.getBottomInventory()).getInventory().onClose(player);
|
|
|
|
((CraftInventory) destination.getTopInventory()).getInventory().onOpen(player);
|
|
|
|
((CraftInventory) destination.getBottomInventory()).getInventory().onOpen(player);
|
2012-02-29 19:56:35 +01:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-02-26 05:56:31 +01:00
|
|
|
public Container() {}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
protected Slot a(Slot slot) {
|
2012-11-06 13:05:28 +01:00
|
|
|
slot.g = this.c.size();
|
|
|
|
this.c.add(slot);
|
|
|
|
this.b.add(null);
|
2012-07-29 09:33:13 +02:00
|
|
|
return slot;
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
public void addSlotListener(ICrafting icrafting) {
|
2012-02-26 05:56:31 +01:00
|
|
|
if (this.listeners.contains(icrafting)) {
|
|
|
|
throw new IllegalArgumentException("Listener already listening");
|
|
|
|
} else {
|
|
|
|
this.listeners.add(icrafting);
|
2012-07-29 09:33:13 +02:00
|
|
|
icrafting.a(this, this.a());
|
|
|
|
this.b();
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public List a() {
|
2012-02-26 05:56:31 +01:00
|
|
|
ArrayList arraylist = new ArrayList();
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
for (int i = 0; i < this.c.size(); ++i) {
|
|
|
|
arraylist.add(((Slot) this.c.get(i)).getItem());
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return arraylist;
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void b() {
|
2012-11-06 13:05:28 +01:00
|
|
|
for (int i = 0; i < this.c.size(); ++i) {
|
|
|
|
ItemStack itemstack = ((Slot) this.c.get(i)).getItem();
|
|
|
|
ItemStack itemstack1 = (ItemStack) this.b.get(i);
|
2012-02-26 05:56:31 +01:00
|
|
|
|
|
|
|
if (!ItemStack.matches(itemstack1, itemstack)) {
|
|
|
|
itemstack1 = itemstack == null ? null : itemstack.cloneItemStack();
|
2012-11-06 13:05:28 +01:00
|
|
|
this.b.set(i, itemstack1);
|
2012-02-26 05:56:31 +01:00
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
for (int j = 0; j < this.listeners.size(); ++j) {
|
|
|
|
((ICrafting) this.listeners.get(j)).a(this, i, itemstack1);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(EntityHuman entityhuman, int i) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Slot a(IInventory iinventory, int i) {
|
2012-11-06 13:05:28 +01:00
|
|
|
for (int j = 0; j < this.c.size(); ++j) {
|
|
|
|
Slot slot = (Slot) this.c.get(j);
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
if (slot.a(iinventory, i)) {
|
|
|
|
return slot;
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
2012-11-06 13:05:28 +01:00
|
|
|
}
|
2012-02-26 05:56:31 +01:00
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
return null;
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
public Slot getSlot(int i) {
|
2012-11-06 13:05:28 +01:00
|
|
|
return (Slot) this.c.get(i);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public ItemStack b(EntityHuman entityhuman, int i) {
|
2012-11-06 13:05:28 +01:00
|
|
|
Slot slot = (Slot) this.c.get(i);
|
2012-02-26 05:56:31 +01:00
|
|
|
|
|
|
|
return slot != null ? slot.getItem() : null;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public ItemStack clickItem(int i, int j, int k, EntityHuman entityhuman) {
|
2012-02-26 05:56:31 +01:00
|
|
|
ItemStack itemstack = null;
|
2012-10-25 05:53:23 +02:00
|
|
|
PlayerInventory playerinventory = entityhuman.inventory;
|
|
|
|
int l;
|
2013-03-13 23:33:27 +01:00
|
|
|
ItemStack itemstack1;
|
2012-02-26 05:56:31 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (k == 5) {
|
|
|
|
int i1 = this.g;
|
|
|
|
|
|
|
|
this.g = c(j);
|
|
|
|
if ((i1 != 1 || this.g != 2) && i1 != this.g) {
|
|
|
|
this.d();
|
|
|
|
} else if (playerinventory.getCarried() == null) {
|
|
|
|
this.d();
|
|
|
|
} else if (this.g == 0) {
|
|
|
|
this.f = b(j);
|
|
|
|
if (d(this.f)) {
|
|
|
|
this.g = 1;
|
|
|
|
this.h.clear();
|
|
|
|
} else {
|
|
|
|
this.d();
|
|
|
|
}
|
|
|
|
} else if (this.g == 1) {
|
|
|
|
Slot slot = (Slot) this.c.get(i);
|
2012-02-26 05:56:31 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (slot != null && a(slot, playerinventory.getCarried(), true) && slot.isAllowed(playerinventory.getCarried()) && playerinventory.getCarried().count > this.h.size() && this.b(slot)) {
|
|
|
|
this.h.add(slot);
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
} else if (this.g == 2) {
|
|
|
|
if (!this.h.isEmpty()) {
|
|
|
|
itemstack1 = playerinventory.getCarried().cloneItemStack();
|
|
|
|
l = playerinventory.getCarried().count;
|
|
|
|
Iterator iterator = this.h.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Slot slot1 = (Slot) iterator.next();
|
|
|
|
|
|
|
|
if (slot1 != null && a(slot1, playerinventory.getCarried(), true) && slot1.isAllowed(playerinventory.getCarried()) && playerinventory.getCarried().count >= this.h.size() && this.b(slot1)) {
|
|
|
|
ItemStack itemstack2 = itemstack1.cloneItemStack();
|
|
|
|
int j1 = slot1.d() ? slot1.getItem().count : 0;
|
|
|
|
|
|
|
|
a(this.h, this.f, itemstack2, j1);
|
|
|
|
if (itemstack2.count > itemstack2.getMaxStackSize()) {
|
|
|
|
itemstack2.count = itemstack2.getMaxStackSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack2.count > slot1.a()) {
|
|
|
|
itemstack2.count = slot1.a();
|
|
|
|
}
|
|
|
|
|
|
|
|
l -= itemstack2.count - j1;
|
|
|
|
slot1.set(itemstack2);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
itemstack1.count = l;
|
|
|
|
if (itemstack1.count <= 0) {
|
|
|
|
itemstack1 = null;
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
playerinventory.setCarried(itemstack1);
|
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
this.d();
|
|
|
|
} else {
|
|
|
|
this.d();
|
|
|
|
}
|
|
|
|
} else if (this.g != 0) {
|
|
|
|
this.d();
|
|
|
|
} else {
|
|
|
|
Slot slot2;
|
|
|
|
int k1;
|
|
|
|
ItemStack itemstack3;
|
|
|
|
|
|
|
|
if ((k == 0 || k == 1) && (j == 0 || j == 1)) {
|
|
|
|
if (i == -999) {
|
|
|
|
if (playerinventory.getCarried() != null && i == -999) {
|
|
|
|
if (j == 0) {
|
|
|
|
entityhuman.drop(playerinventory.getCarried());
|
|
|
|
playerinventory.setCarried((ItemStack) null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == 1) {
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Store a reference
|
2013-03-13 23:33:27 +01:00
|
|
|
ItemStack itemstack4 = playerinventory.getCarried();
|
|
|
|
if (itemstack4.count > 0) {
|
|
|
|
entityhuman.drop(itemstack4.a(1));
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (itemstack4.count == 0) {
|
|
|
|
// CraftBukkit end
|
2012-10-25 05:53:23 +02:00
|
|
|
playerinventory.setCarried((ItemStack) null);
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
} else if (k == 1) {
|
|
|
|
if (i < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
slot2 = (Slot) this.c.get(i);
|
|
|
|
if (slot2 != null && slot2.a(entityhuman)) {
|
|
|
|
itemstack1 = this.b(entityhuman, i);
|
|
|
|
if (itemstack1 != null) {
|
|
|
|
l = itemstack1.id;
|
|
|
|
itemstack = itemstack1.cloneItemStack();
|
|
|
|
if (slot2 != null && slot2.getItem() != null && slot2.getItem().id == l) {
|
|
|
|
this.a(i, j, true, entityhuman);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (i < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-02-26 05:56:31 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
slot2 = (Slot) this.c.get(i);
|
|
|
|
if (slot2 != null) {
|
|
|
|
itemstack1 = slot2.getItem();
|
|
|
|
ItemStack itemstack4 = playerinventory.getCarried();
|
|
|
|
|
|
|
|
if (itemstack1 != null) {
|
|
|
|
itemstack = itemstack1.cloneItemStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack1 == null) {
|
|
|
|
if (itemstack4 != null && slot2.isAllowed(itemstack4)) {
|
|
|
|
k1 = j == 0 ? itemstack4.count : 1;
|
|
|
|
if (k1 > slot2.a()) {
|
|
|
|
k1 = slot2.a();
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
if (itemstack4.count >= k1) {
|
|
|
|
slot2.set(itemstack4.a(k1));
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
// CraftBukkit end
|
2012-02-26 05:56:31 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (itemstack4.count == 0) {
|
2012-02-29 22:31:04 +01:00
|
|
|
playerinventory.setCarried((ItemStack) null);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
} else if (slot2.a(entityhuman)) {
|
|
|
|
if (itemstack4 == null) {
|
|
|
|
k1 = j == 0 ? itemstack1.count : (itemstack1.count + 1) / 2;
|
|
|
|
itemstack3 = slot2.a(k1);
|
|
|
|
playerinventory.setCarried(itemstack3);
|
2012-10-25 05:53:23 +02:00
|
|
|
if (itemstack1.count == 0) {
|
2013-03-13 23:33:27 +01:00
|
|
|
slot2.set((ItemStack) null);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
slot2.a(entityhuman, playerinventory.getCarried());
|
|
|
|
} else if (slot2.isAllowed(itemstack4)) {
|
|
|
|
if (itemstack1.id == itemstack4.id && itemstack1.getData() == itemstack4.getData() && ItemStack.equals(itemstack1, itemstack4)) {
|
|
|
|
k1 = j == 0 ? itemstack4.count : 1;
|
|
|
|
if (k1 > slot2.a() - itemstack1.count) {
|
|
|
|
k1 = slot2.a() - itemstack1.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k1 > itemstack4.getMaxStackSize() - itemstack1.count) {
|
|
|
|
k1 = itemstack4.getMaxStackSize() - itemstack1.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
itemstack4.a(k1);
|
|
|
|
if (itemstack4.count == 0) {
|
|
|
|
playerinventory.setCarried((ItemStack) null);
|
|
|
|
}
|
|
|
|
|
|
|
|
itemstack1.count += k1;
|
|
|
|
} else if (itemstack4.count <= slot2.a()) {
|
|
|
|
slot2.set(itemstack4);
|
|
|
|
playerinventory.setCarried(itemstack1);
|
|
|
|
}
|
|
|
|
} else if (itemstack1.id == itemstack4.id && itemstack4.getMaxStackSize() > 1 && (!itemstack1.usesData() || itemstack1.getData() == itemstack4.getData()) && ItemStack.equals(itemstack1, itemstack4)) {
|
|
|
|
k1 = itemstack1.count;
|
|
|
|
if (k1 > 0 && k1 + itemstack4.count <= itemstack4.getMaxStackSize()) {
|
|
|
|
itemstack4.count += k1;
|
|
|
|
itemstack1 = slot2.a(k1);
|
|
|
|
if (itemstack1.count == 0) {
|
|
|
|
slot2.set((ItemStack) null);
|
|
|
|
}
|
|
|
|
|
|
|
|
slot2.a(entityhuman, playerinventory.getCarried());
|
|
|
|
}
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
|
|
|
slot2.e();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (k == 2 && j >= 0 && j < 9) {
|
|
|
|
slot2 = (Slot) this.c.get(i);
|
|
|
|
if (slot2.a(entityhuman)) {
|
|
|
|
itemstack1 = playerinventory.getItem(j);
|
|
|
|
boolean flag = itemstack1 == null || slot2.inventory == playerinventory && slot2.isAllowed(itemstack1);
|
|
|
|
|
|
|
|
k1 = -1;
|
|
|
|
if (!flag) {
|
|
|
|
k1 = playerinventory.j();
|
|
|
|
flag |= k1 > -1;
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (slot2.d() && flag) {
|
|
|
|
itemstack3 = slot2.getItem();
|
2013-04-27 11:40:05 +02:00
|
|
|
playerinventory.setItem(j, itemstack3.cloneItemStack());
|
2013-03-13 23:33:27 +01:00
|
|
|
if ((slot2.inventory != playerinventory || !slot2.isAllowed(itemstack1)) && itemstack1 != null) {
|
|
|
|
if (k1 > -1) {
|
|
|
|
playerinventory.pickup(itemstack1);
|
|
|
|
slot2.a(itemstack3.count);
|
|
|
|
slot2.set((ItemStack) null);
|
|
|
|
slot2.a(entityhuman, itemstack3);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
slot2.a(itemstack3.count);
|
|
|
|
slot2.set(itemstack1);
|
|
|
|
slot2.a(entityhuman, itemstack3);
|
|
|
|
}
|
|
|
|
} else if (!slot2.d() && itemstack1 != null && slot2.isAllowed(itemstack1)) {
|
|
|
|
playerinventory.setItem(j, (ItemStack) null);
|
|
|
|
slot2.set(itemstack1);
|
|
|
|
}
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
} else if (k == 3 && entityhuman.abilities.canInstantlyBuild && playerinventory.getCarried() == null && i >= 0) {
|
|
|
|
slot2 = (Slot) this.c.get(i);
|
|
|
|
if (slot2 != null && slot2.d()) {
|
|
|
|
itemstack1 = slot2.getItem().cloneItemStack();
|
|
|
|
itemstack1.count = itemstack1.getMaxStackSize();
|
|
|
|
playerinventory.setCarried(itemstack1);
|
|
|
|
}
|
|
|
|
} else if (k == 4 && playerinventory.getCarried() == null && i >= 0) {
|
|
|
|
slot2 = (Slot) this.c.get(i);
|
2013-04-27 11:40:05 +02:00
|
|
|
if (slot2 != null && slot2.d() && slot2.a(entityhuman)) {
|
2013-03-13 23:33:27 +01:00
|
|
|
itemstack1 = slot2.a(j == 0 ? 1 : slot2.getItem().count);
|
|
|
|
slot2.a(entityhuman, itemstack1);
|
|
|
|
entityhuman.drop(itemstack1);
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
} else if (k == 6 && i >= 0) {
|
|
|
|
slot2 = (Slot) this.c.get(i);
|
|
|
|
itemstack1 = playerinventory.getCarried();
|
|
|
|
if (itemstack1 != null && (slot2 == null || !slot2.d() || !slot2.a(entityhuman))) {
|
|
|
|
l = j == 0 ? 0 : this.c.size() - 1;
|
|
|
|
k1 = j == 0 ? 1 : -1;
|
|
|
|
|
|
|
|
for (int l1 = 0; l1 < 2; ++l1) {
|
|
|
|
for (int i2 = l; i2 >= 0 && i2 < this.c.size() && itemstack1.count < itemstack1.getMaxStackSize(); i2 += k1) {
|
|
|
|
Slot slot3 = (Slot) this.c.get(i2);
|
|
|
|
|
|
|
|
if (slot3.d() && a(slot3, itemstack1, true) && slot3.a(entityhuman) && this.a(itemstack1, slot3) && (l1 != 0 || slot3.getItem().count != slot3.getItem().getMaxStackSize())) {
|
|
|
|
int j2 = Math.min(itemstack1.getMaxStackSize() - itemstack1.count, slot3.getItem().count);
|
|
|
|
ItemStack itemstack5 = slot3.a(j2);
|
|
|
|
|
|
|
|
itemstack1.count += j2;
|
|
|
|
if (itemstack5.count <= 0) {
|
|
|
|
slot3.set((ItemStack) null);
|
|
|
|
}
|
2012-02-26 05:56:31 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
slot3.a(entityhuman, itemstack5);
|
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
|
|
|
this.b();
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
return itemstack;
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public boolean a(ItemStack itemstack, Slot slot) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
protected void a(int i, int j, boolean flag, EntityHuman entityhuman) {
|
|
|
|
this.clickItem(i, j, 1, entityhuman);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
public void b(EntityHuman entityhuman) {
|
2012-02-26 05:56:31 +01:00
|
|
|
PlayerInventory playerinventory = entityhuman.inventory;
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
if (playerinventory.getCarried() != null) {
|
|
|
|
entityhuman.drop(playerinventory.getCarried());
|
|
|
|
playerinventory.setCarried((ItemStack) null);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(IInventory iinventory) {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.b();
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
public void setItem(int i, ItemStack itemstack) {
|
|
|
|
this.getSlot(i).set(itemstack);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
public boolean c(EntityHuman entityhuman) {
|
2013-03-13 23:33:27 +01:00
|
|
|
return !this.i.contains(entityhuman);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(EntityHuman entityhuman, boolean flag) {
|
|
|
|
if (flag) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.i.remove(entityhuman);
|
2012-02-26 05:56:31 +01:00
|
|
|
} else {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.i.add(entityhuman);
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
public abstract boolean a(EntityHuman entityhuman);
|
2012-02-26 05:56:31 +01:00
|
|
|
|
|
|
|
protected boolean a(ItemStack itemstack, int i, int j, boolean flag) {
|
|
|
|
boolean flag1 = false;
|
|
|
|
int k = i;
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
k = j - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Slot slot;
|
|
|
|
ItemStack itemstack1;
|
|
|
|
|
|
|
|
if (itemstack.isStackable()) {
|
|
|
|
while (itemstack.count > 0 && (!flag && k < j || flag && k >= i)) {
|
2012-11-06 13:05:28 +01:00
|
|
|
slot = (Slot) this.c.get(k);
|
2012-02-26 05:56:31 +01:00
|
|
|
itemstack1 = slot.getItem();
|
|
|
|
if (itemstack1 != null && itemstack1.id == itemstack.id && (!itemstack.usesData() || itemstack.getData() == itemstack1.getData()) && ItemStack.equals(itemstack, itemstack1)) {
|
|
|
|
int l = itemstack1.count + itemstack.count;
|
|
|
|
|
|
|
|
if (l <= itemstack.getMaxStackSize()) {
|
|
|
|
itemstack.count = 0;
|
|
|
|
itemstack1.count = l;
|
2012-07-29 09:33:13 +02:00
|
|
|
slot.e();
|
2012-02-26 05:56:31 +01:00
|
|
|
flag1 = true;
|
|
|
|
} else if (itemstack1.count < itemstack.getMaxStackSize()) {
|
|
|
|
itemstack.count -= itemstack.getMaxStackSize() - itemstack1.count;
|
|
|
|
itemstack1.count = itemstack.getMaxStackSize();
|
2012-07-29 09:33:13 +02:00
|
|
|
slot.e();
|
2012-02-26 05:56:31 +01:00
|
|
|
flag1 = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
--k;
|
|
|
|
} else {
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack.count > 0) {
|
|
|
|
if (flag) {
|
|
|
|
k = j - 1;
|
|
|
|
} else {
|
|
|
|
k = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!flag && k < j || flag && k >= i) {
|
2012-11-06 13:05:28 +01:00
|
|
|
slot = (Slot) this.c.get(k);
|
2012-02-26 05:56:31 +01:00
|
|
|
itemstack1 = slot.getItem();
|
|
|
|
if (itemstack1 == null) {
|
2012-02-29 22:31:04 +01:00
|
|
|
slot.set(itemstack.cloneItemStack());
|
2012-07-29 09:33:13 +02:00
|
|
|
slot.e();
|
2012-02-26 05:56:31 +01:00
|
|
|
itemstack.count = 0;
|
|
|
|
flag1 = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
--k;
|
|
|
|
} else {
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flag1;
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
|
|
|
public static int b(int i) {
|
|
|
|
return i >> 2 & 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int c(int i) {
|
|
|
|
return i & 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean d(int i) {
|
|
|
|
return i == 0 || i == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void d() {
|
|
|
|
this.g = 0;
|
|
|
|
this.h.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean a(Slot slot, ItemStack itemstack, boolean flag) {
|
|
|
|
boolean flag1 = slot == null || !slot.d();
|
|
|
|
|
|
|
|
if (slot != null && slot.d() && itemstack != null && itemstack.doMaterialsMatch(slot.getItem()) && ItemStack.equals(slot.getItem(), itemstack)) {
|
|
|
|
int i = flag ? 0 : itemstack.count;
|
|
|
|
|
|
|
|
flag1 |= slot.getItem().count + i <= itemstack.getMaxStackSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
return flag1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void a(Set set, int i, ItemStack itemstack, int j) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
itemstack.count = MathHelper.d((float) itemstack.count / (float) set.size());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
itemstack.count = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
itemstack.count += j;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean b(Slot slot) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int b(IInventory iinventory) {
|
|
|
|
if (iinventory == null) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
int i = 0;
|
|
|
|
float f = 0.0F;
|
|
|
|
|
|
|
|
for (int j = 0; j < iinventory.getSize(); ++j) {
|
|
|
|
ItemStack itemstack = iinventory.getItem(j);
|
|
|
|
|
|
|
|
if (itemstack != null) {
|
|
|
|
f += (float) itemstack.count / (float) Math.min(iinventory.getMaxStackSize(), itemstack.getMaxStackSize());
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f /= (float) iinventory.getSize();
|
|
|
|
return MathHelper.d(f * 14.0F) + (i > 0 ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
2012-02-26 05:56:31 +01:00
|
|
|
}
|