52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using Vintagestory.API.Common;
|
|
using Vintagestory.API.MathTools;
|
|
using Vintagestory.GameContent;
|
|
|
|
namespace OrekiWoofsBees.Common;
|
|
|
|
public static class PlantRecognitionUtilities
|
|
{
|
|
private static readonly BlockPos blockPos = new(0);
|
|
|
|
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 IsFlower(Block block, IBlockAccessor accessor, StructVec3i pos) => IsFlower(block, accessor, blockPos.Set(pos.X, pos.Y, pos.Z));
|
|
|
|
public static bool IsPlant(Block block, IBlockAccessor accessor, BlockPos pos)
|
|
{
|
|
return IsCrop(block) || IsFlower(block, accessor, pos);
|
|
}
|
|
|
|
public static bool IsPlant(Block block, IBlockAccessor accessor, StructVec3i pos) => IsPlant(block, accessor, blockPos.Set(pos.X, pos.Y, pos.Z));
|
|
}
|