Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-223324

You can place the upper halves of beds into spawn protection

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.16.5, 21w15a, 21w16a, 21w18a, 21w19a, 21w20a, 1.17.1, 1.18.1, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4, 1.20.1
    • Confirmed
    • Block states

      The Bug:

      You can place the upper halves of beds into spawn protection.

      Steps to Reproduce:

      1. Start a server, join it, give operator permissions to yourself, and switch into creative mode.
      2. Set the world spawn to your current location by using the command provided below.
        /setworldspawn ~ ~ ~
      3. Locate the edge of spawn protection and obtain a bed.
      4. Switch into survival mode, remove your operator permissions, and grant anyone else with them in order to activate spawn protection.
      5. Place the bed adjacent to, but not inside of spawn protection.
      6. Take note as to whether or not you can place the upper halves of beds into spawn protection.

      Observed Behavior:

      You can place the upper halves of beds into spawn protection.

      Expected Behavior:

      You would not be able to place the upper halves of beds into spawn protection.

      Code Analysis:

      Code analysis by Avoma can be found below.

      The following is based on a decompiled version of Minecraft 1.18.1 using MCP-Reborn.

      net.minecraft.world.level.block.BedBlock.java
      public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock {
         ...
         public BlockState getStateForPlacement(BlockPlaceContext $bpc) {
            Direction direction = $bpc.getHorizontalDirection();
            BlockPos blockpos = $bpc.getClickedPos();
            BlockPos blockpos1 = blockpos.relative(direction);
            Level level = $bpc.getLevel();
            return level.getBlockState(blockpos1).canBeReplaced($bpc) && level.getWorldBorder().isWithinBounds(blockpos1) ? this.defaultBlockState().setValue(FACING, direction) : null;
         }
         ...

      If we look at the above class, we can see that before a bed is placed, two checks are carried out. These two checks are as follows:

      • Is the block that the upper half of the bed will occupy a replaceable block?
      • Is the block that the upper half of the bed will occupy within the world border?

      Currently, no checks are carried out to see whether or not the block that the upper half of the bed will occupy is inside of spawn protection, and because of this, you can place the upper halves of beds into spawn protection.

        1. 2021-04-17_19.28.48.png
          2.23 MB
          user-39c63
        2. 2021-05-11_09.54.25.png
          790 kB
          [Mod] Avoma
        3. MC-223324.mp4
          5.90 MB
          [Mod] Avoma

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              CHK: