summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockRedstoneOre.patch
blob: 01d88722ff1055016b28fe5156edd512fad48ee6 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
--- a/net/minecraft/server/BlockRedstoneOre.java
+++ b/net/minecraft/server/BlockRedstoneOre.java
@@ -2,6 +2,11 @@
 
 import java.util.Random;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
 public class BlockRedstoneOre extends Block {
 
     public static final BlockStateBoolean a = BlockRedstoneTorch.LIT;
@@ -16,23 +21,44 @@
     }
 
     public void attack(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman) {
-        interact(iblockdata, world, blockposition);
+        interact(iblockdata, world, blockposition, entityhuman); // CraftBukkit - add entityhuman
         super.attack(iblockdata, world, blockposition, entityhuman);
     }
 
     public void stepOn(World world, BlockPosition blockposition, Entity entity) {
-        interact(world.getType(blockposition), world, blockposition);
-        super.stepOn(world, blockposition, entity);
+        // CraftBukkit start
+        // interact(world.getType(blockposition), world, blockposition);
+        // super.stepOn(world, blockposition, entity);
+        if (entity instanceof EntityHuman) {
+            org.bukkit.event.player.PlayerInteractEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+            if (!event.isCancelled()) {
+                interact(world.getType(blockposition), world, blockposition, entity); // add entity
+                super.stepOn(world, blockposition, entity);
+            }
+        } else {
+            EntityInteractEvent event = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+            world.getServer().getPluginManager().callEvent(event);
+            if (!event.isCancelled()) {
+                interact(world.getType(blockposition), world, blockposition, entity); // add entity
+                super.stepOn(world, blockposition, entity);
+            }
+        }
+        // CraftBukkit end
     }
 
     public boolean interact(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, EnumDirection enumdirection, float f, float f1, float f2) {
-        interact(iblockdata, world, blockposition);
+        interact(iblockdata, world, blockposition, entityhuman); // CraftBukkit - add entityhuman
         return super.interact(iblockdata, world, blockposition, entityhuman, enumhand, enumdirection, f, f1, f2);
     }
 
-    private static void interact(IBlockData iblockdata, World world, BlockPosition blockposition) {
+    private static void interact(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { // CraftBukkit - add Entity
         playEffect(world, blockposition);
         if (!(Boolean) iblockdata.get(BlockRedstoneOre.a)) {
+            // CraftBukkit start
+            if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata.set(BlockRedstoneOre.a, true)).isCancelled()) {
+                return;
+            }
+            // CraftBukkit end
             world.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockRedstoneOre.a, true), 3);
         }
 
@@ -40,6 +66,11 @@
 
     public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Random random) {
         if ((Boolean) iblockdata.get(BlockRedstoneOre.a)) {
+            // CraftBukkit start
+            if (CraftEventFactory.callBlockFadeEvent(world, blockposition, iblockdata.set(BlockRedstoneOre.a, false)).isCancelled()) {
+                return;
+            }
+            // CraftBukkit end
             world.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockRedstoneOre.a, false), 3);
         }
 
@@ -59,12 +90,25 @@
 
     public void dropNaturally(IBlockData iblockdata, World world, BlockPosition blockposition, float f, int i) {
         super.dropNaturally(iblockdata, world, blockposition, f, i);
+        /* CraftBukkit start - Delegated to getExpDrop
         if (this.getDropType(iblockdata, world, blockposition, i) != this) {
             int j = 1 + world.random.nextInt(5);
 
             this.dropExperience(world, blockposition, j);
         }
+        // */
+
+    }
 
+    @Override
+    public int getExpDrop(IBlockData iblockdata, World world, BlockPosition blockposition, int enchantmentLevel) {
+        if (this.getDropType(iblockdata, world, blockposition, enchantmentLevel) != this) {
+            int j = 1 + world.random.nextInt(5);
+
+            return j;
+        }
+        return 0;
+        // CraftBukkit end
     }
 
     private static void playEffect(World world, BlockPosition blockposition) {