--- a/net/minecraft/world/inventory/BeaconMenu.java
+++ b/net/minecraft/world/inventory/BeaconMenu.java
@@ -7,12 +7,16 @@
 import net.minecraft.world.Container;
 import net.minecraft.world.SimpleContainer;
 import net.minecraft.world.effect.MobEffect;
+import net.minecraft.world.entity.player.Inventory;
 import net.minecraft.world.entity.player.Player;
 import net.minecraft.world.item.ItemStack;
 import net.minecraft.world.level.Level;
 import net.minecraft.world.level.block.Blocks;
+import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryView;
+// CraftBukkit end
 
 public class BeaconMenu extends AbstractContainerMenu {
+
     private static final int PAYMENT_SLOT = 0;
     private static final int SLOT_COUNT = 1;
     private static final int DATA_COUNT = 3;
@@ -21,20 +25,14 @@
     private static final int USE_ROW_SLOT_START = 28;
     private static final int USE_ROW_SLOT_END = 37;
     private static final int NO_EFFECT = 0;
-    private final Container beacon = new SimpleContainer(1) {
-        @Override
-        public boolean canPlaceItem(int slot, ItemStack stack) {
-            return stack.is(ItemTags.BEACON_PAYMENT_ITEMS);
-        }
-
-        @Override
-        public int getMaxStackSize() {
-            return 1;
-        }
-    };
+    private final Container beacon;
     private final BeaconMenu.PaymentSlot paymentSlot;
     private final ContainerLevelAccess access;
     private final ContainerData beaconData;
+    // CraftBukkit start
+    private CraftInventoryView bukkitEntity = null;
+    private Inventory player;
+    // CraftBukkit end
 
     public BeaconMenu(int syncId, Container inventory) {
         this(syncId, inventory, new SimpleContainerData(3), ContainerLevelAccess.NULL);
@@ -42,23 +40,43 @@
 
     public BeaconMenu(int syncId, Container inventory, ContainerData propertyDelegate, ContainerLevelAccess context) {
         super(MenuType.BEACON, syncId);
+        this.player = (Inventory) inventory; // CraftBukkit - TODO: check this
+        this.beacon = new SimpleContainer(this.createBlockHolder(context), 1) { // Paper
+            @Override
+            public boolean canPlaceItem(int slot, ItemStack stack) {
+                return stack.is(ItemTags.BEACON_PAYMENT_ITEMS);
+            }
+
+            @Override
+            public int getMaxStackSize() {
+                return 1;
+            }
+            // Paper start
+            @Override
+            public org.bukkit.Location getLocation() {
+                return context.getLocation();
+            }
+            // Paper end
+        };
         checkContainerDataCount(propertyDelegate, 3);
         this.beaconData = propertyDelegate;
         this.access = context;
         this.paymentSlot = new BeaconMenu.PaymentSlot(this.beacon, 0, 136, 110);
         this.addSlot(this.paymentSlot);
         this.addDataSlots(propertyDelegate);
-        int i = 36;
-        int j = 137;
+        boolean flag = true;
+        boolean flag1 = true;
 
-        for(int k = 0; k < 3; ++k) {
-            for(int l = 0; l < 9; ++l) {
-                this.addSlot(new Slot(inventory, l + k * 9 + 9, 36 + l * 18, 137 + k * 18));
+        int j;
+
+        for (j = 0; j < 3; ++j) {
+            for (int k = 0; k < 9; ++k) {
+                this.addSlot(new Slot(inventory, k + j * 9 + 9, 36 + k * 18, 137 + j * 18));
             }
         }
 
-        for(int m = 0; m < 9; ++m) {
-            this.addSlot(new Slot(inventory, m, 36 + m * 18, 195));
+        for (j = 0; j < 9; ++j) {
+            this.addSlot(new Slot(inventory, j, 36 + j * 18, 195));
         }
 
     }
@@ -67,9 +85,10 @@
     public void removed(Player player) {
         super.removed(player);
         if (!player.level().isClientSide) {
-            ItemStack itemStack = this.paymentSlot.remove(this.paymentSlot.getMaxStackSize());
-            if (!itemStack.isEmpty()) {
-                player.drop(itemStack, false);
+            ItemStack itemstack = this.paymentSlot.remove(this.paymentSlot.getMaxStackSize());
+
+            if (!itemstack.isEmpty()) {
+                player.drop(itemstack, false);
             }
 
         }
@@ -77,6 +96,7 @@
 
     @Override
     public boolean stillValid(Player player) {
+        if (!this.checkReachable) return true; // CraftBukkit
         return stillValid(this.access, player, Blocks.BEACON);
     }
 
@@ -88,47 +108,49 @@
 
     @Override
     public ItemStack quickMoveStack(Player player, int slot) {
-        ItemStack itemStack = ItemStack.EMPTY;
-        Slot slot2 = this.slots.get(slot);
-        if (slot2 != null && slot2.hasItem()) {
-            ItemStack itemStack2 = slot2.getItem();
-            itemStack = itemStack2.copy();
+        ItemStack itemstack = ItemStack.EMPTY;
+        Slot slot1 = (Slot) this.slots.get(slot);
+
+        if (slot1 != null && slot1.hasItem()) {
+            ItemStack itemstack1 = slot1.getItem();
+
+            itemstack = itemstack1.copy();
             if (slot == 0) {
-                if (!this.moveItemStackTo(itemStack2, 1, 37, true)) {
+                if (!this.moveItemStackTo(itemstack1, 1, 37, true)) {
                     return ItemStack.EMPTY;
                 }
 
-                slot2.onQuickCraft(itemStack2, itemStack);
-            } else if (!this.paymentSlot.hasItem() && this.paymentSlot.mayPlace(itemStack2) && itemStack2.getCount() == 1) {
-                if (!this.moveItemStackTo(itemStack2, 0, 1, false)) {
+                slot1.onQuickCraft(itemstack1, itemstack);
+            } else if (!this.paymentSlot.hasItem() && this.paymentSlot.mayPlace(itemstack1) && itemstack1.getCount() == 1) {
+                if (!this.moveItemStackTo(itemstack1, 0, 1, false)) {
                     return ItemStack.EMPTY;
                 }
             } else if (slot >= 1 && slot < 28) {
-                if (!this.moveItemStackTo(itemStack2, 28, 37, false)) {
+                if (!this.moveItemStackTo(itemstack1, 28, 37, false)) {
                     return ItemStack.EMPTY;
                 }
             } else if (slot >= 28 && slot < 37) {
-                if (!this.moveItemStackTo(itemStack2, 1, 28, false)) {
+                if (!this.moveItemStackTo(itemstack1, 1, 28, false)) {
                     return ItemStack.EMPTY;
                 }
-            } else if (!this.moveItemStackTo(itemStack2, 1, 37, false)) {
+            } else if (!this.moveItemStackTo(itemstack1, 1, 37, false)) {
                 return ItemStack.EMPTY;
             }
 
-            if (itemStack2.isEmpty()) {
-                slot2.setByPlayer(ItemStack.EMPTY);
+            if (itemstack1.isEmpty()) {
+                slot1.setByPlayer(ItemStack.EMPTY);
             } else {
-                slot2.setChanged();
+                slot1.setChanged();
             }
 
-            if (itemStack2.getCount() == itemStack.getCount()) {
+            if (itemstack1.getCount() == itemstack.getCount()) {
                 return ItemStack.EMPTY;
             }
 
-            slot2.onTake(player, itemStack2);
+            slot1.onTake(player, itemstack1);
         }
 
-        return itemStack;
+        return itemstack;
     }
 
     public int getLevels() {
@@ -141,25 +163,44 @@
 
     @Nullable
     public static MobEffect decodeEffect(int id) {
-        return id == 0 ? null : BuiltInRegistries.MOB_EFFECT.byId(id - 1);
+        return id == 0 ? null : (MobEffect) BuiltInRegistries.MOB_EFFECT.byId(id - 1);
     }
 
     @Nullable
     public MobEffect getPrimaryEffect() {
-        return decodeEffect(this.beaconData.get(1));
+        return BeaconMenu.decodeEffect(this.beaconData.get(1));
     }
 
     @Nullable
     public MobEffect getSecondaryEffect() {
-        return decodeEffect(this.beaconData.get(2));
+        return BeaconMenu.decodeEffect(this.beaconData.get(2));
+    }
+    // Paper start
+    private static @Nullable org.bukkit.potion.PotionEffectType convert(Optional<MobEffect> effect) {
+        return effect.flatMap(net.minecraft.core.registries.BuiltInRegistries.MOB_EFFECT::getResourceKey).map(key -> {
+            return org.bukkit.potion.PotionEffectType.getByKey(org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey.fromMinecraft(key.location()));
+        }).orElse(null);
     }
+    // Paper end
 
     public void updateEffects(Optional<MobEffect> primary, Optional<MobEffect> secondary) {
+        // Paper start - fix MC-174630 - validate secondary power
+        if (secondary.isPresent() && secondary.get() != net.minecraft.world.effect.MobEffects.REGENERATION && (primary.isPresent() && secondary.get() != primary.get())) {
+            secondary = Optional.empty();
+        }
+        // Paper end
         if (this.paymentSlot.hasItem()) {
-            this.beaconData.set(1, encodeEffect(primary.orElse((MobEffect)null)));
-            this.beaconData.set(2, encodeEffect(secondary.orElse((MobEffect)null)));
+            // Paper start
+            io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent event = new io.papermc.paper.event.player.PlayerChangeBeaconEffectEvent((org.bukkit.entity.Player) this.player.player.getBukkitEntity(), convert(primary), convert(secondary), this.access.getLocation().getBlock());
+            if (event.callEvent()) {
+                this.beaconData.set(1, BeaconMenu.encodeEffect(event.getPrimary() == null ? null : org.bukkit.craftbukkit.v1_20_R2.potion.CraftPotionEffectType.bukkitToMinecraft(event.getPrimary())));
+                this.beaconData.set(2, BeaconMenu.encodeEffect(event.getSecondary() == null ? null : org.bukkit.craftbukkit.v1_20_R2.potion.CraftPotionEffectType.bukkitToMinecraft(event.getSecondary())));
+                if (event.willConsumeItem()) {
+            // Paper end
             this.paymentSlot.remove(1);
+                }
             this.access.execute(Level::blockEntityChanged);
+            } // Paper end
         }
 
     }
@@ -168,7 +209,8 @@
         return !this.beacon.getItem(0).isEmpty();
     }
 
-    class PaymentSlot extends Slot {
+    private class PaymentSlot extends Slot {
+
         public PaymentSlot(Container inventory, int index, int x, int y) {
             super(inventory, index, x, y);
         }
@@ -183,4 +225,17 @@
             return 1;
         }
     }
+
+    // CraftBukkit start
+    @Override
+    public CraftInventoryView getBukkitView() {
+        if (this.bukkitEntity != null) {
+            return this.bukkitEntity;
+        }
+
+        org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryBeacon(this.beacon);
+        this.bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+        return this.bukkitEntity;
+    }
+    // CraftBukkit end
 }
