mojira.dev
MC-255074

Bed still explodes in the nether and the end, if there are monsters nearby

If I right click a bed in the nether and the end it still explodes if there are monsters nearby. It should say You may not rest now there are monsters nearby.

Code Analysis by @unknown found here

Attachments

Comments 1

I can confirm this behavior, though after looking through the code, I'm inclined to believe that this is working as intended, however, that isn't my call to make.

Code Analysis:

The following is based on a decompiled version of Minecraft 1.19.2 using Mojang mappings.

net.minecraft.world.level.block.BedBlock.java

public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock {
   ...
   @Override
   public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
      ...
      if (!BedBlock.canSetSpawn(level)) {
         level.removeBlock(blockPos, false);
         BlockPos blockPos2 = blockPos.relative(blockState.getValue(FACING).getOpposite());
         if (level.getBlockState(blockPos2).is(this)) {
            level.removeBlock(blockPos2, false);
         }
         level.explode(null, DamageSource.badRespawnPointExplosion(), null, (double)blockPos.getX() + 0.5, (double)blockPos.getY() + 0.5, (double)blockPos.getZ() + 0.5, 5.0f, true, Explosion.BlockInteraction.DESTROY);
         return InteractionResult.SUCCESS;
      }
      ...

If we look at the above class, we can see that only one check is carried out before a bed is able to explode upon it being interacted with. This check is to see if the bed is able to set the player's spawnpoint. Since the canSetSpawn boolean returns false when the bed is placed in dimensions other than the overworld, the bed is simply then designed to explode when the player attempts to sleep in it, regardless of surrounding nearby monsters.

Wryboyon

(Unassigned)

Community Consensus

Player

1.19.2

Retrieved