3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-18 05:50:04 +01:00
Paper/src/main/java/net/minecraft/server/ItemStack.java

190 Zeilen
4.7 KiB
Java

2011-01-14 14:31:10 +01:00
package net.minecraft.server;
public final class ItemStack {
2011-01-29 22:50:29 +01:00
public int count;
2011-01-14 14:31:10 +01:00
public int b;
2011-01-29 22:50:29 +01:00
public int id;
2011-05-14 16:29:42 +02:00
public int damage; // CraftBukkit - private -> public
2011-01-14 14:31:10 +01:00
public ItemStack(Block block) {
this(block, 1);
}
2011-01-29 22:50:29 +01:00
public ItemStack(Block block, int i) {
this(block.id, i, 0);
2011-01-14 14:31:10 +01:00
}
2011-01-29 22:50:29 +01:00
public ItemStack(Block block, int i, int j) {
this(block.id, i, j);
2011-01-14 14:31:10 +01:00
}
public ItemStack(Item item) {
2011-01-29 22:50:29 +01:00
this(item.id, 1, 0);
2011-01-14 14:31:10 +01:00
}
2011-01-29 22:50:29 +01:00
public ItemStack(Item item, int i) {
this(item.id, i, 0);
2011-01-14 14:31:10 +01:00
}
2011-01-29 22:50:29 +01:00
public ItemStack(Item item, int i, int j) {
this(item.id, i, j);
2011-01-14 14:31:10 +01:00
}
2011-01-29 22:50:29 +01:00
public ItemStack(int i, int j, int k) {
this.count = 0;
this.id = i;
this.count = j;
this.damage = k;
2011-01-14 14:31:10 +01:00
}
public ItemStack(NBTTagCompound nbttagcompound) {
2011-01-29 22:50:29 +01:00
this.count = 0;
this.b(nbttagcompound);
2011-01-14 14:31:10 +01:00
}
2011-01-29 22:50:29 +01:00
public ItemStack a(int i) {
this.count -= i;
return new ItemStack(this.id, i, this.damage);
2011-01-14 14:31:10 +01:00
}
public Item getItem() {
2011-01-29 22:50:29 +01:00
return Item.byId[this.id];
2011-01-14 14:31:10 +01:00
}
public boolean placeItem(EntityHuman entityhuman, World world, int i, int j, int k, int l) {
boolean flag = this.getItem().a(this, entityhuman, world, i, j, k, l);
2011-03-31 22:40:00 +02:00
if (flag) {
2011-04-20 22:47:26 +02:00
entityhuman.a(StatisticList.E[this.id], 1);
2011-03-31 22:40:00 +02:00
}
return flag;
2011-01-14 14:31:10 +01:00
}
public float a(Block block) {
return this.getItem().a(this, block);
2011-01-14 14:31:10 +01:00
}
2011-01-29 22:50:29 +01:00
public ItemStack a(World world, EntityHuman entityhuman) {
return this.getItem().a(this, world, entityhuman);
2011-01-14 14:31:10 +01:00
}
public NBTTagCompound a(NBTTagCompound nbttagcompound) {
2011-01-29 22:50:29 +01:00
nbttagcompound.a("id", (short) this.id);
nbttagcompound.a("Count", (byte) this.count);
nbttagcompound.a("Damage", (short) this.damage);
2011-01-14 14:31:10 +01:00
return nbttagcompound;
}
public void b(NBTTagCompound nbttagcompound) {
2011-02-23 03:37:56 +01:00
this.id = nbttagcompound.d("id");
this.count = nbttagcompound.c("Count");
this.damage = nbttagcompound.d("Damage");
2011-01-14 14:31:10 +01:00
}
public int b() {
return this.getItem().getMaxStackSize();
2011-01-14 14:31:10 +01:00
}
public boolean c() {
2011-01-29 22:50:29 +01:00
return this.b() > 1 && (!this.d() || !this.f());
2011-01-14 14:31:10 +01:00
}
public boolean d() {
2011-01-29 22:50:29 +01:00
return Item.byId[this.id].d() > 0;
2011-01-14 14:31:10 +01:00
}
public boolean e() {
2011-01-29 22:50:29 +01:00
return Item.byId[this.id].c();
2011-01-14 14:31:10 +01:00
}
public boolean f() {
2011-01-29 22:50:29 +01:00
return this.d() && this.damage > 0;
2011-01-14 14:31:10 +01:00
}
public int g() {
2011-01-29 22:50:29 +01:00
return this.damage;
2011-01-14 14:31:10 +01:00
}
public int getData() {
2011-01-29 22:50:29 +01:00
return this.damage;
2011-01-14 14:31:10 +01:00
}
public int i() {
2011-01-29 22:50:29 +01:00
return Item.byId[this.id].d();
2011-01-14 14:31:10 +01:00
}
public void damage(int i, Entity entity) {
2011-01-29 22:50:29 +01:00
if (this.d()) {
this.damage += i;
if (this.damage > this.i()) {
2011-03-31 22:40:00 +02:00
if (entity instanceof EntityHuman) {
2011-04-20 22:47:26 +02:00
((EntityHuman) entity).a(StatisticList.F[this.id], 1);
2011-03-31 22:40:00 +02:00
}
2011-01-29 22:50:29 +01:00
--this.count;
if (this.count < 0) {
this.count = 0;
}
this.damage = 0;
2011-01-14 14:31:10 +01:00
}
}
}
2011-03-31 22:40:00 +02:00
public void a(EntityLiving entityliving, EntityHuman entityhuman) {
boolean flag = Item.byId[this.id].a(this, entityliving, (EntityLiving) entityhuman);
if (flag) {
2011-04-20 22:47:26 +02:00
entityhuman.a(StatisticList.E[this.id], 1);
2011-03-31 22:40:00 +02:00
}
2011-01-14 14:31:10 +01:00
}
2011-03-31 22:40:00 +02:00
public void a(int i, int j, int k, int l, EntityHuman entityhuman) {
boolean flag = Item.byId[this.id].a(this, i, j, k, l, entityhuman);
if (flag) {
2011-04-20 22:47:26 +02:00
entityhuman.a(StatisticList.E[this.id], 1);
2011-03-31 22:40:00 +02:00
}
2011-01-14 14:31:10 +01:00
}
public int a(Entity entity) {
2011-01-29 22:50:29 +01:00
return Item.byId[this.id].a(entity);
2011-01-14 14:31:10 +01:00
}
public boolean b(Block block) {
2011-01-29 22:50:29 +01:00
return Item.byId[this.id].a(block);
2011-01-14 14:31:10 +01:00
}
2011-01-29 22:50:29 +01:00
public void a(EntityHuman entityhuman) {}
2011-01-14 14:31:10 +01:00
2011-03-31 22:40:00 +02:00
public void a(EntityLiving entityliving) {
Item.byId[this.id].a(this, entityliving);
2011-01-14 14:31:10 +01:00
}
public ItemStack j() {
2011-01-29 22:50:29 +01:00
return new ItemStack(this.id, this.count, this.damage);
2011-01-14 14:31:10 +01:00
}
public static boolean equals(ItemStack itemstack, ItemStack itemstack1) {
2011-01-29 22:50:29 +01:00
return itemstack == null && itemstack1 == null ? true : (itemstack != null && itemstack1 != null ? itemstack.c(itemstack1) : false);
2011-01-14 14:31:10 +01:00
}
private boolean c(ItemStack itemstack) {
2011-01-29 22:50:29 +01:00
return this.count != itemstack.count ? false : (this.id != itemstack.id ? false : this.damage == itemstack.damage);
2011-01-14 14:31:10 +01:00
}
public boolean a(ItemStack itemstack) {
2011-01-29 22:50:29 +01:00
return this.id == itemstack.id && this.damage == itemstack.damage;
2011-01-14 14:31:10 +01:00
}
public static ItemStack b(ItemStack itemstack) {
2011-01-29 22:50:29 +01:00
return itemstack == null ? null : itemstack.j();
2011-01-14 14:31:10 +01:00
}
public String toString() {
2011-01-29 22:50:29 +01:00
return this.count + "x" + Item.byId[this.id].a() + "@" + this.damage;
2011-01-14 14:31:10 +01:00
}
}