13
0
geforkt von Mirrors/Paper

Fix setListenerRange for calibrated sculk sensors

Dieser Commit ist enthalten in:
Jake Potrebic 2023-06-08 22:35:52 -07:00
Ursprung e6be773522
Commit 6cc19431ea

Datei anzeigen

@ -6,19 +6,58 @@ Subject: [PATCH] Configurable sculk sensor listener range
== AT == == AT ==
public-f net.minecraft.world.level.gameevent.vibrations.VibrationListener listenerRange public-f net.minecraft.world.level.gameevent.vibrations.VibrationListener listenerRange
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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
@@ -0,0 +0,0 @@ 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
protected class VibrationUser extends SculkSensorBlockEntity.VibrationUser {
public VibrationUser(BlockPos pos) {
@@ -0,0 +0,0 @@ public class CalibratedSculkSensorBlockEntity extends SculkSensorBlockEntity {
@Override
public int 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 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java --- a/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/SculkSensorBlockEntity.java
@@ -0,0 +0,0 @@ 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);
@@ -0,0 +0,0 @@ public class SculkSensorBlockEntity extends BlockEntity implements GameEventList @@ -0,0 +0,0 @@ public class SculkSensorBlockEntity extends BlockEntity implements GameEventList
this.vibrationData = listener; this.vibrationData = listener;
}); });
} }
+ if (nbt.contains(PAPER_LISTENER_RANGE_NBT_KEY)) this.getListener().rangeOverride = nbt.getInt(PAPER_LISTENER_RANGE_NBT_KEY); // Paper + // 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
} }
+ private static final String PAPER_LISTENER_RANGE_NBT_KEY = "Paper.ListenerRange"; // Paper + protected static final String PAPER_LISTENER_RANGE_NBT_KEY = "Paper.ListenerRange"; // Paper
@Override @Override
protected void saveAdditional(CompoundTag nbt) { protected void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt); super.saveAdditional(nbt);
@ -26,28 +65,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
VibrationSystem.Data.CODEC.encodeStart(NbtOps.INSTANCE, this.vibrationData).resultOrPartial(LOGGER::error).ifPresent((listenerNbt) -> { VibrationSystem.Data.CODEC.encodeStart(NbtOps.INSTANCE, this.vibrationData).resultOrPartial(LOGGER::error).ifPresent((listenerNbt) -> {
nbt.put("listener", 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 + 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 @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 public VibrationSystem.Data getVibrationData() {
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 @@ -0,0 +0,0 @@ public class SculkSensorBlockEntity extends BlockEntity implements GameEventList
--- a/src/main/java/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java
+++ b/src/main/java/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ public interface VibrationSystem {
@Override @Override
public int getListenerRadius() { public int getListenerRadius() {
+ if (this.rangeOverride != null) return this.rangeOverride; // Paper + if (SculkSensorBlockEntity.this.rangeOverride != null) return SculkSensorBlockEntity.this.rangeOverride; // Paper
return this.system.getVibrationUser().getListenerRadius(); return 8;
} }
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSculkSensor.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSculkSensor.java diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSculkSensor.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSculkSensor.java
@ -67,7 +100,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ @Override + @Override
+ public void setListenerRange(int range) { + public void setListenerRange(int range) {
+ Preconditions.checkArgument(range > 0, "Vibration listener range must be greater than 0"); + Preconditions.checkArgument(range > 0, "Vibration listener range must be greater than 0");
+ this.getSnapshot().getListener().rangeOverride = range; + this.getSnapshot().rangeOverride = range;
+ } + }
+ // Paper end + // Paper end
} }