aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0094-Option-to-disable-BlockPhysicsEvent-for-Redstone.patch
blob: 1e0fd7ebe4e186d62acfd1f6606cb3d9c30e35ce (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
From c80433172ca35367589f748c6ac3a0270f33b8f3 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 28 Mar 2016 19:55:45 -0400
Subject: [PATCH] Option to disable BlockPhysicsEvent for Redstone

Not sure of any reason a plugin would need to act on a Physics event
for redstone. There is a BlockRedstoneEvent that plugins can also use
for accessing redstone activity.

Defaulting this to false will provide substantial performance improvement
by saving millions of event calls on redstone heavy servers.

diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index adc810720..e706efff5 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -268,4 +268,9 @@ public class PaperWorldConfig {
     private void skeleHorseSpawnChance() {
         skeleHorseSpawnChance = getDouble("skeleton-horse-thunder-spawn-chance", 0.01D); // -1.0D represents a "vanilla" state
     }
+
+    public boolean firePhysicsEventForRedstone = false;
+    private void firePhysicsEventForRedstone() {
+        firePhysicsEventForRedstone = getBoolean("fire-physics-event-for-redstone", firePhysicsEventForRedstone);
+    }
 }
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 9427fc080..8cbdbda92 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -578,7 +578,7 @@ public abstract class World implements IBlockAccess {
             try {
                 // CraftBukkit start
                 CraftWorld world = ((WorldServer) this).getWorld();
-                if (world != null) {
+                if (world != null && !((WorldServer)this).stopPhysicsEvent) { // Paper
                     BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftMagicNumbers.getId(block));
                     this.getServer().getPluginManager().callEvent(event);
 
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 39ed0d533..f969d2a72 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -34,6 +34,7 @@ import org.bukkit.event.weather.LightningStrikeEvent;
 public class WorldServer extends World implements IAsyncTaskHandler {
 
     private static final Logger a = LogManager.getLogger();
+    boolean stopPhysicsEvent = false; // Paper
     private final MinecraftServer server;
     public EntityTracker tracker;
     private final PlayerChunkMap manager;
@@ -727,6 +728,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
 
                         if (iblockdata.getMaterial() != Material.AIR && Block.a(iblockdata.getBlock(), nextticklistentry.a())) {
                             try {
+                                stopPhysicsEvent = !paperConfig.firePhysicsEventForRedstone && (iblockdata.getBlock() instanceof BlockDiodeAbstract || iblockdata.getBlock() instanceof BlockRedstoneTorch); // Paper
                                 iblockdata.getBlock().b((World) this, nextticklistentry.a, iblockdata, this.random);
                             } catch (Throwable throwable) {
                                 CrashReport crashreport = CrashReport.a(throwable, "Exception while ticking a block");
@@ -734,7 +736,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
 
                                 CrashReportSystemDetails.a(crashreportsystemdetails, nextticklistentry.a, iblockdata);
                                 throw new ReportedException(crashreport);
-                            }
+                            } finally { stopPhysicsEvent = false; } // Paper
                         }
                         timing.stopTiming(); // Paper
                     } else {
-- 
2.12.2