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

Village siege's spawn location is calculated incorrectly (fix included)

    XMLWordPrintable

    Details

    • Confirmation Status:
      Plausible
    • Game Mode:
      Creative

      Description

      (Slightly related to MC-7432; both bugs are in the same class.)

      The code that tries to find a location to bring the zombies "in" to the village creates a random location that is calculated slightly incorrectly. Currently, the zombies can be spawned anywhere in a square area around the village center (including in the center of the village), instead of the intended somewhere along circular perimeter area. (That is, if they could be spawned at all; MC-7432 prevents that currently).

      Bugged code
      With MCP and my own variable name interpretations:

      VillageSiege.func_75529_b()
      while (true) {
          if (tries < 10) {
              this.siegeSourceHorX = villageCenterChunk.posX + (int) ((double) (MathHelper.cos(this.worldObj.rand.nextFloat() * (float) Math.PI * 2.0F) * villageRadius) * 0.9D);
              this.siegeSourceVerZ = villageCenterChunk.posY;
              this.siegeSourceHorY = villageCenterChunk.posZ + (int) ((double) (MathHelper.sin(this.worldObj.rand.nextFloat() * (float) Math.PI * 2.0F) * villageRadius) * 0.9D);
      

      The code is obviously trying to roll a random angle, and calculate the location at that "compass angle" from the village center to the village perimeter. But for that result, the angle for both the trigonometric functions should be the same. In the above code, it rolls a new independent random number for each, and thus they can independently vary between -1 and 1, leaving the target area to be a slightly unevenly distributed square.

      Fix
      Tested to work, but not 100% tested to work correctly.

      VillageSiege.func_75529_b()
      while (true) {
          if (tries < 10) {
              float angle = this.worldObj.rand.nextFloat() * (float) Math.PI * 2.0F;
              this.siegeSourceHorX = villageCenterChunk.posX + (int) ((double) (MathHelper.cos(angle) * villageRadius) * 0.9D);
              this.siegeSourceVerZ = villageCenterChunk.posY;
              this.siegeSourceHorY = villageCenterChunk.posZ + (int) ((double) (MathHelper.sin(angle) * villageRadius) * 0.9D);
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                TheMoogle Mog (Ryan Holtz)
                Reporter:
                bugi74 Markku
              • Votes:
                20 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  CHK: