Commits
md_5 authored 934d861cc32
13 13 | +import org.bukkit.block.BlockState; |
14 14 | +import org.bukkit.craftbukkit.block.CraftBlockState; |
15 15 | +import org.bukkit.craftbukkit.util.CraftMagicNumbers; |
16 16 | +import org.bukkit.entity.Player; |
17 17 | +import org.bukkit.event.world.StructureGrowEvent; |
18 18 | +// CraftBukkit end |
19 19 | + |
20 20 | public final class ItemStack { |
21 21 | |
22 22 | public static final DecimalFormat a = new DecimalFormat("#.##"); |
23 - | |
23 + | |
24 24 | this.k = false; |
25 25 | this.item = item; |
26 26 | this.count = i; |
27 27 | - this.damage = j; |
28 28 | - if (this.damage < 0) { |
29 29 | - this.damage = 0; |
30 - | - } |
31 30 | + |
32 31 | + // CraftBukkit start - Pass to setData to do filtering |
33 32 | + this.setData(j); |
34 33 | + //this.damage = j; |
35 34 | + //if (this.damage < 0) { |
36 35 | + // this.damage = 0; |
37 36 | + //} |
37 + | + if (MinecraftServer.getServer() != null) { |
38 + | + NBTTagCompound savedStack = new NBTTagCompound(); |
39 + | + this.save(savedStack); |
40 + | + MinecraftServer.getServer().getDataConverterManager().a(DataConverterTypes.ITEM_INSTANCE, savedStack); |
41 + | + this.c(savedStack); |
42 + | } |
38 43 | + // CraftBukkit end |
39 44 | |
40 45 | } |
41 46 | |
42 - | |
47 + | |
43 48 | } |
44 49 | |
45 50 | public EnumInteractionResult placeItem(EntityHuman entityhuman, World world, BlockPosition blockposition, EnumHand enumhand, EnumDirection enumdirection, float f, float f1, float f2) { |
46 51 | + // CraftBukkit start - handle all block place event logic here |
47 52 | + int data = this.getData(); |
48 53 | + int count = this.count; |
49 54 | + |
50 55 | + if (!(this.getItem() instanceof ItemBucket)) { // if not bucket |
51 56 | + world.captureBlockStates = true; |
52 57 | + // special case bonemeal |
165 170 | + |
166 171 | + entityhuman.b(StatisticList.b(this.item)); |
167 172 | + } |
168 173 | } |
169 174 | + world.capturedTileEntities.clear(); |
170 175 | + world.capturedBlockStates.clear(); |
171 176 | + // CraftBukkit end |
172 177 | |
173 178 | return enuminteractionresult; |
174 179 | } |
175 - | |
180 + | |
176 181 | nbttagcompound.setByte("Count", (byte) this.count); |
177 182 | nbttagcompound.setShort("Damage", (short) this.damage); |
178 183 | if (this.tag != null) { |
179 184 | - nbttagcompound.set("tag", this.tag); |
180 185 | + nbttagcompound.set("tag", this.tag.clone()); // CraftBukkit - make defensive copy, data is going to another thread |
181 186 | } |
182 187 | |
183 188 | return nbttagcompound; |
184 - | |
189 + | |
185 190 | public void c(NBTTagCompound nbttagcompound) { |
186 191 | this.item = Item.d(nbttagcompound.getString("id")); |
187 192 | this.count = nbttagcompound.getByte("Count"); |
188 193 | + /* CraftBukkit start - Route through setData for filtering |
189 194 | this.damage = nbttagcompound.getShort("Damage"); |
190 195 | if (this.damage < 0) { |
191 196 | this.damage = 0; |
192 197 | } |
193 198 | + */ |
194 199 | + this.setData(nbttagcompound.getShort("Damage")); |
195 200 | + // CraftBukkit end |
196 201 | |
197 202 | if (nbttagcompound.hasKeyOfType("tag", 10)) { |
198 203 | - this.tag = nbttagcompound.getCompound("tag"); |
199 204 | + // CraftBukkit - make defensive copy as this data may be coming from the save thread |
200 205 | + this.tag = (NBTTagCompound) nbttagcompound.getCompound("tag").clone(); |
201 206 | if (this.item != null) { |
202 207 | this.item.a(this.tag); |
203 208 | } |
204 - | |
209 + | |
205 210 | } |
206 211 | |
207 212 | public void setData(int i) { |
208 213 | + // CraftBukkit start - Filter out data for items that shouldn't have it |
209 214 | + // The crafting system uses this value for a special purpose so we have to allow it |
210 215 | + if (i == 32767) { |
211 216 | + this.damage = i; |
212 217 | + return; |
213 218 | + } |
214 219 | + |
223 228 | + // Filter invalid plant data |
224 229 | + if (CraftMagicNumbers.getBlock(CraftMagicNumbers.getId(this.getItem())) == Blocks.DOUBLE_PLANT && (i > 5 || i < 0)) { |
225 230 | + i = 0; |
226 231 | + } |
227 232 | + // CraftBukkit end |
228 233 | this.damage = i; |
229 234 | if (this.damage < 0) { |
230 235 | - this.damage = 0; |
231 236 | + // this.damage = 0; // CraftBukkit - remove this. |
232 237 | } |
233 - | |
238 + | - |
234 239 | } |
235 - | |
240 + | |
241 + | public int j() { |
242 + | |
236 243 | this.count = 0; |
237 244 | } |
238 245 | |
239 246 | + // CraftBukkit start - Check for item breaking |
240 247 | + if (this.count == 0 && entityliving instanceof EntityHuman) { |
241 248 | + org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((EntityHuman) entityliving, this); |
242 249 | + } |
243 250 | + // CraftBukkit end |
244 251 | + |
245 252 | this.damage = 0; |
246 253 | } |
247 254 | |
248 - | |
255 + | |
249 256 | |
250 257 | public void setItem(Item item) { |
251 258 | this.item = item; |
252 259 | + this.setData(this.getData()); // CraftBukkit - Set data again to ensure it is filtered properly |
253 260 | } |
254 261 | |
255 262 | public IChatBaseComponent B() { |