[Feedback] Testing 224 - Crop growth times

Generally speaking, anything block-based has 8 bits to play with for encoding extra state, eg chiselling blocks uses “all” of those bits to encode the different shape/orientiations of the shapes.

In some cases, we use extra block-ids where those bits aren’t sufficient, eg texture-rotation (because chiselling already uses all the 8 extra bits) uses 3 extra block-ids instead.

For crops, that means that as a base, we have 8 bits to play with.

3 bits are used for fertilizing. There are 3 types of fertilizer (including the “none” type for when not fertilized at a ll) (2 bits) and also a skill that makes fertilizing “better” (1 bit).

That leaves 5 bits for other things, which we use to store the stage of the crop growth for a maximum of 32 stages. Currently we only use up to 8 stages (so 3 bits), but @james is playing with having in-between stages of growth for more visual variance; and noting that more stages means less variance in the growth process (will “act” less randomnly).

Now, crops tick once per day, and say we have a crop which we want to be fully grown in 225 days (fuel crops have this expected growth time); how would you do that? either you need to store the day that the crop was planted so that you can evaulate “current day - day crop was planted” to know how longs its been… but storing that “day” would need a “lot” more than just 5 bits, it would need more like 5 bytes since servers can live for a long time; so it would make more sense to store “how old is the crop (in days)” which involves much smaller numbers, and then each game-day when the crop is ticked, it will just increment that value. For 225 days, that requires 8 bits… but we already used 3 of them for fertilizer. Also note that the (not yet released) prestige crops have an expected-growth time as it stands of 420 game-days + a wither expected time of 1260 game-days which would mean storing a counter up to 1680 needing 11 bits… but lets ignore that for now.

Now, we might be able to use block-ids to get those 8 bits, we need 3 more bits, which means using 8 block-ids instead of 1, but there’s another problem, which is that there are things like lighting/liquid/block conditions/fertilizer that can effect the growth rate, speeding it up or slowing it down, and if we wanted no RNG, then we actually need much more precision in that tick value than “1 day”… we would need something more like “1/32th of a day” meaning another 5 bits for extra precision, and now suddenly instead of an extra 8 block ids, we actually need 256 block-ids… and if we go back to the unreleaed prestige crop, we would need 2048 block-ids which I hope you can agree is a bit much… but there is “another” problem… which is that fertilizer also has a life time (currently 12 hours = 30 game-days) so need another 5bits, and now instead we need 8192 block ids, or 65536 block ids for the unreleased prestige crops… which is more than the entire range of the block-id datatype to begin with… aka this is just not feasible to “not” have rng with a block-data based system… so what else is there? Well we could make it an entity-based system so that there is an entire entity for every single crop… but then we would have to severely limit how many crops can be placed as it would be far too expensive to have huge fields of crops where every crop has entity data to be stored and maintained (and sent to clients! eek bandwidth…)

So instead, introduce RNG, and instead of storing “days since planted” we just store a much smaller value that can fit, which is the “growth stage”, and there is a probability of advancing to the next stage each day based on the desired average growth time, this is a poisson process which gives an accurate “expected” growth time for all the crops without worrying about precision, but as with any RNG is a law of large numbers and sometimes you get very good RNG rolls and the crop will mature “much faster” than its expected growth time (yay!) and sometimes much slower (boo!).

(There is also an entirely non-technical side to the RNG of crops… which is that it just looks better (visually; opinion) to see a field of crops grow somewhat stochastically instead of advancing exactly like a machine, and also gives a reason to be more pro-active in maintaining your crops, checking for those whose fertilizer has run out quicker than expected to fertilize again and get the best rng rolls on growth, or checking for those that have matured more quickly for an early harvest etc.)

17 Likes