try to further decrease allocations
This commit is contained in:
@@ -15,6 +15,8 @@ namespace OrekiWoofsBees.Common;
|
||||
/// </summary>
|
||||
public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
||||
{
|
||||
private readonly static BlockPos staticBlockPos = new(0);
|
||||
|
||||
private const int default_blocks_per_tick = 20;
|
||||
private const int tick_interval_ms = 20;
|
||||
|
||||
@@ -231,21 +233,20 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
||||
|
||||
cursor.Advance();
|
||||
|
||||
var block = accessor.GetBlock(blockPos);
|
||||
var structPos = new StructVec3i(blockPos.X, blockPos.Y, blockPos.Z);
|
||||
var block = accessor.GetBlock(staticBlockPos.Set(blockPos.X, blockPos.Y, blockPos.Z));
|
||||
|
||||
if (block == null || block.BlockId == 0)
|
||||
{
|
||||
// block is air or unloaded - remove from caches if present
|
||||
flowerPositions.Remove(structPos);
|
||||
cropPositions.Remove(structPos);
|
||||
flowerPositions.Remove(blockPos);
|
||||
cropPositions.Remove(blockPos);
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if this is soil with soil below - mark as soil floor
|
||||
if (block is BlockSoil)
|
||||
{
|
||||
var blockBelow = accessor.GetBlock(blockPos.DownCopy());
|
||||
var blockBelow = accessor.GetBlockRaw(blockPos.X, blockPos.Y - 1, blockPos.Z);
|
||||
if (blockBelow is BlockSoil)
|
||||
{
|
||||
// found soil floor - record it
|
||||
@@ -263,18 +264,18 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
||||
|
||||
if (PlantRecognitionUtilities.IsCrop(block))
|
||||
{
|
||||
cropPositions.Add(structPos);
|
||||
flowerPositions.Remove(structPos);
|
||||
cropPositions.Add(blockPos);
|
||||
flowerPositions.Remove(blockPos);
|
||||
}
|
||||
else if (PlantRecognitionUtilities.IsFlower(block, accessor, blockPos))
|
||||
{
|
||||
flowerPositions.Add(structPos);
|
||||
cropPositions.Remove(structPos);
|
||||
flowerPositions.Add(blockPos);
|
||||
cropPositions.Remove(blockPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
flowerPositions.Remove(structPos);
|
||||
cropPositions.Remove(structPos);
|
||||
flowerPositions.Remove(blockPos);
|
||||
cropPositions.Remove(blockPos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +291,7 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
||||
/// 2. pick the closest horizontal space vertically
|
||||
/// 3. check the next closest block to the beehive in this horizontal space
|
||||
/// </summary>
|
||||
private (BeehiveScanCursor Cursor, BlockPos BlockPos)? GetNextBlockToCheck()
|
||||
private (BeehiveScanCursor Cursor, StructVec3i BlockPos)? GetNextBlockToCheck()
|
||||
{
|
||||
if (beehives.Count == 0)
|
||||
return null;
|
||||
@@ -327,9 +328,9 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
||||
}
|
||||
else
|
||||
{
|
||||
var beehivesList = beehives.Values.ToList();
|
||||
var beehivesList = beehives.Values;
|
||||
lastScannedBeehiveIndex = (lastScannedBeehiveIndex + 1) % beehivesList.Count;
|
||||
bestCursor = beehivesList[lastScannedBeehiveIndex];
|
||||
bestCursor = beehivesList.ElementAt(lastScannedBeehiveIndex);
|
||||
}
|
||||
|
||||
if (bestCursor == null)
|
||||
@@ -350,15 +351,14 @@ public class PlantPositionRegistryModSystem2 : ModSystem, IPlantPositionRegistry
|
||||
|
||||
private int currentIndex = 0;
|
||||
|
||||
public BlockPos GetCurrentBlockPos(Dictionary<int, ScanOffsetTable> tables)
|
||||
public StructVec3i GetCurrentBlockPos(Dictionary<int, ScanOffsetTable> tables)
|
||||
{
|
||||
var table = tables[Radius];
|
||||
var (X, Y, Z) = table.GetOffset(currentIndex);
|
||||
return new BlockPos(
|
||||
return new(
|
||||
HivePos.X + X,
|
||||
HivePos.Y + Y,
|
||||
HivePos.Z + Z,
|
||||
HivePos.dimension
|
||||
HivePos.Z + Z
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user