Paper/Spigot-Server-Patches/0101-Faster-redstone-torch-rapid-clock-removal.patch
Shane Freeder 0ea3083817
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
1e843b72 #510: Add NamespacedKey#fromString() to fetch from user input
a4d18241 #581: Add methods to modify despawn delay for wandering villagers

CraftBukkit Changes:
0cd8f19f #802: Add methods to modify despawn delay for wandering villagers
d5c5d998 SPIGOT-6362: ConcurrentModificationException: null --> Server Crash
8c7d69fe SPIGOT-5228: Entities that are removed during chunk unloads are not properly removed from the chunk.
2021-02-16 17:13:49 +00:00

91 Zeilen
4.8 KiB
Diff

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/server/BlockRedstoneTorch.java b/src/main/java/net/minecraft/server/BlockRedstoneTorch.java
index d88d435b7777f731bc0bb728ebe4d4cb31c6376e..a63a60348fe45f63deec6fcb27b6be09cd2f088c 100644
--- a/src/main/java/net/minecraft/server/BlockRedstoneTorch.java
+++ b/src/main/java/net/minecraft/server/BlockRedstoneTorch.java
@@ -11,7 +11,7 @@ import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
public class BlockRedstoneTorch extends BlockTorch {
public static final BlockStateBoolean LIT = BlockProperties.r;
- private static final Map<IBlockAccess, List<BlockRedstoneTorch.RedstoneUpdateInfo>> b = new WeakHashMap();
+ // Paper - Move the mapped list to World
protected BlockRedstoneTorch(BlockBase.Info blockbase_info) {
super(blockbase_info, ParticleParamRedstone.a);
@@ -58,11 +58,15 @@ public class BlockRedstoneTorch extends BlockTorch {
@Override
public void tickAlways(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, Random random) {
boolean flag = this.a((World) worldserver, blockposition, iblockdata);
- List list = (List) BlockRedstoneTorch.b.get(worldserver);
-
- while (list != null && !list.isEmpty() && worldserver.getTime() - ((BlockRedstoneTorch.RedstoneUpdateInfo) list.get(0)).b > 60L) {
- list.remove(0);
+ // Paper start
+ java.util.ArrayDeque<BlockRedstoneTorch.RedstoneUpdateInfo> redstoneUpdateInfos = worldserver.redstoneUpdateInfos;
+ if (redstoneUpdateInfos != null) {
+ BlockRedstoneTorch.RedstoneUpdateInfo curr;
+ while ((curr = redstoneUpdateInfos.peek()) != null && worldserver.getTime() - curr.getTime() > 60L) {
+ redstoneUpdateInfos.poll();
+ }
}
+ // Paper end
// CraftBukkit start
org.bukkit.plugin.PluginManager manager = worldserver.getServer().getPluginManager();
@@ -127,9 +131,12 @@ public class BlockRedstoneTorch extends BlockTorch {
}
private static boolean a(World world, BlockPosition blockposition, boolean flag) {
- List<BlockRedstoneTorch.RedstoneUpdateInfo> list = (List) BlockRedstoneTorch.b.computeIfAbsent(world, (iblockaccess) -> {
- return Lists.newArrayList();
- });
+ // Paper start
+ java.util.ArrayDeque<BlockRedstoneTorch.RedstoneUpdateInfo> list = world.redstoneUpdateInfos;
+ if (list == null) {
+ list = world.redstoneUpdateInfos = new java.util.ArrayDeque<>();
+ }
+
if (flag) {
list.add(new BlockRedstoneTorch.RedstoneUpdateInfo(blockposition.immutableCopy(), world.getTime()));
@@ -137,9 +144,9 @@ public class BlockRedstoneTorch extends BlockTorch {
int i = 0;
- for (int j = 0; j < list.size(); ++j) {
- BlockRedstoneTorch.RedstoneUpdateInfo blockredstonetorch_redstoneupdateinfo = (BlockRedstoneTorch.RedstoneUpdateInfo) list.get(j);
-
+ for (java.util.Iterator<BlockRedstoneTorch.RedstoneUpdateInfo> iterator = list.iterator(); iterator.hasNext();) {
+ BlockRedstoneTorch.RedstoneUpdateInfo blockredstonetorch_redstoneupdateinfo = iterator.next();
+ // Paper end
if (blockredstonetorch_redstoneupdateinfo.a.equals(blockposition)) {
++i;
if (i >= 8) {
@@ -154,7 +161,7 @@ public class BlockRedstoneTorch extends BlockTorch {
public static class RedstoneUpdateInfo {
private final BlockPosition a;
- private final long b;
+ private final long b; final long getTime() { return this.b; } // Paper - OBFHELPER
public RedstoneUpdateInfo(BlockPosition blockposition, long i) {
this.a = blockposition;
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 369a6b42a89fd75aeb3da4930f47b6917a1ae393..9ac1f42372a18c0907c7b0137b6a83022e3e984d 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -90,6 +90,7 @@ public abstract class World implements GeneratorAccess, 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<BlockRedstoneTorch.RedstoneUpdateInfo> redstoneUpdateInfos; // Paper - Move from Map in BlockRedstoneTorch to here
public CraftWorld getWorld() {
return this.world;