aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0224-AnvilDamageEvent.patch
blob: fc3492a898fcb603e94448dc82436345813ec97a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Fri, 20 Jul 2018 23:37:03 -0500
Subject: [PATCH] AnvilDamageEvent


diff --git a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
index d829173d2fc9fc0e12c24d736f1ed44417b81612..878d3c3089635a515fa7f54c956159a1bb6ce29b 100644
--- a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
@@ -108,6 +108,16 @@ public class AnvilMenu extends ItemCombinerMenu {
             if (!player.getAbilities().instabuild && 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);