Private
Public Access
1
0
Files
OrekiWoofsBeehives/OrekiWoofsBees.Common/PlantRecognitionUtilities.cs
2026-03-11 02:01:27 +01:00

46 lines
1.4 KiB
C#

using Vintagestory.API.Common;
using Vintagestory.API.MathTools;
using Vintagestory.GameContent;
namespace OrekiWoofsBees.Common;
public static class PlantRecognitionUtilities
{
public static bool IsCrop(Block block)
{
return block is BlockCrop;
}
public static bool IsFlower(Block block, IBlockAccessor accessor, BlockPos pos)
{
if (block.FirstCodePart() == "flower")
return true;
if (block is BlockPlantContainer)
{
var plantContainer = block.GetBlockEntity<BlockEntityPlantContainer?>(pos);
if (plantContainer is null)
return false;
var contents = plantContainer.GetContents();
if (contents is null)
return false;
if (contents.Block?.FirstCodePart() == "flower")
return true;
}
if (block is BlockBerryBush && accessor.GetBlockEntity(pos) is BlockEntityBerryBush blockEntityBerryBush)
return blockEntityBerryBush.IsFlowering;
if (block is BlockFruitTreePart && accessor.GetBlockEntity(pos) is BlockEntityFruitTreeFoliage fruitTreeFoliage)
return fruitTreeFoliage.FoliageState == EnumFoliageState.Flowering;
return false;
}
public static bool IsPlant(Block block, IBlockAccessor accessor, BlockPos pos)
{
return IsCrop(block) || IsFlower(block, accessor, pos);
}
}