Paper/patches/server/0100-Faster-redstone-torch-rapid-clock-removal.patch

69 lines
4.1 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
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
2024-06-13 19:30:39 +02:00
index 622ecc1aeb9140d5c0d181fa472d123c42e5c5f4..4abb586f964e342425c7cf0384ab8bf8cdedaea3 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2024-06-13 19:30:39 +02:00
@@ -169,6 +169,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 14:02:28 +02:00
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
2021-06-11 14:02:28 +02:00
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
2024-04-24 03:25:14 +02:00
index 20d20db2639030c103e9d1b3c8da0f51344b81c2..ceba9617748a8b4f3a9bd459475952c9c6c9ed7c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/RedstoneTorchBlock.java
2023-12-05 22:20:44 +01:00
@@ -24,7 +24,7 @@ public class RedstoneTorchBlock extends BaseTorchBlock {
2021-06-11 14:02:28 +02:00
2023-12-05 22:20:44 +01:00
public static final MapCodec<RedstoneTorchBlock> CODEC = simpleCodec(RedstoneTorchBlock::new);
2021-06-11 14:02:28 +02:00
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
2021-06-12 07:20:08 +02:00
public static final int RECENT_TOGGLE_TIMER = 60;
public static final int MAX_RECENT_TOGGLES = 8;
public static final int RESTART_DELAY = 160;
2023-12-05 22:20:44 +01:00
@@ -80,11 +80,15 @@ public class RedstoneTorchBlock extends BaseTorchBlock {
2021-06-11 14:02:28 +02:00
@Override
2024-04-24 03:25:14 +02:00
protected void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
2021-11-23 14:22:49 +01:00
boolean flag = this.hasNeighborSignal(world, pos, state);
2024-04-24 03:25:14 +02:00
- List<RedstoneTorchBlock.Toggle> list = (List) RedstoneTorchBlock.RECENT_TOGGLES.get(world);
2021-06-11 14:02:28 +02:00
-
- 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
2021-06-11 14:02:28 +02:00
+ java.util.ArrayDeque<RedstoneTorchBlock.Toggle> redstoneUpdateInfos = world.redstoneUpdateInfos;
+ if (redstoneUpdateInfos != null) {
+ RedstoneTorchBlock.Toggle curr;
2021-06-12 07:20:08 +02:00
+ while ((curr = redstoneUpdateInfos.peek()) != null && world.getGameTime() - curr.when > 60L) {
2021-06-11 14:02:28 +02:00
+ redstoneUpdateInfos.poll();
+ }
}
+ // Paper end - Faster redstone torch rapid clock removal
2021-06-11 14:02:28 +02:00
// CraftBukkit start
org.bukkit.plugin.PluginManager manager = world.getCraftServer().getPluginManager();
2023-12-05 22:20:44 +01:00
@@ -160,9 +164,12 @@ public class RedstoneTorchBlock extends BaseTorchBlock {
2021-06-11 14:02:28 +02:00
}
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
2021-06-11 14:02:28 +02:00
+ java.util.ArrayDeque<RedstoneTorchBlock.Toggle> list = world.redstoneUpdateInfos;
+ if (list == null) {
+ list = world.redstoneUpdateInfos = new java.util.ArrayDeque<>();
+ }
2024-01-26 19:41:41 +01:00
+ // Paper end - Faster redstone torch rapid clock removal
2021-06-11 14:02:28 +02:00
if (addNew) {
list.add(new RedstoneTorchBlock.Toggle(pos.immutable(), world.getGameTime()));