summaryrefslogtreecommitdiffstats
path: root/nms-patches/PathfinderGoalVillagerFarm.patch
blob: 2600cea082f32e98d62e899c571da790eac5b6c3 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--- a/net/minecraft/server/PathfinderGoalVillagerFarm.java
+++ b/net/minecraft/server/PathfinderGoalVillagerFarm.java
@@ -40,7 +40,11 @@
             Block block = iblockdata.getBlock();
 
             if (this.f == 0 && block instanceof BlockCrops && ((BlockCrops) block).z(iblockdata)) {
-                world.setAir(blockposition, true);
+                // CraftBukkit start
+                if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.c, blockposition, Blocks.AIR, 0).isCancelled()) {
+                    world.setAir(blockposition, true);
+                }
+                // CraftBukkit end
             } else if (this.f == 1 && iblockdata.getMaterial() == Material.AIR) {
                 InventorySubcontainer inventorysubcontainer = this.c.dq();
 
@@ -49,19 +53,28 @@
                     boolean flag = false;
 
                     if (!itemstack.isEmpty()) {
+                        // CraftBukkit start
+                        Block planted = null;
                         if (itemstack.getItem() == Items.WHEAT_SEEDS) {
-                            world.setTypeAndData(blockposition, Blocks.WHEAT.getBlockData(), 3);
+                            planted = Blocks.WHEAT;
                             flag = true;
                         } else if (itemstack.getItem() == Items.POTATO) {
-                            world.setTypeAndData(blockposition, Blocks.POTATOES.getBlockData(), 3);
+                            planted = Blocks.POTATOES;
                             flag = true;
                         } else if (itemstack.getItem() == Items.CARROT) {
-                            world.setTypeAndData(blockposition, Blocks.CARROTS.getBlockData(), 3);
+                            planted = Blocks.CARROTS;
                             flag = true;
                         } else if (itemstack.getItem() == Items.BEETROOT_SEEDS) {
-                            world.setTypeAndData(blockposition, Blocks.BEETROOT.getBlockData(), 3);
+                            planted = Blocks.BEETROOT;
                             flag = true;
                         }
+
+                        if (planted != null && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.c, blockposition, planted, 0).isCancelled()) {
+                            world.setTypeAndData(blockposition, planted.getBlockData(), 3);
+                        } else {
+                            flag = false;
+                        }
+                        // CraftBukkit end
                     }
 
                     if (flag) {