fix BeeSwarm bug where the wrong target beehive was chosen
This commit is contained in:
12
.timetracker
12
.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
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user