Faster redstone torch rapid clock removal

Only resize the the redstone torch list once, since resizing arrays / lists is costly
This commit is contained in:
Martin Panzer
2016-05-23 12:12:37 +02:00
parent bdd96190e0
commit ef21fd4166
2 changed files with 64 additions and 26 deletions

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/level/block/RedstoneTorchBlock.java
+++ b/net/minecraft/world/level/block/RedstoneTorchBlock.java
@@ -22,6 +22,8 @@
@@ -22,11 +22,13 @@
import net.minecraft.world.level.redstone.ExperimentalRedstoneUtils;
import net.minecraft.world.level.redstone.Orientation;
@@ -9,9 +9,29 @@
public class RedstoneTorchBlock extends BaseTorchBlock {
public static final MapCodec<RedstoneTorchBlock> CODEC = simpleCodec(RedstoneTorchBlock::new);
@@ -85,8 +87,24 @@
list.remove(0);
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;
@@ -79,14 +81,34 @@
@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();
@@ -34,7 +54,7 @@
world.setBlock(pos, (BlockState) state.setValue(RedstoneTorchBlock.LIT, false), 3);
if (RedstoneTorchBlock.isToggledTooFrequently(world, pos, true)) {
world.levelEvent(1502, pos, 0);
@@ -94,6 +112,15 @@
@@ -94,6 +116,15 @@
}
}
} else if (!flag && !RedstoneTorchBlock.isToggledTooFrequently(world, pos, false)) {
@@ -50,3 +70,19 @@
world.setBlock(pos, (BlockState) state.setValue(RedstoneTorchBlock.LIT, true), 3);
}
@@ -134,9 +165,12 @@
}
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()));