Commits
md_5 authored 963f4a5fc13
1 1 | --- a/net/minecraft/server/ItemStack.java |
2 2 | +++ b/net/minecraft/server/ItemStack.java |
3 - | |
3 + | |
4 4 | import org.apache.logging.log4j.LogManager; |
5 5 | import org.apache.logging.log4j.Logger; |
6 6 | |
7 7 | +// CraftBukkit start |
8 8 | +import com.mojang.datafixers.Dynamic; |
9 9 | +import java.util.List; |
10 10 | +import java.util.Map; |
11 11 | + |
12 12 | +import org.bukkit.Location; |
13 13 | +import org.bukkit.TreeType; |
14 14 | +import org.bukkit.block.BlockState; |
15 15 | +import org.bukkit.craftbukkit.block.CraftBlock; |
16 16 | +import org.bukkit.craftbukkit.block.CraftBlockState; |
17 + | +import org.bukkit.craftbukkit.inventory.CraftItemStack; |
17 18 | +import org.bukkit.craftbukkit.util.CraftMagicNumbers; |
18 19 | +import org.bukkit.entity.Player; |
19 20 | +import org.bukkit.event.block.BlockFertilizeEvent; |
21 + | +import org.bukkit.event.player.PlayerItemDamageEvent; |
20 22 | +import org.bukkit.event.world.StructureGrowEvent; |
21 23 | +// CraftBukkit end |
22 24 | + |
23 25 | public final class ItemStack { |
24 26 | |
25 27 | private static final Logger c = LogManager.getLogger(); |
26 - | |
28 + | |
27 29 | this.E(); |
28 30 | } |
29 31 | |
30 32 | + // Called to run this stack through the data converter to handle older storage methods and serialized items |
31 33 | + public void convertStack() { |
32 34 | + if (false && MinecraftServer.getServer() != null) { // Skip for now, causes more issues than it solves |
33 35 | + // Don't convert some things - both the old and new data values are valid |
34 36 | + // Conversion would make getting then impossible |
35 37 | + if (this.item == Blocks.PUMPKIN.getItem() || this.item == Blocks.GRASS.getItem() || this.item == Blocks.SNOW.getItem()) { |
36 38 | + return; |
69 71 | this.setDamage(this.getDamage()); |
70 72 | } |
71 73 | + } |
72 74 | |
73 75 | + private ItemStack(NBTTagCompound nbttagcompound) { |
74 76 | + this.load(nbttagcompound); |
75 77 | + // CraftBukkit end |
76 78 | this.E(); |
77 79 | } |
78 80 | |
79 - | |
81 + | |
80 82 | return this.h ? Items.AIR : this.item; |
81 83 | } |
82 84 | |
83 85 | - public EnumInteractionResult placeItem(ItemActionContext itemactioncontext) { |
84 86 | + public EnumInteractionResult placeItem(ItemActionContext itemactioncontext, EnumHand enumhand) { // CraftBukkit - add hand |
85 87 | EntityHuman entityhuman = itemactioncontext.getEntity(); |
86 88 | BlockPosition blockposition = itemactioncontext.getClickPosition(); |
87 89 | ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false); |
88 - | |
90 + | |
89 91 | if (entityhuman != null && !entityhuman.abilities.mayBuild && !this.b(itemactioncontext.getWorld().F(), shapedetectorblock)) { |
90 92 | return EnumInteractionResult.PASS; |
91 93 | } else { |
92 94 | + // CraftBukkit start - handle all block place event logic here |
93 95 | + NBTTagCompound oldData = this.getTagClone(); |
94 96 | + int oldCount = this.getCount(); |
95 97 | + World world = itemactioncontext.getWorld(); |
96 98 | + |
97 99 | + if (!(this.getItem() instanceof ItemBucket)) { // if not bucket |
98 100 | + world.captureBlockStates = true; |
224 226 | + |
225 227 | + entityhuman.b(StatisticList.ITEM_USED.b(item)); |
226 228 | + } |
227 229 | } |
228 230 | + world.capturedTileEntities.clear(); |
229 231 | + world.capturedBlockStates.clear(); |
230 232 | + // CraftBukkit end |
231 233 | |
232 234 | return enuminteractionresult; |
233 235 | } |
234 - | |
236 + | |
235 237 | nbttagcompound.setString("id", minecraftkey == null ? "minecraft:air" : minecraftkey.toString()); |
236 238 | nbttagcompound.setByte("Count", (byte) this.count); |
237 239 | if (this.tag != null) { |
238 240 | - nbttagcompound.set("tag", this.tag); |
239 241 | + nbttagcompound.set("tag", this.tag.clone()); // CraftBukkit - make defensive copy, data is going to another thread |
240 242 | } |
241 243 | |
242 244 | return nbttagcompound; |
243 - | |
245 + | |
246 + | } |
247 + | |
248 + | i -= k; |
249 + | + // CraftBukkit start |
250 + | + if (entityplayer != null) { |
251 + | + PlayerItemDamageEvent event = new PlayerItemDamageEvent(entityplayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), i); |
252 + | + event.getPlayer().getServer().getPluginManager().callEvent(event); |
253 + | + |
254 + | + if (i != event.getDamage() || event.isCancelled()) { |
255 + | + event.getPlayer().updateInventory(); |
256 + | + } |
257 + | + if (event.isCancelled()) { |
258 + | + return false; |
259 + | + } |
260 + | + |
261 + | + i = event.getDamage(); |
262 + | + } |
263 + | + // CraftBukkit end |
264 + | if (i <= 0) { |
265 + | return false; |
266 + | } |
267 + | |
244 268 | if (this.isDamaged(i, entityliving.getRandom(), entityliving instanceof EntityPlayer ? (EntityPlayer) entityliving : null)) { |
245 269 | entityliving.c(this); |
246 270 | Item item = this.getItem(); |
247 271 | + // CraftBukkit start - Check for item breaking |
248 272 | + if (this.count == 1 && entityliving instanceof EntityHuman) { |
249 273 | + org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((EntityHuman) entityliving, this); |
250 274 | + } |
251 275 | + // CraftBukkit end |
252 276 | |
253 277 | this.subtract(1); |
254 278 | if (entityliving instanceof EntityHuman) { |
255 - | |
279 + | |
256 280 | return this.tag; |
257 281 | } |
258 282 | |
259 283 | + // CraftBukkit start |
260 284 | + @Nullable |
261 285 | + private NBTTagCompound getTagClone() { |
262 286 | + return this.tag == null ? null : this.tag.clone(); |
263 287 | + } |
264 288 | + |
265 289 | + private void setTagClone(@Nullable NBTTagCompound nbtttagcompound) { |
266 290 | + this.setTag(nbtttagcompound == null ? null : nbtttagcompound.clone()); |
267 291 | + } |
268 292 | + // CraftBukkit end |
269 293 | + |
270 294 | public NBTTagCompound getOrCreateTag() { |
271 295 | if (this.tag == null) { |
272 296 | this.setTag(new NBTTagCompound()); |
273 - | |
297 + | |
274 298 | } |
275 299 | |
276 300 | public void setRepairCost(int i) { |
277 301 | + // CraftBukkit start - remove RepairCost tag when 0 (SPIGOT-3945) |
278 302 | + if (i == 0) { |
279 303 | + if (this.hasTag()) { |
280 304 | + this.tag.remove("RepairCost"); |
281 305 | + } |
282 306 | + return; |
283 307 | + } |
284 308 | + // CraftBukkit end |
285 309 | this.getOrCreateTag().setInt("RepairCost", i); |
286 310 | } |
287 311 | |
288 - | |
312 + | |
289 313 | nbttaglist.add((NBTBase) nbttagcompound); |
290 314 | } |
291 315 | |
292 316 | + // CraftBukkit start |
293 317 | + @Deprecated |
294 318 | + public void setItem(Item item) { |
295 319 | + this.item = item; |
296 320 | + } |
297 321 | + // CraftBukkit end |
298 322 | + |