|
64 | 64 | return stillValid(this.access, player, Blocks.BEACON); |
65 | 65 | } |
66 | 66 |
|
67 | | -@@ -143,13 +_,30 @@ |
| 67 | +@@ -143,13 +_,53 @@ |
68 | 68 | public @Nullable Holder<MobEffect> getSecondaryEffect() { |
69 | 69 | return decodeEffect(this.beaconData.get(2)); |
70 | 70 | } |
|
75 | 75 | + // Paper end - Add PlayerChangeBeaconEffectEvent |
76 | 76 |
|
77 | 77 | - 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) { |
81 | 88 | + secondary = Optional.empty(); |
82 | 89 | + } |
| 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 | ++ } |
83 | 106 | + // Paper end |
84 | 107 | if (this.paymentSlot.hasItem()) { |
85 | 108 | - this.beaconData.set(1, encodeEffect(primary.orElse(null))); |
|
0 commit comments