From 1776a263747609d3faed0d496a9d8a3f7fecd1b0 Mon Sep 17 00:00:00 2001 From: OrekiWoof Date: Sun, 24 May 2026 08:05:33 +0200 Subject: [PATCH] fix BeeSwarm bug where the wrong target beehive was chosen --- .timetracker | 12 ++++++++++- .../BlockEntities/BlockEntityBeeSwarm.cs | 20 ++++++++++--------- OrekiWoofsBees.Common/StructVec3i.cs | 2 ++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.timetracker b/.timetracker index 0406096..19e5b03 100644 --- a/.timetracker +++ b/.timetracker @@ -1,5 +1,5 @@ { - "total": 642801, + "total": 646950, "sessions": [ { "begin": "2026-01-09T17:26:02+01:00", @@ -1475,6 +1475,16 @@ "begin": "2026-05-24T06:50:13+02:00", "end": "2026-05-24T06:50:54+02:00", "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 } ] } \ No newline at end of file diff --git a/OrekiWoofsBeehives/BlockEntities/BlockEntityBeeSwarm.cs b/OrekiWoofsBeehives/BlockEntities/BlockEntityBeeSwarm.cs index 5d70247..a21e4c0 100644 --- a/OrekiWoofsBeehives/BlockEntities/BlockEntityBeeSwarm.cs +++ b/OrekiWoofsBeehives/BlockEntities/BlockEntityBeeSwarm.cs @@ -295,19 +295,19 @@ public class BlockEntityBeeSwarm : BlockEntity Disperse(); } - private void StartMigrating(double nowHours, BlockPos targetPos, bool targetIsVanillaSkep, string? targetPopulatedSkepCode) + private void StartMigrating(double nowHours, StructVec3i targetPos, bool targetIsVanillaSkep, string? targetPopulatedSkepCode) { StopCandidateRefresh(); SwarmState = SwarmState.MigratingToNewHive; stateStartTotalHours = nowHours; migrationStartPopulation = Population; transferredDuringMigration = 0; - this.targetPos = targetPos.Copy(); + this.targetPos = targetPos.ToBlockPos(); this.targetIsVanillaSkep = targetIsVanillaSkep; this.targetPopulatedSkepCode = targetPopulatedSkepCode; 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); MarkDirty(false); @@ -382,7 +382,7 @@ public class BlockEntityBeeSwarm : BlockEntity continue; 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; 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; } - private bool TryConvertSkepToPopulated(BlockPos pos, string populatedCode) + private bool TryConvertSkepToPopulated(StructVec3i pos, string populatedCode) { var block = Api.World.GetBlock(new AssetLocation(populatedCode)); if (block == null || block.Id == 0) return false; - Api.World.BlockAccessor.ExchangeBlock(block.BlockId, pos); + Api.World.BlockAccessor.ExchangeBlock(block.BlockId, pos.ToBlockPos()); return true; } @@ -612,6 +612,7 @@ public class BlockEntityBeeSwarm : BlockEntity tree.SetBlockPos("targetPos", targetPos); } + private readonly BlockPos _tempBlockPos = new(0, 0, 0); private TreeArrayAttribute BuildCandidateHivesTreeArray() { if (targetHiveCandidates == null) @@ -622,7 +623,8 @@ public class BlockEntityBeeSwarm : BlockEntity for (int i = 0; i < count; i++) { 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; } return new TreeArrayAttribute(entries); @@ -659,5 +661,5 @@ public class BlockEntityBeeSwarm : BlockEntity 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); } diff --git a/OrekiWoofsBees.Common/StructVec3i.cs b/OrekiWoofsBees.Common/StructVec3i.cs index 59d3737..1d7358a 100644 --- a/OrekiWoofsBees.Common/StructVec3i.cs +++ b/OrekiWoofsBees.Common/StructVec3i.cs @@ -5,4 +5,6 @@ namespace OrekiWoofsBees.Common; 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 BlockPos ToBlockPos() => new(X, Y, Z); }