3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 12:30:06 +01:00

Create a concept of a null item stack

Dieser Commit ist enthalten in:
durron597 2011-01-06 06:20:12 -05:00
Ursprung 95c53f09fc
Commit 687ae0533c

Datei anzeigen

@ -7,7 +7,7 @@ public class CraftItemStack extends ItemStack {
protected net.minecraft.server.ItemStack item; protected net.minecraft.server.ItemStack item;
public CraftItemStack(net.minecraft.server.ItemStack item) { public CraftItemStack(net.minecraft.server.ItemStack item) {
super(item.c, item.a); super(item != null ? item.c : 0, item != null ? item.a : 0);
this.item = item; this.item = item;
} }
@ -18,44 +18,68 @@ public class CraftItemStack extends ItemStack {
@Override @Override
public Material getType() { public Material getType() {
super.setTypeID(item.c); // sync, needed? super.setTypeID(item != null ? item.c : 0); // sync, needed?
return super.getType(); return super.getType();
} }
@Override @Override
public int getTypeID() { public int getTypeID() {
super.setTypeID(item.c); // sync, needed? super.setTypeID(item != null ? item.c : 0); // sync, needed?
return item.c; return item != null ? item.c : 0;
} }
@Override @Override
public void setTypeID(int type) { public void setTypeID(int type) {
super.setTypeID(item.c); if (type == 0) {
super.setTypeID(0);
super.setAmount(0);
item = null;
} else {
if (item == null) {
item = new net.minecraft.server.ItemStack(type);
super.setAmount(1);
} else {
item.c = type; item.c = type;
super.setTypeID(item.c);
}
}
} }
@Override @Override
public int getAmount() { public int getAmount() {
super.setAmount(item.a); // sync, needed? super.setAmount(item != null ? item.a : 0); // sync, needed?
return item.a; return item.a;
} }
@Override @Override
public void setAmount(int amount) { public void setAmount(int amount) {
if (amount == 0) {
super.setTypeID(0);
super.setAmount(0);
item = null;
} else {
super.setAmount(amount); super.setAmount(amount);
item.a = amount; item.a = amount;
} }
}
@Override @Override
public void setDamage(final byte damage) { public void setDamage(final byte damage) {
// Ignore damage if item is null
if (item != null) {
super.setDamage(damage); super.setDamage(damage);
item.d = damage; item.d = damage;
} }
}
@Override @Override
public byte getDamage() { public byte getDamage() {
if (item != null) {
super.setDamage((byte) item.d); // sync, needed? super.setDamage((byte) item.d); // sync, needed?
return (byte) item.d; return (byte) item.d;
} else {
return 0;
}
} }
} }