From c9e125f62aaf95ac8bda912381392687835e1f2f Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Thu, 8 Jun 2023 22:35:52 -0700 Subject: [PATCH] Fix setListenerRange for calibrated sculk sensors --- ...igurable-sculk-sensor-listener-range.patch | 111 ++++++++++++------ 1 file changed, 72 insertions(+), 39 deletions(-) diff --git a/patches/server/0789-Configurable-sculk-sensor-listener-range.patch b/patches/server/0789-Configurable-sculk-sensor-listener-range.patch index f3a0edca2a..c68e2d2cc3 100644 --- a/patches/server/0789-Configurable-sculk-sensor-listener-range.patch +++ b/patches/server/0789-Configurable-sculk-sensor-listener-range.patch @@ -6,52 +6,85 @@ Subject: [PATCH] Configurable sculk sensor listener range == AT == public-f net.minecraft.world.level.gameevent.vibrations.VibrationListener listenerRange -diff --git a/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java -index a6c226da995eecc323d69a3eff1f8d202410e069..4db0227e24cb5afd9f34307ff9ff920c67be0489 100644 ---- a/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java -+++ b/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java -@@ -48,9 +48,11 @@ public class SculkSensorBlockEntity extends BlockEntity implements GameEventList - this.vibrationData = listener; - }); - } -+ if (nbt.contains(PAPER_LISTENER_RANGE_NBT_KEY)) this.getListener().rangeOverride = nbt.getInt(PAPER_LISTENER_RANGE_NBT_KEY); // Paper - +diff --git a/src/main/java/net/minecraft/world/level/block/entity/CalibratedSculkSensorBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/CalibratedSculkSensorBlockEntity.java +index a18589425006ccabd87b76a9827ab516040009bb..fb1c47a17c2fe3807ed54fd2b2bb17c2fe28b901 100644 +--- a/src/main/java/net/minecraft/world/level/block/entity/CalibratedSculkSensorBlockEntity.java ++++ b/src/main/java/net/minecraft/world/level/block/entity/CalibratedSculkSensorBlockEntity.java +@@ -19,6 +19,12 @@ public class CalibratedSculkSensorBlockEntity extends SculkSensorBlockEntity { + public VibrationSystem.User createVibrationUser() { + return new CalibratedSculkSensorBlockEntity.VibrationUser(this.getBlockPos()); } ++ // Paper start ++ @Override ++ protected void saveRangeOverride(final net.minecraft.nbt.CompoundTag nbt) { ++ if (this.rangeOverride != null && this.rangeOverride != 16) nbt.putInt(PAPER_LISTENER_RANGE_NBT_KEY, this.rangeOverride); // only save if it's different from the default ++ } ++ // Paper end -+ private static final String PAPER_LISTENER_RANGE_NBT_KEY = "Paper.ListenerRange"; // Paper - @Override - protected void saveAdditional(CompoundTag nbt) { - super.saveAdditional(nbt); -@@ -58,6 +60,7 @@ public class SculkSensorBlockEntity extends BlockEntity implements GameEventList - VibrationSystem.Data.CODEC.encodeStart(NbtOps.INSTANCE, this.vibrationData).resultOrPartial(LOGGER::error).ifPresent((listenerNbt) -> { - nbt.put("listener", listenerNbt); - }); -+ if (this.getListener().rangeOverride != null && this.getListener().rangeOverride != VibrationUser.LISTENER_RANGE) nbt.putInt(PAPER_LISTENER_RANGE_NBT_KEY, this.getListener().rangeOverride); // Paper - only save if it's different from the default - } - - @Override -diff --git a/src/main/java/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java b/src/main/java/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java -index 405709bed99bb0ddd3a746f0f7815b59394c1b81..ac8394b9caa4e0b3101897190a26c28ef8acfbd2 100644 ---- a/src/main/java/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java -+++ b/src/main/java/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java -@@ -261,6 +261,7 @@ public interface VibrationSystem { - public static class Listener implements GameEventListener { - - private final VibrationSystem system; -+ @Nullable public Integer rangeOverride = null; // Paper - - public Listener(VibrationSystem receiver) { - this.system = receiver; -@@ -273,6 +274,7 @@ public interface VibrationSystem { + protected class VibrationUser extends SculkSensorBlockEntity.VibrationUser { + public VibrationUser(BlockPos pos) { +@@ -27,6 +33,7 @@ public class CalibratedSculkSensorBlockEntity extends SculkSensorBlockEntity { @Override public int getListenerRadius() { -+ if (this.rangeOverride != null) return this.rangeOverride; // Paper - return this.system.getVibrationUser().getListenerRadius(); ++ if (CalibratedSculkSensorBlockEntity.this.rangeOverride != null) return CalibratedSculkSensorBlockEntity.this.rangeOverride; // Paper + return 16; + } + +diff --git a/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java +index a6c226da995eecc323d69a3eff1f8d202410e069..5d3740875de337e24fdba28305f61e96d01c457f 100644 +--- a/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java ++++ b/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java +@@ -24,6 +24,7 @@ public class SculkSensorBlockEntity extends BlockEntity implements GameEventList + private final VibrationSystem.Listener vibrationListener; + private final VibrationSystem.User vibrationUser = this.createVibrationUser(); + public int lastVibrationFrequency; ++ @Nullable public Integer rangeOverride = null; // Paper + + protected SculkSensorBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); +@@ -48,9 +49,17 @@ public class SculkSensorBlockEntity extends BlockEntity implements GameEventList + this.vibrationData = listener; + }); + } ++ // Paper start ++ if (nbt.contains(PAPER_LISTENER_RANGE_NBT_KEY)) { ++ this.rangeOverride = nbt.getInt(PAPER_LISTENER_RANGE_NBT_KEY); ++ } else { ++ this.rangeOverride = null; ++ } ++ // Paper end + + } + ++ protected static final String PAPER_LISTENER_RANGE_NBT_KEY = "Paper.ListenerRange"; // Paper + @Override + protected void saveAdditional(CompoundTag nbt) { + super.saveAdditional(nbt); +@@ -58,7 +67,13 @@ public class SculkSensorBlockEntity extends BlockEntity implements GameEventList + VibrationSystem.Data.CODEC.encodeStart(NbtOps.INSTANCE, this.vibrationData).resultOrPartial(LOGGER::error).ifPresent((listenerNbt) -> { + nbt.put("listener", listenerNbt); + }); ++ this.saveRangeOverride(nbt); // Paper ++ } ++ // Paper start ++ protected void saveRangeOverride(CompoundTag nbt) { ++ if (this.rangeOverride != null && this.rangeOverride != VibrationUser.LISTENER_RANGE) nbt.putInt(PAPER_LISTENER_RANGE_NBT_KEY, this.rangeOverride); // only save if it's different from the default + } ++ // Paper end + + @Override + public VibrationSystem.Data getVibrationData() { +@@ -95,6 +110,7 @@ public class SculkSensorBlockEntity extends BlockEntity implements GameEventList + + @Override + public int getListenerRadius() { ++ if (SculkSensorBlockEntity.this.rangeOverride != null) return SculkSensorBlockEntity.this.rangeOverride; // Paper + return 8; } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSculkSensor.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSculkSensor.java -index de804383467518ef0f063aea948514db568f59db..ba4069544de16d3562b55df4d7973e877d66ee1c 100644 +index de804383467518ef0f063aea948514db568f59db..f2599117cc8c12d9402e22c34c76f323b5a1ec5c 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftSculkSensor.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSculkSensor.java @@ -21,4 +21,16 @@ public class CraftSculkSensor extends CraftBlo @@ -67,7 +100,7 @@ index de804383467518ef0f063aea948514db568f59db..ba4069544de16d3562b55df4d7973e87 + @Override + public void setListenerRange(int range) { + Preconditions.checkArgument(range > 0, "Vibration listener range must be greater than 0"); -+ this.getSnapshot().getListener().rangeOverride = range; ++ this.getSnapshot().rangeOverride = range; + } + // Paper end }