mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
AnvilDamageEvent
This commit is contained in:
parent
fb64feeb61
commit
f20fbf5477
1 changed files with 23 additions and 6 deletions
|
@ -41,7 +41,24 @@
|
|||
this.inputSlots.setItem(0, ItemStack.EMPTY);
|
||||
this.access.execute((world, blockposition) -> {
|
||||
BlockState iblockdata = world.getBlockState(blockposition);
|
||||
@@ -143,8 +152,8 @@
|
||||
@@ -102,6 +111,16 @@
|
||||
if (!player.hasInfiniteMaterials() && iblockdata.is(BlockTags.ANVIL) && player.getRandom().nextFloat() < 0.12F) {
|
||||
BlockState iblockdata1 = AnvilBlock.damage(iblockdata);
|
||||
|
||||
+ // Paper start - AnvilDamageEvent
|
||||
+ com.destroystokyo.paper.event.block.AnvilDamagedEvent event = new com.destroystokyo.paper.event.block.AnvilDamagedEvent(getBukkitView(), iblockdata1 != null ? org.bukkit.craftbukkit.block.data.CraftBlockData.fromData(iblockdata1) : null);
|
||||
+ if (!event.callEvent()) {
|
||||
+ return;
|
||||
+ } else if (event.getDamageState() == com.destroystokyo.paper.event.block.AnvilDamagedEvent.DamageState.BROKEN) {
|
||||
+ iblockdata1 = null;
|
||||
+ } else {
|
||||
+ iblockdata1 = ((org.bukkit.craftbukkit.block.data.CraftBlockData) event.getDamageState().getMaterial().createBlockData()).getState().setValue(AnvilBlock.FACING, iblockdata.getValue(AnvilBlock.FACING));
|
||||
+ }
|
||||
+ // Paper end - AnvilDamageEvent
|
||||
if (iblockdata1 == null) {
|
||||
world.removeBlock(blockposition, false);
|
||||
world.levelEvent(1029, blockposition, 0);
|
||||
@@ -143,8 +162,8 @@
|
||||
if (itemstack1.isDamageableItem() && itemstack.isValidRepairItem(itemstack2)) {
|
||||
k = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4);
|
||||
if (k <= 0) {
|
||||
|
@ -52,7 +69,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
@@ -158,8 +167,8 @@
|
||||
@@ -158,8 +177,8 @@
|
||||
this.repairItemCountCost = i1;
|
||||
} else {
|
||||
if (!flag && (!itemstack1.is(itemstack2.getItem()) || !itemstack1.isDamageableItem())) {
|
||||
|
@ -63,7 +80,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
@@ -233,8 +242,8 @@
|
||||
@@ -233,8 +252,8 @@
|
||||
}
|
||||
|
||||
if (flag2 && !flag1) {
|
||||
|
@ -74,7 +91,7 @@
|
|||
return;
|
||||
}
|
||||
}
|
||||
@@ -260,14 +269,14 @@
|
||||
@@ -260,14 +279,14 @@
|
||||
}
|
||||
|
||||
if (b0 == i && b0 > 0) {
|
||||
|
@ -92,7 +109,7 @@
|
|||
itemstack1 = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@@ -285,12 +294,13 @@
|
||||
@@ -285,12 +304,13 @@
|
||||
EnchantmentHelper.setEnchantments(itemstack1, itemenchantments_a.toImmutable());
|
||||
}
|
||||
|
||||
|
@ -109,7 +126,7 @@
|
|||
}
|
||||
|
||||
public static int calculateIncreasedRepairCost(int cost) {
|
||||
@@ -329,4 +339,19 @@
|
||||
@@ -329,4 +349,19 @@
|
||||
public int getCost() {
|
||||
return this.cost.get();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue