public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve) { base.FromTreeAttributes(tree, worldAccessForResolve); EnumFoliageState prevState = FoliageState; PartType = (EnumTreePartType)tree.GetInt("partType"); FoliageState = (EnumFoliageState)tree.GetInt("foliageState"); GrowthDir = BlockFacing.ALLFACES[tree.GetInt("growthDir")]; TreeType = tree.GetString("treeType"); Height = tree.GetInt("height"); fruitingSide = tree.GetInt("fruitingSide", fruitingSide); if (tree.HasAttribute("rootOffX")) { RootOff = new Vec3i(tree.GetInt("rootOffX"), tree.GetInt("rootOffY"), tree.GetInt("rootOffZ")); } if (Api != null && Api.Side == EnumAppSide.Client && prevState != FoliageState) { MarkDirty(true); } }
private bool TryGrowTo(EnumTreePartType partType, BlockFacing facing, int len = 1) { var pos = ownBe.Pos.AddCopy(facing, len); var block = stemBlock; if (partType == EnumTreePartType.Branch) { block = branchBlock; } if (partType == EnumTreePartType.Leaves) { block = leavesBlock; } var nblock = Api.World.BlockAccessor.GetBlock(pos); bool replaceable = (partType == EnumTreePartType.Leaves && nblock.IsReplacableBy(leavesBlock)) || (partType == EnumTreePartType.Branch && nblock == leavesBlock) || (partType == EnumTreePartType.Stem && nblock == branchBlock) ; if (!replaceable) { return(false); } var rootBe = Api.World.BlockAccessor.GetBlockEntity(ownBe.Pos.AddCopy(ownBe.RootOff)) as BlockEntityFruitTreeBranch; if (rootBe == null) { return(false); } var bh = rootBe.GetBehavior <FruitTreeRootBH>(); if (bh != null) { bh.BlocksGrown++; } Api.World.BlockAccessor.SetBlock(block.Id, pos); var beb = (Api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityFruitTreeBranch); var beh = beb?.GetBehavior <FruitTreeGrowingBranchBH>(); if (beh != null) { beh.VDrive = VDrive - (facing.IsVertical ? 1 : 0); beh.HDrive = HDrive - (facing.IsHorizontal ? 1 : 0); beb.ParentOff = facing.Normali.Clone(); beb.lastGrowthAttemptTotalDays = ownBe.lastGrowthAttemptTotalDays; } var be = Api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityFruitTreePart; if (be != null) { if (partType != EnumTreePartType.Stem) { be.FoliageState = EnumFoliageState.Plain; } be.GrowthDir = facing; be.TreeType = ownBe.TreeType; be.PartType = partType; be.RootOff = ownBe.RootOff.Clone().Add(facing.Opposite, len); be.Height = ownBe.Height + facing.Normali.Y; be.OnGrown(); } if (beh != null) { //beh.OnTick(0); } return(true); }