public override void OnLoaded(ICoreAPI api)
        {
            base.OnLoaded(api);

            capi = api as ICoreClientAPI;

            branchBlock  = api.World.GetBlock(CodeWithVariant("type", "branch"));
            foliageBlock = api.World.GetBlock(AssetLocation.Create(Attributes["foliageBlock"].AsString(), Code.Domain)) as BlockFruitTreeFoliage;

            TypeProps = Attributes["fruittreeProperties"].AsObject <Dictionary <string, FruitTreeTypeProperties> >();
            var shapeFiles = Attributes["shapes"].AsObject <Dictionary <string, CompositeShape> >();

            WorldGenConds = Attributes["worldgen"].AsObject <FruitTreeWorldGenConds[]>();

            foreach (var val in shapeFiles)
            {
                IAsset asset = api.Assets.TryGet(val.Value.Base.WithPathAppendixOnce(".json").WithPathPrefixOnce("shapes/"), true);
                Shapes[val.Key] = new FruitTreeShape()
                {
                    Shape = asset?.ToObject <Shape>(), CShape = val.Value
                };
            }

            foreach (var prop in TypeProps)
            {
                foreach (var bdstack in prop.Value.FruitStacks)
                {
                    bdstack.Resolve(api.World, "fruit tree FruitStacks");
                }

                (api as ICoreServerAPI)?.RegisterTreeGenerator(new AssetLocation("fruittree-" + prop.Key), (blockAccessor, pos, skipForestFloor, s, v, o, t) => GrowTree(blockAccessor, pos, prop.Key));
            }
        }
Exemple #2
0
        public override void Initialize(ICoreAPI api, JsonObject properties)
        {
            base.Initialize(api, properties);

            if (Api.Side == EnumAppSide.Server)
            {
                listenerId = Blockentity.RegisterGameTickListener(OnTick, callbackTimeMs + Api.World.Rand.Next(callbackTimeMs));
            }

            stemBlock   = Api.World.GetBlock(ownBe.Block.CodeWithVariant("type", "stem"));
            branchBlock = Api.World.GetBlock(ownBe.Block.CodeWithVariant("type", "branch")) as BlockFruitTreeBranch;
            leavesBlock = Api.World.GetBlock(AssetLocation.Create(ownBe.Block.Attributes["foliageBlock"].AsString(), ownBe.Block.Code.Domain)) as BlockFruitTreeFoliage;

            if (ownBe.Block == leavesBlock)
            {
                ownBe.PartType = EnumTreePartType.Leaves;
            }
            if (ownBe.Block == branchBlock)
            {
                ownBe.PartType = EnumTreePartType.Branch;
            }

            if (ownBe.lastGrowthAttemptTotalDays == 0)
            {
                ownBe.lastGrowthAttemptTotalDays = api.World.Calendar.TotalDays;
            }
        }