mojira.dev
MC-69151

Chickens with NoAI set to true still lay eggs

/summon minecraft:chicken ~1 ~ ~1 {NoAI:1b,EggLayTime:1}

Considering the mob should have no AI, eggs really should not appear.

Code Analysis

Code analysis done by @unknown

Doing a check for the isNoAi() bool in the aiStep() method fixes this issue

Current Code

net/minecraft/world/entity/animal/Chicken.java

public void aiStep() {
      super.aiStep();
      this.oFlap = this.flap;
      this.oFlapSpeed = this.flapSpeed;
      this.flapSpeed += (this.onGround ? -1.0F : 4.0F) * 0.3F;
      this.flapSpeed = Mth.clamp(this.flapSpeed, 0.0F, 1.0F);
      if (!this.onGround && this.flapping < 1.0F) {
         this.flapping = 1.0F;
      }

      this.flapping *= 0.9F;
      Vec3 vec3 = this.getDeltaMovement();
      if (!this.onGround && vec3.y < 0.0D) {
         this.setDeltaMovement(vec3.multiply(1.0D, 0.6D, 1.0D));
      }

      this.flap += this.flapping * 2.0F;
      if (!this.level.isClientSide && this.isAlive() && !this.isBaby() && !this.isChickenJockey() && --this.eggTime <= 0) {
         this.playSound(SoundEvents.CHICKEN_EGG, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
         this.spawnAtLocation(Items.EGG);
         this.gameEvent(GameEvent.ENTITY_PLACE);
         this.eggTime = this.random.nextInt(6000) + 6000;
      }

   }

Fixed Code

net/minecraft/world/entity/animal/Chicken.java

public void aiStep() {
      super.aiStep();
      this.oFlap = this.flap;
      this.oFlapSpeed = this.flapSpeed;
      this.flapSpeed += (this.onGround ? -1.0F : 4.0F) * 0.3F;
      this.flapSpeed = Mth.clamp(this.flapSpeed, 0.0F, 1.0F);
      if (!this.onGround && this.flapping < 1.0F) {
         this.flapping = 1.0F;
      }

      this.flapping *= 0.9F;
      Vec3 vec3 = this.getDeltaMovement();
      if (!this.onGround && vec3.y < 0.0D) {
         this.setDeltaMovement(vec3.multiply(1.0D, 0.6D, 1.0D));
      }

      this.flap += this.flapping * 2.0F;
      //Adding a check if the isNoAi bool fixes MC-69151
      if (!this.level.isClientSide && this.isAlive() && !this.isBaby() && !this.isChickenJockey() && --this.eggTime <= 0 && !isNoAi()) {
         this.playSound(SoundEvents.CHICKEN_EGG, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
         this.spawnAtLocation(Items.EGG);
         this.gameEvent(GameEvent.ENTITY_PLACE);
         this.eggTime = this.random.nextInt(6000) + 6000;
      }

   }

Linked issues

Attachments

Comments 12

Qwert225

Bug confirmed for 1.8

Egor

Still happening in 1.8.3

Pepijn96

Confirmed for 1.8.5

Torabi

As @unknown has stated on several issues,

Any part of an entities behavior that is not implemented as part of the AI is not affected by the NoAI tag.

Pepijn96

That must be one of the most meaningless statements ever made. Anyway, where can we at least suggest this to be changed? It's pretty annoying that they still lay eggs.

2 more comments
Torabi

I didn't assume, I looked at the code. There are many aspects of entity behavior that logically should be handled by the AI that aren't, because they're remnants of old code. Hopefully that will change when entities are given an overhaul.

kumasasa

Hopefully that will change when entities are given an overhaul.

Will trigger a bug report: "Chickens with NoAI true no longer lay eggs"

Torabi
user-f2760

Fixing this would just limit options; the egg laying is already controlled/disable-able with the IsChickenJockey tag.

Avoma

I can confirm this behavior in 1.19.2. You can use the following command to easily reproduce this issue.

/summon minecraft:chicken ~1 ~ ~1 {NoAI:1b,EggLayTime:1}

qmagnet

(Unassigned)

Confirmed

Platform

Low

Mob behaviour

chicken

Minecraft 1.8-pre1, Minecraft 1.8, Minecraft 1.8.3, Minecraft 1.8.5, 1.19, ..., 1.20.2, 1.20.4, 1.21, 1.21.4, 25w02a

Retrieved