support for hot-changing radius
This commit is contained in:
22
.timetracker
22
.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
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user