summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockRedstoneOre.patch
blob: 0bfc945b831314848b967dbb3efd7d7c58817c9a (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
--- ../work/decompile-8eb82bde//net/minecraft/server/BlockRedstoneOre.java	2014-11-28 17:43:42.949707438 +0000
+++ src/main/java/net/minecraft/server/BlockRedstoneOre.java	2014-11-28 17:38:23.000000000 +0000
@@ -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 {
 
     private final boolean a;
@@ -20,23 +25,44 @@
     }
 
     public void attack(World world, BlockPosition blockposition, EntityHuman entityhuman) {
-        this.d(world, blockposition);
+        this.d(world, blockposition, entityhuman); // CraftBukkit - add entityhuman
         super.attack(world, blockposition, entityhuman);
     }
 
-    public void a(World world, BlockPosition blockposition, Entity entity) {
-        this.d(world, blockposition);
-        super.a(world, blockposition, entity);
+    public void a(World world, BlockPosition blockposition, Entity entity) { 
+        // CraftBukkit start
+        // this.d(world, blockposition);
+        // super.a(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);
+            if (!event.isCancelled()) {
+                this.d(world, blockposition, entity); // add entity
+                super.a(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()) {
+                this.d(world, blockposition, entity); // add entity
+                super.a(world, blockposition, entity);  
+            }
+        }
+        // CraftBukkit end
     }
 
     public boolean interact(World world, BlockPosition blockposition, IBlockData iblockdata, EntityHuman entityhuman, EnumDirection enumdirection, float f, float f1, float f2) {
-        this.d(world, blockposition);
+        this.d(world, blockposition, entityhuman); // CraftBukkit - add entityhuman
         return super.interact(world, blockposition, iblockdata, entityhuman, enumdirection, f, f1, f2);
     }
 
-    private void d(World world, BlockPosition blockposition) {
+    private void d(World world, BlockPosition blockposition, Entity entity) { // CraftBukkit - add Entity
         this.e(world, blockposition);
         if (this == Blocks.REDSTONE_ORE) {
+            // CraftBukkit start
+            if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition.getX(), blockposition.getY(), blockposition.getZ(), Blocks.LIT_REDSTONE_ORE, 0).isCancelled()) {
+                return;
+            }
+            // CraftBukkit end
             world.setTypeUpdate(blockposition, Blocks.LIT_REDSTONE_ORE.getBlockData());
         }
 
@@ -44,6 +70,11 @@
 
     public void b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
         if (this == Blocks.LIT_REDSTONE_ORE) {
+            // CraftBukkit start
+            if (CraftEventFactory.callBlockFadeEvent(world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), Blocks.REDSTONE_ORE).isCancelled()) {
+                return;
+            }
+            // CraftBukkit end
             world.setTypeUpdate(blockposition, Blocks.REDSTONE_ORE.getBlockData());
         }
 
@@ -63,12 +94,24 @@
 
     public void dropNaturally(World world, BlockPosition blockposition, IBlockData iblockdata, float f, int i) {
         super.dropNaturally(world, blockposition, iblockdata, f, i);
+        /* CraftBukkit start - Delegated to getExpDrop
         if (this.getDropType(iblockdata, world.random, i) != Item.getItemOf(this)) {
             int j = 1 + world.random.nextInt(5);
 
             this.dropExperience(world, blockposition, j);
         }
+        // */
+    }
 
+    @Override
+    public int getExpDrop(World world, IBlockData data, int i) {
+        if (this.getDropType(data, world.random, i) != Item.getItemOf(this)) {
+            int j = 1 + world.random.nextInt(5);
+
+            return j;
+        }
+        return 0;
+        // CraftBukkit end
     }
 
     private void e(World world, BlockPosition blockposition) {