diff --git a/.timetracker b/.timetracker index 02e1977..9a4b034 100644 --- a/.timetracker +++ b/.timetracker @@ -1,5 +1,5 @@ { - "total": 658541, + "total": 665981, "sessions": [ { "begin": "2026-01-09T17:26:02+01:00", @@ -1510,6 +1510,26 @@ "begin": "2026-05-24T10:45:43+02:00", "end": "2026-05-24T11:14:02+02:00", "duration": 1698 + }, + { + "begin": "2026-05-24T12:55:01+02:00", + "end": "2026-05-24T13:15:18+02:00", + "duration": 1217 + }, + { + "begin": "2026-05-24T13:16:44+02:00", + "end": "2026-05-24T13:38:36+02:00", + "duration": 1312 + }, + { + "begin": "2026-05-25T02:37:48+02:00", + "end": "2026-05-25T02:57:49+02:00", + "duration": 1201 + }, + { + "begin": "2026-05-25T04:46:47+02:00", + "end": "2026-05-25T05:48:38+02:00", + "duration": 3710 } ] } \ No newline at end of file diff --git a/OrekiWoofsBeehives/BlockEntities/BlockEntityReusableBeehive.cs b/OrekiWoofsBeehives/BlockEntities/BlockEntityReusableBeehive.cs index c43d032..0330211 100644 --- a/OrekiWoofsBeehives/BlockEntities/BlockEntityReusableBeehive.cs +++ b/OrekiWoofsBeehives/BlockEntities/BlockEntityReusableBeehive.cs @@ -32,6 +32,7 @@ public class BlockEntityReusableBeehive : BlockEntityContainer, IModEntity private bool isInGreenhouse; private BlockPos? activeSwarmPos; private BlockPos? incomingSwarmPos; + private int? registeredRadius; public override InventoryBase Inventory => inventory; public override string InventoryClassName => "beehive"; @@ -82,6 +83,7 @@ public class BlockEntityReusableBeehive : BlockEntityContainer, IModEntity } plantPositionRegistry.RegisterBeehive(Pos, Config.Instance.BeehiveRadius); + registeredRadius = Config.Instance.BeehiveRadius; var beehivesModSystem = Api.GetOrekiWoofsBeehives(); if (beehivesModSystem is null) @@ -152,10 +154,29 @@ public class BlockEntityReusableBeehive : BlockEntityContainer, IModEntity stopwatch.LogTime(this, 0.05, "after flowers and crops"); UpdateBeePopulationAndHoney(); stopwatch.LogTime(this, 0.05, "after population and honey"); + UpdateRadius(); stopwatch.StopAndLogTime(this, 0.05); } + private void UpdateRadius() + { + if (registeredRadius == Config.Instance.BeehiveRadius) + return; + + var plantPositionRegistry = Api.GetPlantPositionRegistry(); + try + { + plantPositionRegistry?.UpdateBeehiveRadius(Pos, Config.Instance.BeehiveRadius); + } + catch (Exception e) + { + Mod?.Logger.Warning("Couldn't update radius"); + Mod?.Logger.Warning(e); + } + registeredRadius = Config.Instance.BeehiveRadius; + } + private void ClearStaleIncomingSwarmReservation() { if (incomingSwarmPos == null) diff --git a/OrekiWoofsBees.Common/IPlantPositionRegistry.cs b/OrekiWoofsBees.Common/IPlantPositionRegistry.cs index 4f9621a..35fdd8f 100644 --- a/OrekiWoofsBees.Common/IPlantPositionRegistry.cs +++ b/OrekiWoofsBees.Common/IPlantPositionRegistry.cs @@ -28,6 +28,8 @@ public interface IPlantPositionRegistry void RegisterBeehive(BlockPos pos, int radius); + void UpdateBeehiveRadius(BlockPos pos, int radius); + void RemovePlantPosition(BlockPos pos, Block block); void UnregisterBeehive(BlockPos pos); diff --git a/OrekiWoofsBees.Common/PlantPositionRegistryModSystem2.cs b/OrekiWoofsBees.Common/PlantPositionRegistryModSystem2.cs index 76311b9..bb3fb2d 100644 --- a/OrekiWoofsBees.Common/PlantPositionRegistryModSystem2.cs +++ b/OrekiWoofsBees.Common/PlantPositionRegistryModSystem2.cs @@ -77,6 +77,15 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry beehives[key] = new BeehiveScanCursor(pos, radius); } + public void UpdateBeehiveRadius(BlockPos pos, int radius) + { + if (!offsetTables.ContainsKey(radius)) + offsetTables[radius] = new ScanOffsetTable(radius); + + var key = StructVec3i.FromBlockPos(pos); + beehives[key] = new BeehiveScanCursor(pos, radius); + } + public void UnregisterBeehive(BlockPos pos) { var key = StructVec3i.FromBlockPos(pos); diff --git a/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorRoamingBees.cs b/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorRoamingBees.cs index 11d0e89..5f9bbaa 100644 --- a/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorRoamingBees.cs +++ b/RoamingBees/RoamingBees/Behaviors/BlockEntityBehaviorRoamingBees.cs @@ -39,6 +39,7 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti private ClimateCondition? climate; private Vec3d? windVec; + private int? registeredRadius; private int onParticleTickStopwatchTriggerCount; private int spawnStopwatchTriggerCount; private readonly Stopwatch plantInfoStopwatch = new(); @@ -87,6 +88,7 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti plantPositionRegistry = api.GetPlantPositionRegistry(); var radius = GetRadiusFromBlockEntity(); plantPositionRegistry?.RegisterBeehive(Blockentity.Pos, radius); + registeredRadius = radius; var updateFrequency = 20; Blockentity.RegisterGameTickListener(OnParticleTick, updateFrequency); @@ -116,13 +118,13 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti climate = Api.World.BlockAccessor.GetClimateAt(Blockentity.Pos, EnumGetClimateMode.NowValues); } + private readonly TreeAttribute _tempTreeAttribute = new(); private int GetRadiusFromBlockEntity() { var radius = properties[RADIUS_ATTRIBUTE].AsInt(10); - - var tree = new TreeAttribute(); - Blockentity.ToTreeAttributes(tree); - radius = tree.GetAsInt(RADIUS_ATTRIBUTE, radius); + _tempTreeAttribute.Clear(); + Blockentity.ToTreeAttributes(_tempTreeAttribute); + radius = _tempTreeAttribute.GetAsInt(RADIUS_ATTRIBUTE, radius); return radius; } @@ -230,10 +232,31 @@ public class BlockEntityBehaviorRoamingBees(BlockEntity blockEntity) : BlockEnti plantInfoStopwatch.Restart(); UpdatePlantInfo(); + UpdateRadius(); + var note = $"global bees: {modSystem?.GlobalActiveBees}, registered hives: {modSystem?.BeeSpawnPacketDistributor?.SpawnHandlersCount}, radius: {Config.Instance.BeeRoamingRadius}"; plantInfoStopwatch.StopAndLogTime(this, 0.1, note); } + private void UpdateRadius() + { + var radius = GetRadiusFromBlockEntity(); + if (registeredRadius == radius) + return; + + var plantPositionRegistry = Api.GetPlantPositionRegistry(); + try + { + plantPositionRegistry?.UpdateBeehiveRadius(Pos, radius); + } + catch (Exception e) + { + Mod?.Logger.Warning("Couldn't update radius"); + Mod?.Logger.Warning(e); + } + registeredRadius = radius; + } + private bool ShouldTick() { if (Block is BlockSkep && !Config.Instance.EnableOnVanillaSkeps)