reinit branch
This commit is contained in:
45
OrekiWoofsBees.Common/PlantRecognitionUtilities.cs
Normal file
45
OrekiWoofsBees.Common/PlantRecognitionUtilities.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user