Skip to content

Commit 84aa160

Browse files
committed
Validate beacon effect selections
Beacons don't do any validation on the selected effects except for checking whether the effects are in the whitelist. This commit adds validation to check if a secondary-only effect (regeneration) is used as a primary and whether the effect is allowed to be selected according to the beacon's level. Closes #13631.
1 parent 5d62ec0 commit 84aa160

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

build-data/paper.at

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ public net.minecraft.world.level.block.entity.BarrelBlockEntity playSound(Lnet/m
628628
public net.minecraft.world.level.block.entity.BarrelBlockEntity updateBlockState(Lnet/minecraft/world/level/block/state/BlockState;Z)V
629629
public net.minecraft.world.level.block.entity.BaseContainerBlockEntity lockKey
630630
public net.minecraft.world.level.block.entity.BaseContainerBlockEntity name
631+
public net.minecraft.world.level.block.entity.BeaconBlockEntity MAX_LEVELS
631632
public net.minecraft.world.level.block.entity.BeaconBlockEntity levels
632633
public net.minecraft.world.level.block.entity.BeaconBlockEntity lockKey
633634
public net.minecraft.world.level.block.entity.BeaconBlockEntity name

paper-server/patches/sources/net/minecraft/world/inventory/BeaconMenu.java.patch

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
return stillValid(this.access, player, Blocks.BEACON);
6565
}
6666

67-
@@ -143,13 +_,30 @@
67+
@@ -143,13 +_,53 @@
6868
public @Nullable Holder<MobEffect> getSecondaryEffect() {
6969
return decodeEffect(this.beaconData.get(2));
7070
}
@@ -75,11 +75,34 @@
7575
+ // Paper end - Add PlayerChangeBeaconEffectEvent
7676

7777
- public void updateEffects(final Optional<Holder<MobEffect>> primary, final Optional<Holder<MobEffect>> secondary) {
78-
+ public void updateEffects(final Optional<Holder<MobEffect>> primary, Optional<Holder<MobEffect>> secondary) { // Paper - fix MC-174630 - make non-final
79-
+ // Paper start - fix MC-174630 - validate secondary power
80-
+ if (secondary.isPresent() && secondary.get() != net.minecraft.world.effect.MobEffects.REGENERATION && (primary.isPresent() && secondary.get() != primary.get())) {
78+
+ public void updateEffects(Optional<Holder<MobEffect>> primary, Optional<Holder<MobEffect>> secondary) { // Paper - make non-final
79+
+ // Paper start
80+
+ if (!(this.access.getWorld().getBlockEntity(this.access.getPosition()) instanceof net.minecraft.world.level.block.entity.BeaconBlockEntity beaconEntity)) {
81+
+ return;
82+
+ }
83+
+ if (secondary.isPresent() && secondary.get() != net.minecraft.world.effect.MobEffects.REGENERATION && (primary.isPresent() && secondary.get() != primary.get())) { // fix MC-174630 - validate secondary power
84+
+ secondary = Optional.empty();
85+
+ }
86+
+ // Only max level beacon is allowed to have a secondary effect
87+
+ if (beaconEntity.levels != net.minecraft.world.level.block.entity.BeaconBlockEntity.MAX_LEVELS) {
8188
+ secondary = Optional.empty();
8289
+ }
90+
+ if (primary.isPresent()) {
91+
+ boolean primaryAllowed = false;
92+
+ // Regeneration can never be the primary effect, so we only check up until the second to last level
93+
+ for (int i = 0; i < Math.min(beaconEntity.levels, net.minecraft.world.level.block.entity.BeaconBlockEntity.MAX_LEVELS - 1); i++) {
94+
+ java.util.List<Holder<MobEffect>> allowedEffects = net.minecraft.world.level.block.entity.BeaconBlockEntity.BEACON_EFFECTS.get(i);
95+
+ if (allowedEffects.contains(primary.get())) {
96+
+ primaryAllowed = true;
97+
+ break;
98+
+ }
99+
+ }
100+
+ if (!primaryAllowed) {
101+
+ // Secondary must always be cleared: a beacon can't have just a secondary effect
102+
+ primary = Optional.empty();
103+
+ secondary = Optional.empty();
104+
+ }
105+
+ }
83106
+ // Paper end
84107
if (this.paymentSlot.hasItem()) {
85108
- this.beaconData.set(1, encodeEffect(primary.orElse(null)));

0 commit comments

Comments
 (0)