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) { var code = block.FirstCodePart(); if (code == "flower") return true; if (code == "fruitingbush") { var blockEntity = accessor.GetBlockEntity(pos); if (blockEntity is null) return false; foreach (var behavior in blockEntity.Behaviors) { if (behavior.IsFruitingBushFlowering()) return true; } } if (block is BlockPlantContainer) { var plantContainer = block.GetBlockEntity(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)); }