Private
Public Access
1
0

support for hot-changing radius

This commit is contained in:
2026-05-25 05:51:16 +02:00
parent b3b262b208
commit 0f1bcece53
5 changed files with 80 additions and 5 deletions

View File

@@ -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)