Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 223 lines 6.1 kB view raw
1package net.minecraft.server; 2 3import org.bukkit.craftbukkit.inventory.CraftItemStack; 4import org.bukkit.entity.Player; 5import org.bukkit.event.player.PlayerItemDamageEvent; 6 7public final class ItemStack { 8 9 public int count; 10 public int b; 11 public int id; 12 public int damage; // CraftBukkit - private -> public 13 14 public ItemStack(Block block) { 15 this(block, 1); 16 } 17 18 public ItemStack(Block block, int i) { 19 this(block.id, i, 0); 20 } 21 22 public ItemStack(Block block, int i, int j) { 23 this(block.id, i, j); 24 } 25 26 public ItemStack(Item item) { 27 this(item.id, 1, 0); 28 } 29 30 public ItemStack(Item item, int i) { 31 this(item.id, i, 0); 32 } 33 34 public ItemStack(Item item, int i, int j) { 35 this(item.id, i, j); 36 } 37 38 public ItemStack(int i, int j, int k) { 39 this.count = 0; 40 this.id = i; 41 this.count = j; 42 this.damage = k; 43 } 44 45 public ItemStack(NBTTagCompound nbttagcompound) { 46 this.count = 0; 47 this.b(nbttagcompound); 48 } 49 50 public ItemStack a(int i) { 51 this.count -= i; 52 return new ItemStack(this.id, i, this.damage); 53 } 54 55 public Item getItem() { 56 return Item.byId[this.id]; 57 } 58 59 public boolean placeItem(EntityHuman entityhuman, World world, int i, int j, int k, int l) { 60 boolean flag = this.getItem().a(this, entityhuman, world, i, j, k, l); 61 62 if (flag) { 63 entityhuman.a(StatisticList.E[this.id], 1); 64 } 65 66 return flag; 67 } 68 69 public float a(Block block) { 70 return this.getItem().a(this, block); 71 } 72 73 public ItemStack a(World world, EntityHuman entityhuman) { 74 return this.getItem().a(this, world, entityhuman); 75 } 76 77 public NBTTagCompound a(NBTTagCompound nbttagcompound) { 78 nbttagcompound.a("id", (short) this.id); 79 nbttagcompound.a("Count", (byte) this.count); 80 nbttagcompound.a("Damage", (short) this.damage); 81 return nbttagcompound; 82 } 83 84 public void b(NBTTagCompound nbttagcompound) { 85 this.id = nbttagcompound.d("id"); 86 this.count = nbttagcompound.c("Count"); 87 this.damage = nbttagcompound.d("Damage"); 88 } 89 90 public int getMaxStackSize() { 91 return this.getItem().getMaxStackSize(); 92 } 93 94 public boolean isStackable() { 95 return this.getMaxStackSize() > 1 && (!this.d() || !this.f()); 96 } 97 98 public boolean d() { 99 return Item.byId[this.id].e() > 0; 100 } 101 102 public boolean usesData() { 103 return Item.byId[this.id].d(); 104 } 105 106 public boolean f() { 107 return this.d() && this.damage > 0; 108 } 109 110 public int g() { 111 return this.damage; 112 } 113 114 public int getData() { 115 return this.damage; 116 } 117 118 public void b(int i) { 119 this.damage = i; 120 } 121 122 public int i() { 123 return Item.byId[this.id].e(); 124 } 125 126 @SuppressWarnings("deprecation") 127 public void damage(int i, Entity entity) { 128 if (this.d()) { 129 if (entity instanceof EntityPlayer) { 130 PlayerItemDamageEvent event = new PlayerItemDamageEvent((Player) entity.getBukkitEntity(), new CraftItemStack(this), i); 131 event.getPlayer().getServer().getPluginManager().callEvent(event); 132 if (i != event.getDamage() || event.isCancelled()) event.getPlayer().updateInventory(); 133 if (event.isCancelled()) return; 134 i = event.getDamage(); 135 } 136 this.damage += i; 137 if (this.damage > this.i()) { 138 if (entity instanceof EntityHuman) { 139 ((EntityHuman) entity).a(StatisticList.F[this.id], 1); 140 } 141 142 --this.count; 143 if (this.count < 0) { 144 this.count = 0; 145 } 146 147 this.damage = 0; 148 } 149 } 150 } 151 152 public void a(EntityLiving entityliving, EntityHuman entityhuman) { 153 boolean flag = Item.byId[this.id].a(this, entityliving, (EntityLiving) entityhuman); 154 155 if (flag) { 156 entityhuman.a(StatisticList.E[this.id], 1); 157 } 158 } 159 160 public void a(int i, int j, int k, int l, EntityHuman entityhuman) { 161 boolean flag = Item.byId[this.id].a(this, i, j, k, l, entityhuman); 162 163 if (flag) { 164 entityhuman.a(StatisticList.E[this.id], 1); 165 } 166 } 167 168 public int a(Entity entity) { 169 return Item.byId[this.id].a(entity); 170 } 171 172 public boolean b(Block block) { 173 return Item.byId[this.id].a(block); 174 } 175 176 public void a(EntityHuman entityhuman) { 177 } 178 179 public void a(EntityLiving entityliving) { 180 Item.byId[this.id].a(this, entityliving); 181 } 182 183 public ItemStack cloneItemStack() { 184 return new ItemStack(this.id, this.count, this.damage); 185 } 186 187 public static boolean equals(ItemStack itemstack, ItemStack itemstack1) { 188 return itemstack == null && itemstack1 == null ? true : (itemstack != null && itemstack1 != null ? itemstack.d(itemstack1) : false); 189 } 190 191 private boolean d(ItemStack itemstack) { 192 return this.count != itemstack.count ? false : (this.id != itemstack.id ? false : this.damage == itemstack.damage); 193 } 194 195 public boolean doMaterialsMatch(ItemStack itemstack) { 196 return this.id == itemstack.id && this.damage == itemstack.damage; 197 } 198 199 public static ItemStack b(ItemStack itemstack) { 200 return itemstack == null ? null : itemstack.cloneItemStack(); 201 } 202 203 public String toString() { 204 return this.count + "x" + Item.byId[this.id].a() + "@" + this.damage; 205 } 206 207 public void a(World world, Entity entity, int i, boolean flag) { 208 if (this.b > 0) { 209 --this.b; 210 } 211 212 Item.byId[this.id].a(this, world, entity, i, flag); 213 } 214 215 public void b(World world, EntityHuman entityhuman) { 216 entityhuman.a(StatisticList.D[this.id], this.count); 217 Item.byId[this.id].c(this, world, entityhuman); 218 } 219 220 public boolean c(ItemStack itemstack) { 221 return this.id == itemstack.id && this.count == itemstack.count && this.damage == itemstack.damage; 222 } 223}