void TryToDelink(bool delinkSelf = true) { var surveyor = new BlockSurveyor(this.Control); foreach (var block in this.Fillers.Where((f) => !this.Delinked[f.Index])) { var material = surveyor.Look().At(block.Value).Block(); if (material == null || IsPlacement(material.Value)) { continue; } else if (material == this.Materials.Filler) { var filler = surveyor.Look().At(block.Value).For <Filler <Machine> >(); this.Delink(filler, block.Index); this.Replace(filler); } // block is long gone, while we are still in delinking process else { this.Delinked[block.Index] = true; } } if (delinkSelf && this.Fillers.All((f) => this.Delinked[f.Index])) { this.LinkState = LinkState.Delinked; this.Replace(this.Control); } }
void TryToLink() { var surveyor = new BlockSurveyor(this.Control); foreach (var block in this.Fillers.Where((f) => !this.Linked[f.Index])) { var material = surveyor.Look().At(block.Value).Block(); // not loaded or actual filler block is not created yet if (material == null || IsPlacement(material.Value)) { continue; } else if (material == this.Materials.Filler) { var filler = surveyor.Look().At(block.Value).For <Filler <Machine> >(); if (filler == null) { // game put material in place, but not entity yet. continue; } filler.Control = this.Control; filler.mSegment.RequestRegenerateGraphics(); this.Linked[block.Index] = true; } // block was destroyed before link process completed, so it could not call delink in OnDestroy method // we should do it ourselves else { this.StartDelinking(); this.TryToDelink(); return; } } if (this.Fillers.All((f) => this.Linked[f.Index])) { this.Control.mSegment.RequestRegenerateGraphics(); this.LinkState = LinkState.Linked; } }
public void Update(BlockSurveyor Surveyor) { var from = this.StartBlock + Direction.Up().Shift *this.LastCheckedPosition; var to = from + Direction.Up().Shift *CheckChunk; var clear = new GridBox(new Box(from, to)).Blocks() .Select(b => CubeHelper.IsCubeSolid(Surveyor.Look().At(b).Block()?.Type ?? 1)) .NoneTrue(); if (clear) { this.LastCheckedPosition = (this.LastCheckedPosition + CheckChunk) % ClearHeight; if (this.LastCheckedPosition == 0) { this.Clear = true; } } else { this.Clear = false; this.LastCheckedPosition = 0; } }