From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NanaChiyo0721 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; }