mojira.dev
MC-251525

Sculk sensors are not activated upon rabbits eating planted carrots

The bug

Sculk sensors do not detect rabbits eating planted carrots. This is unexpected, as this is a block change and as such should be considered a vibration and be detected by sculk sensors.

To reproduce

  1. /fill ~ ~ ~ ~10 ~ ~10 minecraft:farmland[moisture=7]

  2. /fill ~ ~1 ~ ~10 ~1 ~10 minecraft:carrots[age=7]

  3. Place a sculk sensor nearby.

  4. /summon rabbit ~ ~ ~

  5. Wait for the rabbit to eat the carrots.

Expected result

The sculk sensor would pick up the vibration.

Code analysis

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

Attachments

Comments 8

I can confirm this behavior. Here's a code analysis regarding this issue.

Code Analysis:

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

net.minecraft.world.entity.Rabbit.java

public class Rabbit extends Animal {
   ...
   static class RaidGardenGoal extends MoveToBlockGoal {
      ...
      public void tick() {
         ...
         if (this.isReachedTarget()) {
            Level level = this.rabbit.level;
            BlockPos blockpos = this.blockPos.above();
            BlockState blockstate = level.getBlockState(blockpos);
            Block block = blockstate.getBlock();
            if (this.canRaid && block instanceof CarrotBlock) {
               int i = blockstate.getValue(CarrotBlock.AGE);
               if (i == 0) {
                  level.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 2);
                  level.destroyBlock(blockpos, true, this.rabbit);
               } else {
                  level.setBlock(blockpos, blockstate.setValue(CarrotBlock.AGE, Integer.valueOf(i - 1)), 2);
                  level.levelEvent(2001, blockpos, Block.getId(blockstate));
               }

               this.rabbit.moreCarrotTicks = 40;
            }
            ...

If we look at the above class, we can see that rabbits eating carrots as a result of raiding gardens simply isn't registered as a game event as the gameEvent() method is never called, thus not detecting this action as a vibration.

Potential Fix:

Simply calling the gameEvent() method where appropriate within this piece of code should resolve this problem. The "BLOCK_CHANGE" or "EAT" game event tag would be expected to be used here.

Can confirm in 1.19.1.

Can confirm in 1.19.2. Just for clarification reasons, sculk sensors are activated upon the player feeding carrots to rabbits directly but are not activated when rabbits eat carrots from raiding gardens. It would probably be worth mentioning this somewhere within the report to clear up any potential confusion.

Can confirm in 23w17a

Can confirm in 23w18a

Can confirm in 1.20 Pre-release 4

Can confirm in 1.20.1

ampolive

kingbdogz

Confirmed

Low

Game Events

sculk_sensor

1.18.2, 22w18a, 1.19 Pre-release 1, 1.19 Pre-release 2, 1.19 Pre-release 3, , 23w18a, 1.20 Pre-release 4, 1.20 Release Candidate 1, 1.20, 1.20.1

23w32a

Retrieved