public override bool TryAdvanceStage(IGrowableBlock block, byte currentStageIndex) { Logger.Log("{0} TryAdvanceStage", filename); Vector3Int pos = block.Position; if (currentStageIndex == 0 && pos.IsValid) { for (int i = 0; i < logs.Count; i++) { ushort currentType; if (World.TryGetTypeAt(pos + logs[i], out currentType)) { if (currentType == 0 || currentType == saplingIndex) { if (!ServerManager.TryChangeBlock(pos + logs[i], logIndex)) { return(false); // not loaded } } } else { return(false); // not loaded } } for (int i = 0; i < leaves.Count; i++) { ushort currentType; if (World.TryGetTypeAt(pos + leaves[i], out currentType)) { if (currentType == 0) { if (!ServerManager.TryChangeBlock(pos + leaves[i], leavesIndex)) { return(false); // not loaded } } } else { return(false); // not loaded } } } // succesfully grew, or invalid stage index. Either case, done. block.SetInvalid(); return(true); }
public override bool TryAdvanceStage(IGrowableBlock block, byte currentStageIndex) { if (currentStageIndex == 0) { Vector3Int pos = block.Position; for (int i = 0; i < logs.Count; i++) { ushort currentType; if (World.TryGetTypeAt(pos + logs[i], out currentType)) { if (currentType == 0 || currentType == BuiltinBlocks.CherrySapling) { if (!ServerManager.TryChangeBlock(pos + logs[i], BuiltinBlocks.LogTemperate)) { return(false); // not loaded } } } else { return(false); // not loaded } } for (int i = 0; i < leaves.Count; i++) { ushort currentType; if (World.TryGetTypeAt(pos + leaves[i], out currentType)) { if (currentType == 0) { if (!ServerManager.TryChangeBlock(pos + leaves[i], BuiltinBlocks.CherryBlossom)) { return(false); // not loaded } } } else { return(false); // not loaded } } } // succesfully grew, or invalid stage index. Either case, done. block.SetInvalid(); return(true); }
/// <summary> /// Called when a stage is grown. /// By default places the BlockType of the stage at the position /// </summary> public virtual bool TryAdvanceStage(IGrowableBlock block, byte currentStageIndex) { byte nextStageIndex = (byte)(currentStageIndex + 1); if (nextStageIndex < Stages.Count) { // more stages to go IGrowableStage nextStage = Stages[nextStageIndex]; ushort oldType; if (World.TryGetTypeAt(block.Position, out oldType)) { if (oldType == 0) { // no block... certainly not a valid stage block.SetInvalid(); return(true); } if (oldType != Stages[currentStageIndex].BlockTypeIndex) { // ?? current block type does not match current stage type. // Probably legacy imported blocks // Try to recover what stage to be for (int i = 0; i < Stages.Count; i++) { if (Stages[i].BlockTypeIndex == oldType) { block.CurrentStageIndex = (byte)i; return(false); } } block.SetInvalid(); return(true); } } else { return(false); } if (ServerManager.TryChangeBlock(block.Position, nextStage.BlockTypeIndex)) { if (nextStageIndex == Stages.Count - 1) { // reached last stage block.SetInvalid(); } else { block.CurrentStageIndex = nextStageIndex; block.Growth = Random.NextFloat(0f, RandomStartGrowthMax * Stages[nextStageIndex].GrowthTime); } return(true); } else { return(false); } } else { // at last stage already block.SetInvalid(); return(true); } }