2011-01-29 22:50:29 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
public class InventoryPlayer implements IInventory {
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public ItemStack[] items = new ItemStack[36];
|
|
|
|
public ItemStack[] armor = new ItemStack[4];
|
|
|
|
public int itemInHandIndex = 0;
|
2011-05-14 16:29:42 +02:00
|
|
|
public EntityHuman d; // CraftBukkit - private -> public
|
2011-01-29 22:50:29 +01:00
|
|
|
private ItemStack f;
|
2011-03-31 22:40:00 +02:00
|
|
|
public boolean e = false;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
public ItemStack[] getContents() {
|
2011-04-20 19:05:14 +02:00
|
|
|
return items;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack[] getArmorContents() {
|
2011-04-20 19:05:14 +02:00
|
|
|
return armor;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public InventoryPlayer(EntityHuman entityhuman) {
|
2011-03-31 22:40:00 +02:00
|
|
|
this.d = entityhuman;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public ItemStack getItemInHand() {
|
|
|
|
return this.itemInHandIndex < 9 && this.itemInHandIndex >= 0 ? this.items[this.itemInHandIndex] : null;
|
2011-03-31 22:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int e() {
|
|
|
|
return 9;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private int d(int i) {
|
2011-04-20 19:05:14 +02:00
|
|
|
for (int j = 0; j < this.items.length; ++j) {
|
|
|
|
if (this.items[j] != null && this.items[j].id == i) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int c(ItemStack itemstack) {
|
2011-04-20 19:05:14 +02:00
|
|
|
for (int i = 0; i < this.items.length; ++i) {
|
|
|
|
if (this.items[i] != null && this.items[i].id == itemstack.id && this.items[i].c() && this.items[i].count < this.items[i].b() && this.items[i].count < this.getMaxStackSize() && (!this.items[i].e() || this.items[i].getData() == itemstack.getData())) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-31 22:40:00 +02:00
|
|
|
private int k() {
|
2011-04-20 19:05:14 +02:00
|
|
|
for (int i = 0; i < this.items.length; ++i) {
|
|
|
|
if (this.items[i] == null) {
|
2011-01-29 22:50:29 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int d(ItemStack itemstack) {
|
|
|
|
int i = itemstack.id;
|
|
|
|
int j = itemstack.count;
|
|
|
|
int k = this.c(itemstack);
|
|
|
|
|
|
|
|
if (k < 0) {
|
2011-03-31 22:40:00 +02:00
|
|
|
k = this.k();
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (k < 0) {
|
|
|
|
return j;
|
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.items[k] == null) {
|
|
|
|
this.items[k] = new ItemStack(i, 0, itemstack.getData());
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int l = j;
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (j > this.items[k].b() - this.items[k].count) {
|
|
|
|
l = this.items[k].b() - this.items[k].count;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (l > this.getMaxStackSize() - this.items[k].count) {
|
|
|
|
l = this.getMaxStackSize() - this.items[k].count;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (l == 0) {
|
|
|
|
return j;
|
|
|
|
} else {
|
|
|
|
j -= l;
|
2011-04-20 19:05:14 +02:00
|
|
|
this.items[k].count += l;
|
|
|
|
this.items[k].b = 5;
|
2011-01-29 22:50:29 +01:00
|
|
|
return j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 22:40:00 +02:00
|
|
|
public void f() {
|
2011-04-20 19:05:14 +02:00
|
|
|
for (int i = 0; i < this.items.length; ++i) {
|
|
|
|
if (this.items[i] != null && this.items[i].b > 0) {
|
|
|
|
--this.items[i].b;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean b(int i) {
|
|
|
|
int j = this.d(i);
|
|
|
|
|
|
|
|
if (j < 0) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
if (--this.items[j].count <= 0) {
|
|
|
|
this.items[j] = null;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public boolean canHold(ItemStack itemstack) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!itemstack.f()) {
|
|
|
|
itemstack.count = this.d(itemstack);
|
|
|
|
if (itemstack.count == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 22:40:00 +02:00
|
|
|
int i = this.k();
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (i >= 0) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.items[i] = itemstack;
|
|
|
|
this.items[i].b = 5;
|
2011-01-29 22:50:29 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
public ItemStack a(int i, int j) {
|
2011-04-20 19:05:14 +02:00
|
|
|
ItemStack[] aitemstack = this.items;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (i >= this.items.length) {
|
|
|
|
aitemstack = this.armor;
|
|
|
|
i -= this.items.length;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aitemstack[i] != null) {
|
|
|
|
ItemStack itemstack;
|
|
|
|
|
|
|
|
if (aitemstack[i].count <= j) {
|
|
|
|
itemstack = aitemstack[i];
|
|
|
|
aitemstack[i] = null;
|
|
|
|
return itemstack;
|
|
|
|
} else {
|
|
|
|
itemstack = aitemstack[i].a(j);
|
|
|
|
if (aitemstack[i].count == 0) {
|
|
|
|
aitemstack[i] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void setItem(int i, ItemStack itemstack) {
|
|
|
|
ItemStack[] aitemstack = this.items;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (i >= aitemstack.length) {
|
|
|
|
i -= aitemstack.length;
|
2011-04-20 19:05:14 +02:00
|
|
|
aitemstack = this.armor;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
aitemstack[i] = itemstack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float a(Block block) {
|
|
|
|
float f = 1.0F;
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.items[this.itemInHandIndex] != null) {
|
|
|
|
f *= this.items[this.itemInHandIndex].a(block);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public NBTTagList a(NBTTagList nbttaglist) {
|
|
|
|
int i;
|
|
|
|
NBTTagCompound nbttagcompound;
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (i = 0; i < this.items.length; ++i) {
|
|
|
|
if (this.items[i] != null) {
|
2011-01-29 22:50:29 +01:00
|
|
|
nbttagcompound = new NBTTagCompound();
|
|
|
|
nbttagcompound.a("Slot", (byte) i);
|
2011-04-20 19:05:14 +02:00
|
|
|
this.items[i].a(nbttagcompound);
|
2011-01-29 22:50:29 +01:00
|
|
|
nbttaglist.a((NBTBase) nbttagcompound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (i = 0; i < this.armor.length; ++i) {
|
|
|
|
if (this.armor[i] != null) {
|
2011-01-29 22:50:29 +01:00
|
|
|
nbttagcompound = new NBTTagCompound();
|
|
|
|
nbttagcompound.a("Slot", (byte) (i + 100));
|
2011-04-20 19:05:14 +02:00
|
|
|
this.armor[i].a(nbttagcompound);
|
2011-01-29 22:50:29 +01:00
|
|
|
nbttaglist.a((NBTBase) nbttagcompound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nbttaglist;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagList nbttaglist) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.items = new ItemStack[36];
|
|
|
|
this.armor = new ItemStack[4];
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
for (int i = 0; i < nbttaglist.c(); ++i) {
|
2011-01-29 22:50:29 +01:00
|
|
|
NBTTagCompound nbttagcompound = (NBTTagCompound) nbttaglist.a(i);
|
2011-02-23 03:37:56 +01:00
|
|
|
int j = nbttagcompound.c("Slot") & 255;
|
2011-01-29 22:50:29 +01:00
|
|
|
ItemStack itemstack = new ItemStack(nbttagcompound);
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (itemstack.getItem() != null) {
|
|
|
|
if (j >= 0 && j < this.items.length) {
|
|
|
|
this.items[j] = itemstack;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (j >= 100 && j < this.armor.length + 100) {
|
|
|
|
this.armor[j - 100] = itemstack;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public int getSize() {
|
|
|
|
return this.items.length + 4;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public ItemStack getItem(int i) {
|
|
|
|
ItemStack[] aitemstack = this.items;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (i >= aitemstack.length) {
|
|
|
|
i -= aitemstack.length;
|
2011-04-20 19:05:14 +02:00
|
|
|
aitemstack = this.armor;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return aitemstack[i];
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public String getName() {
|
2011-01-29 22:50:29 +01:00
|
|
|
return "Inventory";
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public int getMaxStackSize() {
|
2011-01-29 22:50:29 +01:00
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int a(Entity entity) {
|
2011-04-20 19:05:14 +02:00
|
|
|
ItemStack itemstack = this.getItem(this.itemInHandIndex);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
return itemstack != null ? itemstack.a(entity) : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean b(Block block) {
|
|
|
|
if (block.material != Material.STONE && block.material != Material.ORE && block.material != Material.SNOW_BLOCK && block.material != Material.SNOW_LAYER) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
ItemStack itemstack = this.getItem(this.itemInHandIndex);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
return itemstack != null ? itemstack.b(block) : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 22:40:00 +02:00
|
|
|
public int g() {
|
2011-01-29 22:50:29 +01:00
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
int k = 0;
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (int l = 0; l < this.armor.length; ++l) {
|
|
|
|
if (this.armor[l] != null && this.armor[l].getItem() instanceof ItemArmor) {
|
|
|
|
int i1 = this.armor[l].i();
|
|
|
|
int j1 = this.armor[l].g();
|
2011-01-29 22:50:29 +01:00
|
|
|
int k1 = i1 - j1;
|
|
|
|
|
|
|
|
j += k1;
|
|
|
|
k += i1;
|
2011-04-20 19:05:14 +02:00
|
|
|
int l1 = ((ItemArmor) this.armor[l].getItem()).bj;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
i += l1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k == 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return (i - 1) * j / k + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void c(int i) {
|
2011-04-20 19:05:14 +02:00
|
|
|
for (int j = 0; j < this.armor.length; ++j) {
|
|
|
|
if (this.armor[j] != null && this.armor[j].getItem() instanceof ItemArmor) {
|
|
|
|
this.armor[j].damage(i, this.d);
|
|
|
|
if (this.armor[j].count == 0) {
|
|
|
|
this.armor[j].a(this.d);
|
|
|
|
this.armor[j] = null;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 22:40:00 +02:00
|
|
|
public void h() {
|
2011-01-29 22:50:29 +01:00
|
|
|
int i;
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (i = 0; i < this.items.length; ++i) {
|
|
|
|
if (this.items[i] != null) {
|
|
|
|
this.d.a(this.items[i], true);
|
|
|
|
this.items[i] = null;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (i = 0; i < this.armor.length; ++i) {
|
|
|
|
if (this.armor[i] != null) {
|
|
|
|
this.d.a(this.armor[i], true);
|
|
|
|
this.armor[i] = null;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void update() {
|
2011-03-31 22:40:00 +02:00
|
|
|
this.e = true;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b(ItemStack itemstack) {
|
|
|
|
this.f = itemstack;
|
2011-03-31 22:40:00 +02:00
|
|
|
this.d.a(itemstack);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-03-31 22:40:00 +02:00
|
|
|
public ItemStack j() {
|
2011-01-29 22:50:29 +01:00
|
|
|
return this.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a_(EntityHuman entityhuman) {
|
2011-03-31 22:40:00 +02:00
|
|
|
return this.d.dead ? false : entityhuman.g(this.d) <= 64.0D;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
}
|