Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-69151

Chickens with NoAI set to true still lay eggs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.8-pre1, Minecraft 1.8, Minecraft 1.8.3, Minecraft 1.8.5, 1.19, 1.19.2, 1.19.3, 1.20.1, 1.20.2, 1.20.4, 1.21
    • Confirmed
    • Mob behaviour
    • Low
    • Platform

      /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 Thumpbacker

      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;
            }
      
         }
      

            Unassigned Unassigned
            qmagnet qmagnet
            Votes:
            10 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              CHK: