mojira.dev
MC-238098

Occupied bed blows up when kicking a villager out of the bed in the Nether/End

The Bug:

If you try to kick a villager out of a bed in the nether / end, the bed blows up.

Steps to Reproduce:

  • Go to the nether or end

  • Set the time to night

  • Place down a bed and spawn a villager

  • Try to kick the villager out of the bed

Observed Behavior:

The bed will explode.

Expected Behavior:

The villager is kicked out first, and if you click on the bed a second time, when it is unoccupied, it will explode.

Code Analysis:

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 8

Using a bed, even if therevs a villager in it in general kicks the villager out and makes you enter; which is by design.
That villagers can sleep in them is MC-146515.

@Dhranios Doesn't work in Overworld. We can't kick villager out of bed by using their bed. Only way to destroy the bed with hands.

In that case the wiki has incorrect information ("The villager is kicked out of its bed when a player attempts to sleep there."), my apologies.

I found this post a little unclear, so just to clarify:

The Bug:

If you try to kick a villager out of a bed in the nether / end, the bed blows up.

Steps to Reproduce:

  • Go to the nether or end

  • Set the time to night

  • Place down a bed and spawn a villager

  • Try to kick the villager out of the bed

Observed Behavior:

The bed will explode.

Expected Behavior:

The villager is kicked out, and if you click on the bed a second time, when it unoccupied, it will explode.

Can confirm in 1.18.1.

I can confirm this behavior in 1.18.2 and 1.19 Pre-release 4. Here's a code analysis regarding this issue.

Code Analysis:

The following is based on a decompiled version of Minecraft 1.19 Pre-release 4 using Mojang mappings.

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

public class BedBlock extends HorizontalDirectionalBlock implements EntityBlock {
   ...
   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 through player interaction. This check is if the bed can set the player's spawn point. The canSetSpawn() boolean returns false if the given bed is in a dimension other than the overworld, so if the player was to attempt to set their spawn here, the bed would explode. Since no checks are carried out to see if the bed is currently occupied by a villager, this results in the issue occurring.

Yes, the check for occupancy is right after the above code. If they were reordered it would fix this.

Thank you for your report!
We're tracking this issue in MC-145964, so this ticket is being resolved and linked as a duplicate.

That ticket has already been resolved as working as intended, which means this is not considered a bug and won't be fixed. Please do not leave a comment on the linked ticket.

If you haven't already, you might like to make use of the search feature to see if the issue has already been mentioned.

Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki

cartoonstalgia

(Unassigned)

Confirmed

Block states, Player

1.17.1, 21w39a, 1.18.1, 1.18.2, 1.19 Pre-release 4, 1.19.2, 1.19.4, 23w14a, 1.20.4, 24w04a

Retrieved