aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0103-Faster-redstone-torch-rapid-clock-removal.patch
blob: 4ec00fb17ac6b0724c375dc7ebed4cc075f5f357 (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martin Panzer <postremus1996@googlemail.com>
Date: Mon, 23 May 2016 12:12:37 +0200
Subject: [PATCH] Faster redstone torch rapid clock removal

Only resize the the redstone torch list once, since resizing arrays / lists is costly

diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 33c9001970fe01bedd72f6ba4388b43ed9707fc8..95fc5fc293eb7d77868fa0a37beb792ee0620fcd 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -168,6 +168,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
     private org.spigotmc.TickLimiter tileLimiter;
     private int tileTickPosition;
     public final Map<Explosion.CacheKey, Float> explosionDensityCache = new HashMap<>(); // Paper - Optimize explosions
+    public java.util.ArrayDeque<net.minecraft.world.level.block.RedstoneTorchBlock.Toggle> redstoneUpdateInfos; // Paper - Faster redstone torch rapid clock removal; Move from Map in BlockRedstoneTorch to here
 
     public CraftWorld getWorld() {
         return this.world;
diff --git a/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java b/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java
index 20d20db2639030c103e9d1b3c8da0f51344b81c2..ceba9617748a8b4f3a9bd459475952c9c6c9ed7c 100644
--- a/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java
@@ -24,7 +24,7 @@ public class RedstoneTorchBlock extends BaseTorchBlock {
 
     public static final MapCodec<RedstoneTorchBlock> CODEC = simpleCodec(RedstoneTorchBlock::new);
     public static final BooleanProperty LIT = BlockStateProperties.LIT;
-    private static final Map<BlockGetter, List<RedstoneTorchBlock.Toggle>> RECENT_TOGGLES = new WeakHashMap();
+    // Paper - Faster redstone torch rapid clock removal; Move the mapped list to World
     public static final int RECENT_TOGGLE_TIMER = 60;
     public static final int MAX_RECENT_TOGGLES = 8;
     public static final int RESTART_DELAY = 160;
@@ -80,11 +80,15 @@ public class RedstoneTorchBlock extends BaseTorchBlock {
     @Override
     protected void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
         boolean flag = this.hasNeighborSignal(world, pos, state);
-        List<RedstoneTorchBlock.Toggle> list = (List) RedstoneTorchBlock.RECENT_TOGGLES.get(world);
-
-        while (list != null && !list.isEmpty() && world.getGameTime() - ((RedstoneTorchBlock.Toggle) list.get(0)).when > 60L) {
-            list.remove(0);
+        // Paper start - Faster redstone torch rapid clock removal
+        java.util.ArrayDeque<RedstoneTorchBlock.Toggle> redstoneUpdateInfos = world.redstoneUpdateInfos;
+        if (redstoneUpdateInfos != null) {
+            RedstoneTorchBlock.Toggle curr;
+            while ((curr = redstoneUpdateInfos.peek()) != null && world.getGameTime() - curr.when > 60L) {
+                redstoneUpdateInfos.poll();
+            }
         }
+        // Paper end - Faster redstone torch rapid clock removal
 
         // CraftBukkit start
         org.bukkit.plugin.PluginManager manager = world.getCraftServer().getPluginManager();
@@ -160,9 +164,12 @@ public class RedstoneTorchBlock extends BaseTorchBlock {
     }
 
     private static boolean isToggledTooFrequently(Level world, BlockPos pos, boolean addNew) {
-        List<RedstoneTorchBlock.Toggle> list = (List) RedstoneTorchBlock.RECENT_TOGGLES.computeIfAbsent(world, (iblockaccess) -> {
-            return Lists.newArrayList();
-        });
+        // Paper start - Faster redstone torch rapid clock removal
+        java.util.ArrayDeque<RedstoneTorchBlock.Toggle> list = world.redstoneUpdateInfos;
+        if (list == null) {
+            list = world.redstoneUpdateInfos = new java.util.ArrayDeque<>();
+        }
+        // Paper end - Faster redstone torch rapid clock removal
 
         if (addNew) {
             list.add(new RedstoneTorchBlock.Toggle(pos.immutable(), world.getGameTime()));