Пример #1
0
        protected bool getRootBhSetupListener()
        {
            if (RootOff == null || RootOff.IsZero)
            {
                rootBh = GetBehavior <FruitTreeRootBH>();
            }
            else
            {
                var be = Api.World.BlockAccessor.GetBlockEntity(Pos.AddCopy(RootOff)) as BlockEntityFruitTreeBranch;
                rootBh = be?.GetBehavior <FruitTreeRootBH>();
            }

            if (TreeType == null)
            {
                Api.World.Logger.Error("Coding error. Fruit tree without fruit tree type @" + Pos);
                return(false);
            }

            if (rootBh != null && rootBh.propsByType.TryGetValue(TreeType, out var val))
            {
                switch (val.State)
                {
                case EnumFruitTreeState.EnterDormancy: FoliageState = EnumFoliageState.Plain; break;

                case EnumFruitTreeState.Dormant: FoliageState = EnumFoliageState.DormantNoLeaves; break;

                case EnumFruitTreeState.Flowering: FoliageState = EnumFoliageState.Flowering; break;

                case EnumFruitTreeState.Fruiting: FoliageState = EnumFoliageState.Fruiting; break;

                case EnumFruitTreeState.Ripe: FoliageState = EnumFoliageState.Ripe; break;

                case EnumFruitTreeState.Empty: FoliageState = EnumFoliageState.Plain; break;

                case EnumFruitTreeState.Young: FoliageState = EnumFoliageState.Plain; break;

                case EnumFruitTreeState.Dead: FoliageState = EnumFoliageState.Dead; break;
                }

                if (Api.Side == EnumAppSide.Server)
                {
                    rootBh.propsByType[TreeType].OnFruitingStateChange += RootBh_OnFruitingStateChange;
                }
                listenerOk = true;
                return(true);
            }

            return(false);
        }
 void initCustomBehaviors(ItemStack parentPlantStack, bool callInitialize)
 {
     if (RootOff?.IsZero == true && GetBehavior <FruitTreeRootBH>() == null)
     {
         var bh = new FruitTreeRootBH(this, parentPlantStack);
         if (callInitialize)
         {
             bh.Initialize(Api, null);
         }
         Behaviors.Add(bh);
     }
     if (GrowTries < 60 && GetBehavior <FruitTreeGrowingBranchBH>() == null)
     {
         var bh = new FruitTreeGrowingBranchBH(this);
         if (callInitialize)
         {
             bh.Initialize(Api, null);
         }
         Behaviors.Add(bh);
     }
 }