Reduce allocation in SignalGetter
Shiroha CI / build (push) Canceled after 0s
Shiroha CI / Event File (push) Canceled after 0s

This commit is contained in:
2026-08-07 15:51:57 +08:00
parent f1ad249c11
commit d1786e96ef
57 changed files with 64 additions and 0 deletions
@@ -0,0 +1,64 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NanaChiyo0721 <nanachiyo0721@163.com>
Date: Fri, 7 Aug 2026 15:42:07 +0800
Subject: [PATCH] Reduce allocation in SignalGetter
diff --git a/net/minecraft/world/level/SignalGetter.java b/net/minecraft/world/level/SignalGetter.java
index b2ff063a5bfc7e73557f17896a1eadee0d39b735..435cd36c961158dd900af473d5c9c89980a1abab 100644
--- a/net/minecraft/world/level/SignalGetter.java
+++ b/net/minecraft/world/level/SignalGetter.java
@@ -17,32 +17,47 @@ public interface SignalGetter extends BlockGetter {
default int getDirectSignalTo(final BlockPos pos) {
int result = 0;
- result = Math.max(result, this.getDirectSignal(pos.below(), Direction.DOWN));
+ // Shiroha start - Reduce allocation in SignalGetter
+ var localPosForCompute = new net.minecraft.core.BlockPos.MutableBlockPos(pos.getX(), pos.getY(), pos.getZ()); // replace with singleton to reduce allocation
+ localPosForCompute.setY(localPosForCompute.getY() - 1); // below
+ result = Math.max(result, this.getDirectSignal(localPosForCompute, Direction.DOWN));
+ // Shiroha end - Reduce allocation in SignalGetter
if (result >= Redstone.SIGNAL_MAX) {
return result;
}
- result = Math.max(result, this.getDirectSignal(pos.above(), Direction.UP));
+ localPosForCompute.setY(localPosForCompute.getY() + 2); // Shiroha - Reduce allocation in SignalGetter - reset below, above -> 1+1(2)
+ result = Math.max(result, this.getDirectSignal(localPosForCompute, Direction.UP)); // Shiroha - Reduce allocation in SignalGetter
if (result >= Redstone.SIGNAL_MAX) {
return result;
}
- result = Math.max(result, this.getDirectSignal(pos.north(), Direction.NORTH));
+ // Shiroha start - Reduce allocation in SignalGetter
+ localPosForCompute.setY(localPosForCompute.getY() - 1);
+ localPosForCompute.setZ(localPosForCompute.getZ() - 1);
+ // Shiroha end - Reduce allocation in SignalGetter
+ result = Math.max(result, this.getDirectSignal(localPosForCompute, Direction.NORTH)); // Shiroha - Reduce allocation in SignalGetter
if (result >= Redstone.SIGNAL_MAX) {
return result;
}
- result = Math.max(result, this.getDirectSignal(pos.south(), Direction.SOUTH));
+ localPosForCompute.setZ(localPosForCompute.getZ() + 2); // Shiroha - Reduce allocation in SignalGetter - reset north, south -> 1+1(2)
+ result = Math.max(result, this.getDirectSignal(localPosForCompute, Direction.SOUTH)); // Shiroha - Reduce allocation in SignalGetter
if (result >= Redstone.SIGNAL_MAX) {
return result;
}
- result = Math.max(result, this.getDirectSignal(pos.west(), Direction.WEST));
+ // Shiroha start - Reduce allocation in SignalGetter
+ localPosForCompute.setZ(localPosForCompute.getZ() - 1);
+ localPosForCompute.setX(localPosForCompute.getX() - 1);
+ // Shiroha end - Reduce allocation in SignalGetter
+ result = Math.max(result, this.getDirectSignal(localPosForCompute, Direction.WEST)); // Shiroha - Reduce allocation in SignalGetter
if (result >= Redstone.SIGNAL_MAX) {
return result;
}
- result = Math.max(result, this.getDirectSignal(pos.east(), Direction.EAST));
+ localPosForCompute.setX(localPosForCompute.getX() + 2); // Shiroha - Reduce allocation in SignalGetter - reset west, east -> 1+1(2)
+ result = Math.max(result, this.getDirectSignal(localPosForCompute, Direction.EAST)); // Shiroha - Reduce allocation in SignalGetter
return result >= Redstone.SIGNAL_MAX ? result : result;
}