Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7159

Crop Growth Modifier resolution is severely low.


    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • 1.19-R0.1-SNAPSHOT
    • Yes

      For years growth rate issues have plagued spiggot. 

      Where the modifiers seemingly did not effect the server if increased and required significant decrease to reduce. 

      Today I have discovered why. 

      Within "BlockCrops.randomTick",  there is an if statement as follows:

      if (randomsource.nextInt((int)(100.0F/ (float)modifier * (25.0F / f)) +  1 ==0)

      This is catastrophically wrong. 

      The vanilla probability of crop growth is 1/(25 / f +1)

      A modifier to this chance would be 100/Modifier[1/(25 / f +1)]{*}with 100 being normal growth.

      This is NOT what occurs in the if statement above. 

      (int)(100.0F/ (float)modifier * (25.0F / f)) is where the problem lies. 

      This value will always come out as an integer rounded down. I hope it is clear to see that, say for a case of modifier = 100 and f = 10

      that (int) 100.0F / (float)100 * (25.0F/10) < 1 and hence = 0. 

      Hence, most cases (until modifier is equal to or less than 40) the growth chance will always be based on:

      if (randomsource.nextInt(0 +  1 ==0)

      Hence a 50% chance as a random int between 0 and 1 are chosen. If 0 , then true. 

      This is a bug that, considering forum posts about the issue, has been persistent for years. 

      As such I will offer my personal recommendation at a fix below: 

      int chancevanilla = (int)(100/(floor(25.0F/f)+1))-1; //%chance in vanilla MC

      int ModMult = (int)(modifier/100.0F);

      int chancemod = (int)(chancevanilla*ModMult;

      if((randomsource.nextInt(99) <= chancemod) // rolls a random integer between 0 and 99 (100 numbers).// If chancevanilla or lower is rolled, then true. 

      I.e. if chance vanilla == 33 and then the modifier was 200, then chancemod would be 65 and hence have a 66% chance of success (66 choices lead to a true if statement out of the potential 100 ints between 0 and 99) 

            DerFrZocker Marvin Rieple
            Razielmartelus96 Jordan Stevens
            0 Vote for this issue
            2 Start watching this issue