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

Mushroom Cows do not path to mycelium, but grass. Causes unintended spawning requirements

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Minecraft 16w38a
    • Minecraft 1.9.4
    • PC, Windows
    • Unconfirmed
    • Survival

      Mooshroom pathfinding favours grass rather than mycelium.

      Causes:

      Caused by harcoded use of GRASS block instead of instance attribute, spawnableBlock (MCP for 1.9.4):

      In entity/passive/EntityAnimal: #20 (EntityAnimal class):

          protected Block spawnableBlock = Blocks.GRASS;
      

      In entity/passive/EntityAnimal: #82 (EntityAnimal class):

          public float getBlockPathWeight(BlockPos pos)
          {
              return this.worldObj.getBlockState(pos.down()).getBlock() == Blocks.GRASS ? 10.0F : this.worldObj.getLightBrightness(pos) - 0.5F;
          }
      

      since MushroomCows redefine their spawnableBlock to mycelium:

      In entity/passive/EntityMooshroom: #23 (EntityMooshroom class):

          this.spawnableBlock = Blocks.MYCELIUM;
      

      this have no effect on their pathing behaviour as the perferred block is hardcoded to GRASS.

      Solution:

      Replace
      In entity/passive/EntityAnimal: #84 (EntityAnimal class):

       return this.worldObj.getBlockState(pos.down()).getBlock() == Blocks.GRASS ? 10.0F : this.worldObj.getLightBrightness(pos) - 0.5F;
      

      replace to:

      return this.worldObj.getBlockState(pos.down()).getBlock() == this.spawnableBlock ? 10.0F : this.worldObj.getLightBrightness(pos) - 0.5F;
      

      Sideeffects of the current state:

      Passive mobs are intended to spawn in light levels of 9 or above, as signified by this expression:

      In entity/passive/EntityAnimal: #122 (EntityAnimal class):

      return this.worldObj.getBlockState(blockpos.down()).getBlock() == this.spawnableBlock && this.worldObj.getLight(blockpos) > 8 && super.getCanSpawnHere();
      

      However since mooshrooms will path through grass, the following code takes an effect while spawning on mycelium:

      In entity/passive/EntityCreature: #40 (EntityCreature class):

              return super.getCanSpawnHere() && this.getBlockPathWeight(new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ)) >= 0.0F;
      

      and:
      In entity/passive/EntityAnimal: #82 (EntityAnimal class):

          public float getBlockPathWeight(BlockPos pos)
          {
              return this.worldObj.getBlockState(pos.down()).getBlock() == Blocks.GRASS ? 10.0F : this.worldObj.getLightBrightness(pos) - 0.5F;
          }
      

      So instead of light level > 8, what it needs is brightness > 0.5F, which is achieved with light level > 11, which stays in contrary to the statement in EntityAnimal#122

      Video with explanation:
      https://www.youtube.com/watch?v=sm43geXAgys

      Please and Thank you.

            FruBasilicum [Mojang] Agnes Larsson
            gnembon [Mojang] Gnembon
            Votes:
            12 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: