Private
Public Access
1
0

fix BeeSwarm bug where the wrong target beehive was chosen

This commit is contained in:
2026-05-24 08:05:33 +02:00
parent 7126ae4f88
commit 1776a26374
3 changed files with 24 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
{ {
"total": 642801, "total": 646950,
"sessions": [ "sessions": [
{ {
"begin": "2026-01-09T17:26:02+01:00", "begin": "2026-01-09T17:26:02+01:00",
@@ -1475,6 +1475,16 @@
"begin": "2026-05-24T06:50:13+02:00", "begin": "2026-05-24T06:50:13+02:00",
"end": "2026-05-24T06:50:54+02:00", "end": "2026-05-24T06:50:54+02:00",
"duration": 41 "duration": 41
},
{
"begin": "2026-05-24T06:51:03+02:00",
"end": "2026-05-24T06:53:00+02:00",
"duration": 116
},
{
"begin": "2026-05-24T06:53:21+02:00",
"end": "2026-05-24T08:00:35+02:00",
"duration": 4033
} }
] ]
} }

View File

@@ -295,19 +295,19 @@ public class BlockEntityBeeSwarm : BlockEntity
Disperse(); Disperse();
} }
private void StartMigrating(double nowHours, BlockPos targetPos, bool targetIsVanillaSkep, string? targetPopulatedSkepCode) private void StartMigrating(double nowHours, StructVec3i targetPos, bool targetIsVanillaSkep, string? targetPopulatedSkepCode)
{ {
StopCandidateRefresh(); StopCandidateRefresh();
SwarmState = SwarmState.MigratingToNewHive; SwarmState = SwarmState.MigratingToNewHive;
stateStartTotalHours = nowHours; stateStartTotalHours = nowHours;
migrationStartPopulation = Population; migrationStartPopulation = Population;
transferredDuringMigration = 0; transferredDuringMigration = 0;
this.targetPos = targetPos.Copy(); this.targetPos = targetPos.ToBlockPos();
this.targetIsVanillaSkep = targetIsVanillaSkep; this.targetIsVanillaSkep = targetIsVanillaSkep;
this.targetPopulatedSkepCode = targetPopulatedSkepCode; this.targetPopulatedSkepCode = targetPopulatedSkepCode;
retryDay = -1; retryDay = -1;
if (!targetIsVanillaSkep && Api.World.BlockAccessor.GetBlockEntity(targetPos) is BlockEntityReusableBeehive targetHive) if (!targetIsVanillaSkep && Api.World.BlockAccessor.GetBlockEntity(this.targetPos) is BlockEntityReusableBeehive targetHive)
targetHive.SetIncomingSwarm(Pos); targetHive.SetIncomingSwarm(Pos);
MarkDirty(false); MarkDirty(false);
@@ -382,7 +382,7 @@ public class BlockEntityBeeSwarm : BlockEntity
continue; continue;
var score = CalculateBeehiveTargetScore(hive, targetPos, radius); var score = CalculateBeehiveTargetScore(hive, targetPos, radius);
candidates.Add(new SwarmTargetCandidate(targetPos, false, score, null)); candidates.Add(new SwarmTargetCandidate(StructVec3i.FromBlockPos(targetPos), false, score, null));
} }
} }
@@ -403,7 +403,7 @@ public class BlockEntityBeeSwarm : BlockEntity
continue; continue;
var score = CalculateSkepTargetScore(targetPos, radius); var score = CalculateSkepTargetScore(targetPos, radius);
candidates.Add(new SwarmTargetCandidate(targetPos, true, score, entry.Value)); candidates.Add(new SwarmTargetCandidate(StructVec3i.FromBlockPos(targetPos), true, score, entry.Value));
} }
} }
@@ -411,13 +411,13 @@ public class BlockEntityBeeSwarm : BlockEntity
return candidates; return candidates;
} }
private bool TryConvertSkepToPopulated(BlockPos pos, string populatedCode) private bool TryConvertSkepToPopulated(StructVec3i pos, string populatedCode)
{ {
var block = Api.World.GetBlock(new AssetLocation(populatedCode)); var block = Api.World.GetBlock(new AssetLocation(populatedCode));
if (block == null || block.Id == 0) if (block == null || block.Id == 0)
return false; return false;
Api.World.BlockAccessor.ExchangeBlock(block.BlockId, pos); Api.World.BlockAccessor.ExchangeBlock(block.BlockId, pos.ToBlockPos());
return true; return true;
} }
@@ -612,6 +612,7 @@ public class BlockEntityBeeSwarm : BlockEntity
tree.SetBlockPos("targetPos", targetPos); tree.SetBlockPos("targetPos", targetPos);
} }
private readonly BlockPos _tempBlockPos = new(0, 0, 0);
private TreeArrayAttribute BuildCandidateHivesTreeArray() private TreeArrayAttribute BuildCandidateHivesTreeArray()
{ {
if (targetHiveCandidates == null) if (targetHiveCandidates == null)
@@ -622,7 +623,8 @@ public class BlockEntityBeeSwarm : BlockEntity
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
var entry = new TreeAttribute(); var entry = new TreeAttribute();
entry.SetBlockPos("pos", targetHiveCandidates[i].Pos); _tempBlockPos.Set(targetHiveCandidates[i].Pos.X, targetHiveCandidates[i].Pos.Y, targetHiveCandidates[i].Pos.Z);
entry.SetBlockPos("pos", _tempBlockPos); // safe, as internally does 3x SetInt
entries[i] = entry; entries[i] = entry;
} }
return new TreeArrayAttribute(entries); return new TreeArrayAttribute(entries);
@@ -659,5 +661,5 @@ public class BlockEntityBeeSwarm : BlockEntity
Api.GetOrekiWoofsBeehives()?.BroadcastUnloadDebug(message); Api.GetOrekiWoofsBeehives()?.BroadcastUnloadDebug(message);
} }
private readonly record struct SwarmTargetCandidate(BlockPos Pos, bool IsVanillaSkep, double Score, string? PopulatedSkepCode); private readonly record struct SwarmTargetCandidate(StructVec3i Pos, bool IsVanillaSkep, double Score, string? PopulatedSkepCode);
} }

View File

@@ -5,4 +5,6 @@ namespace OrekiWoofsBees.Common;
public readonly record struct StructVec3i(int X, int Y, int Z) public readonly record struct StructVec3i(int X, int Y, int Z)
{ {
public static StructVec3i FromBlockPos(BlockPos pos) => new(pos.X, pos.Y, pos.Z); public static StructVec3i FromBlockPos(BlockPos pos) => new(pos.X, pos.Y, pos.Z);
public BlockPos ToBlockPos() => new(X, Y, Z);
} }