mojira.dev
MC-225364

Chorus flowers can be destroyed by projectiles in adventure mode

The Bug:

Chorus flowers can be destroyed by projectiles in adventure mode.

Steps to Reproduce:

  1. Place down a chorus flower and obtain a bow and some arrows.

  2. Switch to adventure mode and shoot the arrow at the chorus flower.

  3. Take note as to whether or not chorus flowers can be destroyed by projectiles in adventure mode.

Observed Behavior:

Chorus flowers can be destroyed.

Expected Behavior:

Chorus flowers would not be able to be destroyed.

Code Analysis:

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

Linked issues

Attachments

Comments 10

Can confirm in 1.17.

Can confirm in 1.17.1.

Can also confirm in 21w37a. This ticket relates to MC-225365 and MC-223322. Here are some additional details regarding this issue.

The Bug:

Chorus flowers can be broken with projectiles in adventure mode.

Steps to Reproduce:

  • Place down a chorus flower and obtain a projectile.

  • Switch into adventure mode and shoot the projectile at the chorus flower.

  • → ❌  Notice how chorus flowers can be broken with projectiles in adventure mode.

Expected Behavior:

The expected behavior would be that chorus flowers cannot be broken with projectiles in adventure mode.

I can confirm this behavior in 1.18.1.

Here's a code analysis along with a potential fix regarding this issue.

Code Analysis:

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

net.minecraft.world.level.block.ChorusFlowerBlock.java

public class ChorusFlowerBlock extends Block {
   ...
   public void onProjectileHit(Level $l, BlockState $bs, BlockHitResult $bhr, Projectile $p) {
      BlockPos blockpos = $bhr.getBlockPos();
      if (!$l.isClientSide && $p.mayInteract($l, blockpos) && $p.getType().is(EntityTypeTags.IMPACT_PROJECTILES)) {
         $l.destroyBlock(blockpos, true, $p);
      }

   }
   ...

If we look at the above class, we can see that no checks are carried out to see what abilities the player possesses when using projectiles to destroy chorus flowers. The only checks that are in place are as follows:

  • Was the action non-client-side?

  • Can the chorus flower be interacted with? (Is the chorus flower outside of spawn protection and within the world border?)

  • Is the projectile a part of the IMPACT_PROJECTILES entity tag?

These checks are evident through the following line of code:

if (!$l.isClientSide && $p.mayInteract($l, blockpos) && $p.getType().is(EntityTypeTags.IMPACT_PROJECTILES))

Potential Fix:

Simply adding a line of code that checks what abilities the player possesses before a projectile can destroy a chorus flower, should resolve this problem. The following line of code could be used in order to fix this:

!$p.getAbilities().mayBuild

Can confirm in 1.18.2.

Can confirm in 1.19.

Can confirm in 1.19.1.

Can confirm in 1.19.3

Can confirm in 23w03a

BasInBest

gnembon

Confirmed

Gameplay

Normal

Player, Projectiles

chorus_flower

1.16.5, 21w19a, 1.17, 1.17.1, 21w37a, ..., 1.19.3, 23w03a, 1.19.4, 23w18a, 23w41a

23w42a

Retrieved