Commits

md_5 authored db70bd6edbf
SPIGOT-7441: Fix issue placing certain items in creative/op
No tags

nms-patches/net/minecraft/world/item/ItemStack.patch

Modified
76 76 }
77 77
78 78 + private ItemStack(NBTTagCompound nbttagcompound) {
79 79 + this.load(nbttagcompound);
80 80 + // CraftBukkit end
81 81 + }
82 82 +
83 83 public static ItemStack of(NBTTagCompound nbttagcompound) {
84 84 try {
85 85 return new ItemStack(nbttagcompound);
86 -@@ -237,12 +292,187 @@
87 - if (entityhuman != null && !entityhuman.getAbilities().mayBuild && !this.hasAdventureModePlaceTagForBlock(itemactioncontext.getLevel().registryAccess().registryOrThrow(Registries.BLOCK), shapedetectorblock)) {
86 +@@ -238,11 +293,190 @@
88 87 return EnumInteractionResult.PASS;
89 88 } else {
89 + Item item = this.getItem();
90 +- EnumInteractionResult enuminteractionresult = item.useOn(itemactioncontext);
90 91 + // CraftBukkit start - handle all block place event logic here
91 92 + NBTTagCompound oldData = this.getTagClone();
92 93 + int oldCount = this.getCount();
93 94 + WorldServer world = (WorldServer) itemactioncontext.getLevel();
94 95 +
95 -+ if (!(this.getItem() instanceof ItemBucket || this.getItem() instanceof SolidBucketItem)) { // if not bucket
96 ++ if (!(item instanceof ItemBucket || item instanceof SolidBucketItem)) { // if not bucket
96 97 + world.captureBlockStates = true;
97 98 + // special case bonemeal
98 -+ if (this.getItem() == Items.BONE_MEAL) {
99 ++ if (item == Items.BONE_MEAL) {
99 100 + world.captureTreeGeneration = true;
100 101 + }
101 102 + }
102 - Item item = this.getItem();
103 - EnumInteractionResult enuminteractionresult = item.useOn(itemactioncontext);
103 ++ EnumInteractionResult enuminteractionresult;
104 ++ try {
105 ++ enuminteractionresult = item.useOn(itemactioncontext);
106 ++ } finally {
107 ++ world.captureBlockStates = false;
108 ++ }
104 109 + NBTTagCompound newData = this.getTagClone();
105 110 + int newCount = this.getCount();
106 111 + this.setCount(oldCount);
107 112 + this.setTagClone(oldData);
108 -+ world.captureBlockStates = false;
109 113 + if (enuminteractionresult.consumesAction() && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) {
110 114 + world.captureTreeGeneration = false;
111 115 + Location location = CraftLocation.toBukkit(blockposition, world.getWorld());
112 116 + TreeType treeType = BlockSapling.treeType;
113 117 + BlockSapling.treeType = null;
114 118 + List<CraftBlockState> blocks = new java.util.ArrayList<>(world.capturedBlockStates.values());
115 119 + world.capturedBlockStates.clear();
116 120 + StructureGrowEvent structureEvent = null;
117 121 + if (treeType != null) {
118 122 + boolean isBonemeal = getItem() == Items.BONE_MEAL;
265 269 +
266 270 + entityhuman.awardStat(StatisticList.ITEM_USED.get(item));
267 271 + }
268 272 }
269 273 + world.capturedTileEntities.clear();
270 274 + world.capturedBlockStates.clear();
271 275 + // CraftBukkit end
272 276
273 277 return enuminteractionresult;
274 278 }
275 -@@ -323,6 +553,21 @@
279 +@@ -323,6 +557,21 @@
276 280 }
277 281
278 282 i -= k;
279 283 + // CraftBukkit start
280 284 + if (entityplayer != null) {
281 285 + PlayerItemDamageEvent event = new PlayerItemDamageEvent(entityplayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), i);
282 286 + event.getPlayer().getServer().getPluginManager().callEvent(event);
283 287 +
284 288 + if (i != event.getDamage() || event.isCancelled()) {
285 289 + event.getPlayer().updateInventory();
286 290 + }
287 291 + if (event.isCancelled()) {
288 292 + return false;
289 293 + }
290 294 +
291 295 + i = event.getDamage();
292 296 + }
293 297 + // CraftBukkit end
294 298 if (i <= 0) {
295 299 return false;
296 300 }
297 -@@ -344,6 +589,11 @@
301 +@@ -344,6 +593,11 @@
298 302 if (this.hurt(i, t0.getRandom(), t0 instanceof EntityPlayer ? (EntityPlayer) t0 : null)) {
299 303 consumer.accept(t0);
300 304 Item item = this.getItem();
301 305 + // CraftBukkit start - Check for item breaking
302 306 + if (this.count == 1 && t0 instanceof EntityHuman) {
303 307 + org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((EntityHuman) t0, this);
304 308 + }
305 309 + // CraftBukkit end
306 310
307 311 this.shrink(1);
308 312 if (t0 instanceof EntityHuman) {
309 -@@ -492,6 +742,17 @@
313 +@@ -492,6 +746,17 @@
310 314 return this.tag;
311 315 }
312 316
313 317 + // CraftBukkit start
314 318 + @Nullable
315 319 + private NBTTagCompound getTagClone() {
316 320 + return this.tag == null ? null : this.tag.copy();
317 321 + }
318 322 +
319 323 + private void setTagClone(@Nullable NBTTagCompound nbtttagcompound) {
320 324 + this.setTag(nbtttagcompound == null ? null : nbtttagcompound.copy());
321 325 + }
322 326 + // CraftBukkit end
323 327 +
324 328 public NBTTagCompound getOrCreateTag() {
325 329 if (this.tag == null) {
326 330 this.setTag(new NBTTagCompound());
327 -@@ -862,6 +1123,12 @@
331 +@@ -862,6 +1127,12 @@
328 332 }
329 333
330 334 public void setRepairCost(int i) {
331 335 + // CraftBukkit start - remove RepairCost tag when 0 (SPIGOT-3945)
332 336 + if (i == 0) {
333 337 + this.removeTagKey("RepairCost");
334 338 + return;
335 339 + }
336 340 + // CraftBukkit end
337 341 this.getOrCreateTag().putInt("RepairCost", i);
338 342 }
339 343
340 -@@ -911,6 +1178,13 @@
344 +@@ -911,6 +1182,13 @@
341 345 nbttaglist.add(nbttagcompound);
342 346 }
343 347
344 348 + // CraftBukkit start
345 349 + @Deprecated
346 350 + public void setItem(Item item) {
347 351 + this.item = item;
348 352 + }
349 353 + // CraftBukkit end
350 354 +

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut