66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using Vintagestory.API.Client;
|
|
using Vintagestory.API.MathTools;
|
|
|
|
namespace RoamingBees.Particles;
|
|
|
|
internal static class DebugPathRenderManager
|
|
{
|
|
private const int debug_paths_radius = 5;
|
|
private const int debug_paths_update_interval_ms = 100;
|
|
|
|
private static ICoreClientAPI? clientApi;
|
|
private static long? tickListenerId;
|
|
|
|
public static void SetEnabled(ICoreClientAPI? api, bool enabled)
|
|
{
|
|
if (clientApi != api)
|
|
{
|
|
DisableCurrent();
|
|
clientApi = api;
|
|
}
|
|
|
|
if (clientApi == null)
|
|
return;
|
|
|
|
if (enabled)
|
|
{
|
|
if (!tickListenerId.HasValue)
|
|
tickListenerId = clientApi.Event.RegisterGameTickListener(OnTick, debug_paths_update_interval_ms);
|
|
return;
|
|
}
|
|
|
|
DisableCurrent();
|
|
}
|
|
|
|
private static void DisableCurrent()
|
|
{
|
|
if (clientApi != null && tickListenerId.HasValue)
|
|
clientApi.Event.UnregisterGameTickListener(tickListenerId.Value);
|
|
tickListenerId = null;
|
|
}
|
|
|
|
private static void OnTick(float _)
|
|
{
|
|
if (clientApi?.World is not IClientWorldAccessor clientWorld)
|
|
return;
|
|
|
|
var playerEntity = clientWorld.Player?.Entity;
|
|
if (playerEntity == null)
|
|
return;
|
|
|
|
var playerPos = playerEntity.Pos.AsBlockPos;
|
|
var blockAccessor = clientWorld.BlockAccessor;
|
|
|
|
for (var dx = -debug_paths_radius; dx <= debug_paths_radius; dx++)
|
|
for (var dy = -debug_paths_radius; dy <= debug_paths_radius; dy++)
|
|
for (var dz = -debug_paths_radius; dz <= debug_paths_radius; dz++)
|
|
{
|
|
var blockPos = new BlockPos(playerPos.X + dx, playerPos.Y + dy, playerPos.Z + dz);
|
|
if (!BeePathGeneration.TryGetTargetBoxAtWorldBlock(blockAccessor, blockPos, out var box))
|
|
continue;
|
|
|
|
DebugPathBoxRenderer.Render(clientWorld, box);
|
|
}
|
|
}
|
|
}
|