Fix cancelling BlockPlaceEvent calling onRemove

This commit is contained in:
Tamion
2024-05-23 11:02:20 +02:00
parent acdfeeea3d
commit 276e09c3b0
3 changed files with 55 additions and 56 deletions

View File

@@ -152,7 +152,7 @@
});
}
}
@@ -370,32 +418,198 @@
@@ -370,32 +418,200 @@
}
public InteractionResult useOn(UseOnContext context) {
@@ -169,7 +169,7 @@
+ DataComponentPatch oldData = this.components.asPatch();
+ int oldCount = this.getCount();
+ ServerLevel world = (ServerLevel) context.getLevel();
+
+ if (!(item instanceof BucketItem/* || item instanceof SolidBucketItem*/)) { // if not bucket // Paper - Fix cancelled powdered snow bucket placement
+ world.captureBlockStates = true;
+ // special case bonemeal
@@ -200,7 +200,7 @@
+ structureEvent = new StructureGrowEvent(location, treeType, isBonemeal, (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
+ org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent);
+ }
+
+ BlockFertilizeEvent fertilizeEvent = new BlockFertilizeEvent(CraftBlock.at(world, blockposition), (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
+ fertilizeEvent.setCancelled(structureEvent != null && structureEvent.isCancelled());
+ org.bukkit.Bukkit.getPluginManager().callEvent(fertilizeEvent);
@@ -246,9 +246,11 @@
+ world.capturedTileEntities.clear(); // Paper - Allow chests to be placed with NBT data; clear out block entities as chests and such will pop loot
+ // revert back all captured blocks
+ world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710
+ world.isBlockPlaceCancelled = true; // Paper - prevent calling cleanup logic when undoing a block place upon a cancelled BlockPlaceEvent
+ for (BlockState blockstate : blocks) {
+ blockstate.update(true, false);
+ }
+ world.isBlockPlaceCancelled = false; // Paper - prevent calling cleanup logic when undoing a block place upon a cancelled BlockPlaceEvent
+ world.preventPoiUpdated = false;
+
+ // Brute force all possible updates
@@ -356,7 +358,7 @@
ItemStack itemstack = this.copy();
boolean flag = this.getUseDuration(user) <= 0;
InteractionResult enuminteractionresult = this.getItem().use(world, user, hand);
@@ -490,27 +704,66 @@
@@ -490,27 +706,66 @@
return this.isDamageableItem() && this.getDamageValue() >= this.getMaxDamage() - 1;
}
@@ -430,7 +432,7 @@
this.shrink(1);
breakCallback.accept(item);
@@ -518,7 +771,7 @@
@@ -518,7 +773,7 @@
}
@@ -439,7 +441,7 @@
if (player instanceof ServerPlayer entityplayer) {
int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer);
@@ -535,6 +788,11 @@
@@ -535,6 +790,11 @@
}
public void hurtAndBreak(int amount, LivingEntity entity, EquipmentSlot slot) {
@@ -451,7 +453,7 @@
Level world = entity.level();
if (world instanceof ServerLevel worldserver) {
@@ -546,9 +804,9 @@
@@ -546,9 +806,9 @@
entityplayer = null;
}
@@ -464,7 +466,7 @@
}
}
@@ -580,11 +838,11 @@
@@ -580,11 +840,11 @@
return this.getItem().getBarColor(this);
}
@@ -478,7 +480,7 @@
return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference);
}
@@ -592,8 +850,8 @@
@@ -592,8 +852,8 @@
Item item = this.getItem();
if (item.hurtEnemy(this, target, user)) {
@@ -489,7 +491,7 @@
entityhuman.awardStat(Stats.ITEM_USED.get(item));
}
@@ -608,7 +866,7 @@
@@ -608,7 +868,7 @@
this.getItem().postHurtEnemy(this, target, user);
}
@@ -498,7 +500,7 @@
Item item = this.getItem();
if (item.mineBlock(this, world, state, pos, miner)) {
@@ -617,11 +875,11 @@
@@ -617,11 +877,11 @@
}
@@ -512,7 +514,7 @@
return this.getItem().interactLivingEntity(this, user, entity, hand);
}
@@ -736,7 +994,7 @@
@@ -736,7 +996,7 @@
}
@@ -521,7 +523,7 @@
player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount);
this.getItem().onCraftedBy(this, world, player);
}
@@ -768,7 +1026,13 @@
@@ -768,7 +1028,13 @@
public boolean useOnRelease() {
return this.getItem().useOnRelease(this);
@@ -535,7 +537,7 @@
@Nullable
public <T> T set(DataComponentType<? super T> type, @Nullable T value) {
@@ -805,6 +1069,25 @@
@@ -805,6 +1071,25 @@
this.getItem().verifyComponentsAfterLoad(this);
}
}
@@ -561,7 +563,7 @@
public void applyComponents(DataComponentPatch changes) {
this.components.applyPatch(changes);
@@ -858,7 +1141,7 @@
@@ -858,7 +1143,7 @@
}
private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> componentType, Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type) {
@@ -570,7 +572,7 @@
if (t0 != null) {
t0.addToTooltip(context, textConsumer, type);
@@ -866,7 +1149,7 @@
@@ -866,7 +1151,7 @@
}
@@ -579,7 +581,7 @@
boolean flag = this.getItem().shouldPrintOpWarning(this, player);
if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) {
@@ -941,7 +1224,7 @@
@@ -941,7 +1226,7 @@
}
}
@@ -588,7 +590,7 @@
ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
if (itemattributemodifiers.showInTooltip()) {
@@ -966,7 +1249,7 @@
@@ -966,7 +1251,7 @@
}
}
@@ -597,7 +599,7 @@
double d0 = modifier.amount();
boolean flag = false;
@@ -1091,6 +1374,19 @@
@@ -1091,6 +1376,19 @@
EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer);
}
@@ -617,7 +619,7 @@
public Component getDisplayName() {
MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName());
@@ -1153,7 +1449,7 @@
@@ -1153,7 +1451,7 @@
}
public void consume(int amount, @Nullable LivingEntity entity) {