Resourceful Bees

Resourceful Bees

10M Downloads

Bees clump on a single flower

iarspider opened this issue ยท 13 comments

commented

** Describe the bug **
Bees no longer distribute over available flowers

** To Reproduce **
Steps to reproduce the behavior:

  • Place several bee of one type in an enclosure with more than 1 flower (that this bee likes)
  • Observe the bees clump on a single one

** Expected behavior **
Bees should spread over available flowers

** please complete the following information: **

Forge Version 1.16.5-36.1.0
Mod Version 0.6.2b

** Additional context **
Add any other context about the problem here.

screenshot

Worked properly at least in 0.5.10b

commented

it's a matter of balancing performance. all bees scan blocks in the same order around them so depending on where they are when they do it they will likely pick the same flower. we can't change the order blocks are scanned without significant performance impact. you can however use the honey dipper in the latest version to select a bee and designate a new flower location for it. also keep in mind that bees have a 10% chance to forget the flower position upon exiting the hive/apiary and as such may end up finding a different one later anyway

commented

I see. Thanks!

commented

also keep in mind our flower scanning logic is SIGNIFICANTLY more performant than vanillas own flower scanning logic. there's tradeoffs in performance vs function and right now this is about the best tradeoff possible.

commented

it's a matter of balancing performance. all bees scan blocks in the same order around them so depending on where they are when they do it they will likely pick the same flower. we can't change the order blocks are scanned without significant performance impact. you can however use the honey dipper in the latest version to select a bee and designate a new flower location for it. also keep in mind that bees have a 10% chance to forget the flower position upon exiting the hive/apiary and as such may end up finding a different one later anyway

May I ask why the decision that the bees have a 10% chance to forget was made? I was about to report it as a bug until I read this. This is also not mentioned anywhere. Having to constantly come back to the bees to set their flower is tedious. If not for the honey dipper all the bees will constantly clump up on the same flower and slow production by 99%.

commented

the 10% is a vanilla thing

commented

... Any chance you'll implement something so the bees are smarter and don't forget?

commented

in the next update in our hives bees wont forget their flower at all

commented

That sounds awesome! Wasn't sure what in the world I was going to do to keep the bees from being dumb. Looking forward to the update. Playing Enigmatica 6, btw. :)

commented

+1 for not forgetting, I'm having so many issues where bee's will clump together, then kill eachother for space! or just get stuck trying to get pollen and end up on the flower over night

commented

Which version of our mod did you test on? Because the code you're recommending a change to doesn't have the clumping issue and instead picks the flower position closest to the bee.

commented

So I am playing Enigmatica 6 latest version which appears to have version 0.6.5b. And looking at changelog of 0.6.7b I can see that's where the flower finding was changed to search closest to the player. And apparently I missed that the cached offsets are setup that way when I made my change to the version I tested (derp). So all good, I will just update to later version or update when the modpack does which should be soon.

commented

Just a comment on the performance note here.
I was having big issue with bees all getting stuck on one flower - I have about 60 bees in 5 enclosures the size of apiary, with 4 beehives in each, there are 24 flowers to choose from in each and all the bees would go for just one in the corner (with the exception of a few that require different kind of flower)

So I took a look at the code and decided to make a small change to findFlower method to randomize the positions where bees search for flowers each time they do it, diff of which you can see below.
And I have profiled it two times for more than an hour after which time the total time to run findFlower method was at 200ms in the first profiling session and didn't even appear in the second one (as I am guessing it was way below threshold for it to make it into the list).
So even though this change definitely has some performance "impact" I am pretty sure that it is so negligible that performance gained from all the results is far greater - findFlower method doesn't need to run so many times (as bees can actually get to the flower they want to and don't have to forget it only to find and try to go to the exact same flower again), code doesn't need to calculate all of the collisions of bees trying to get to the same flower and actually the bees most of the time don't exist in the world as they spend most of the time in beehives after they briefly went to their flower.
Also I am sure that the change can be changed to perform better but given how negligible running this code is I don't even feel like it's needed.

         BlockPos beePos = bee.blockPosition();
         if (!isEntity) {
             BlockPos.Mutable flowerPos = beePos.mutable();
-            for (BlockPos blockPos : positionOffsets){
+            ArrayList<BlockPos> randomizedOffsets = new ArrayList<>(positionOffsets);
+            Collections.shuffle(randomizedOffsets);
+            for (BlockPos blockPos : randomizedOffsets){
commented

We're actively looking into alternative pathfinding mechanisms which are performant while allowing a more diverse choice of flower, however shuffling the list would not be a viable option for this. we hope to have a better system coming soon.