Pollidisiac's feeding algorithm issue and fix
QuartzIsCheap opened this issue ยท 2 comments
Mod Loader
Fabric
Minecraft Version
1.18.2
Botania version
1.18.2-431-FABRIC
Modloader version
Fabric : Loader 0.13.3 + API 0.51.1
Modpack info
No response
The latest.log file
https://gist.github.com/QuartzIsCheap/9c497554891a65057d02666f596aada0
Issue description
The Pollidisiac uses an algorithm to distribute the food items around it to the animals around it.
It starts by fetching the animals and the ItemStacks in its vicinity. Then, for each animal, it will FIRST check if the animal is adult and already in love, THEN it will try to feed it each ItemStack.
- Suppose there are two cows and one ItemStack containing 2 wheat. The first cow will get one wheat out of the ItemStack, the second cow will get the remaining one.
- Suppose now that there are two ItemStacks containing one wheat each. The algorithm will go to the first cow, check if it's adult, check if it's not already in love, and then iterate over the ItemStacks. Since both ItemStacks are edible by the cow, and since the check
!animal.isInLove()
is outside the ItemStack loop, both wheat will be fed to the cow during this game tick.
Steps to reproduce
- Create a closed, 5x5 space
- Place a creative mana pool
- Place a Pollidisiac
- Put two cows in the space
- Place 2 Dispensers facing in the closed space, such that item shot out of them won't combine
- Put one wheat in each
- Power both Dispensers at the same time with a redstone wire
- Observe that only one cow is in love since only one got the two wheat
Other information
Fixing the issue is straightforward : it is enough to break
from the ItemStacks loop in the if (animal.isFood(stack))
branch, that is, between lines 59 and 60.