From a88f5cf25b2f5b5f16db77b9455b79e5b124fac2 Mon Sep 17 00:00:00 2001 From: DocViviLeandra Date: Wed, 11 Mar 2026 11:50:04 -0500 Subject: [PATCH] Add virtual methods for retrieving CropProps and crop growth stages, increasing moddability --- Common/Collectible/Block/Block.cs | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Common/Collectible/Block/Block.cs b/Common/Collectible/Block/Block.cs index a600a371..ec1fd4c7 100644 --- a/Common/Collectible/Block/Block.cs +++ b/Common/Collectible/Block/Block.cs @@ -2168,6 +2168,45 @@ public BlockBehavior GetBehavior(Type type, bool withInheritance) return null; } + /// + /// Returns the CropProps for the Block. + /// + /// + public virtual BlockCropProperties GetCropProps() { + return CropProps; + } + + /// + /// Returns the CropProps for a specific in-world instance of the Block at a specific in-world position. Without overrides, this returns the same result as + /// + /// + /// The position of the block in-world. + /// + public virtual BlockCropProperties GetCropProps(IWorldAccessor world, BlockPos pos) { + return GetCropProps(); + } + + /// + /// Returns the Block's crop growth stage, if it is indeed a crop. + /// + /// 0, if it is not a crop or the stage cannot be determined. + public virtual int GetCurrentCropStage() { + if (GetCropProps() == null) return 0; + + int.TryParse(LastCodePart(), out int stage); + return stage; + } + + /// + /// Returns the crop growth stage for a specific in-world instance of the block at a specific in-world position. Without overrides, this returns the same result as + /// + /// + /// + /// + public virtual int GetCurrentCropStage(IWorldAccessor world, BlockPos pos) { + return GetCurrentCropStage(); + } + /// /// Called by the block info HUD for display the interaction help besides the crosshair