9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-28 03:19:21 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0252-Rail-Optimization-optimized-PoweredRailBlock-logic.patch
Dreeam 9a4efaa230 Drop patch that causes performance regression
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2
since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList.
Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2
lazy handles filter condition on iteration, so much better.
2025-08-04 19:25:56 +08:00

31 lines
1.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Sat, 17 Feb 2024 17:57:08 -0500
Subject: [PATCH] Rail Optimization: optimized PoweredRailBlock logic
Original project: https://github.com/FxMorin/RailOptimization
Full Rewrite of the powered rail iteration logic
that makes powered/activator rails turning on/off up to 4x faster.
This rewrite brings a massive performance boost while keeping the vanilla order. This is achieved by running all the
powered rail logic from a single rail instead of each block iterating separately. Which was not only very
expensive but also completely unnecessary and with a lot of massive overhead
diff --git a/net/minecraft/world/level/block/PoweredRailBlock.java b/net/minecraft/world/level/block/PoweredRailBlock.java
index ebc0df13fc204472742a611b25f1ffd34478b042..1e2f6ef1db365747621d9814ffe3d63fe3e143d8 100644
--- a/net/minecraft/world/level/block/PoweredRailBlock.java
+++ b/net/minecraft/world/level/block/PoweredRailBlock.java
@@ -122,6 +122,12 @@ public class PoweredRailBlock extends BaseRailBlock {
@Override
protected void updateState(BlockState state, Level level, BlockPos pos, Block block) {
+ // Leaf start - Rail Optimization
+ if (org.dreeam.leaf.config.modules.opt.OptimizedPoweredRails.enabled) {
+ org.dreeam.leaf.world.block.OptimizedPoweredRails.updateState(this, state, level, pos);
+ return;
+ }
+ // Leaf end - Rail Optimization
boolean poweredValue = state.getValue(POWERED);
boolean flag = level.hasNeighborSignal(pos)
|| this.findPoweredRailSignal(level, pos, state, true, 0)