public bool PostGenerateChunk(Chunk chunk, BlockSnapshot[,,] snapshots, World2dRegion region2d) { if (!_generations.TryRemove(chunk.Position, out var generation)) { return(true); } return(generation.OnChunkLoad(snapshots, chunk, region2d)); }
private BlockSnapshot UpdateSnapshot(BlockSnapshot snapshot, Vector3i position, World2dRegion region) { if (!(snapshot is IGrass grass)) { return(snapshot); } var pos2d = new Vector2i(position.X, position.Z); var relative = pos2d - (region.Position << World2dRegion.WorldPositionShift); grass.GrassColor = region.InterpolatedGrassColors[relative.X, relative.Y]; return(snapshot); }
public bool OnChunkLoad(BlockSnapshot[,,] snapshots, Chunk chunk, World2dRegion region2d) { var empty = true; var chunkPos = chunk.Position << Chunk.WorldPositionShift; Chunk.ForEachChunkPosition((x, y, z) => { var blockPos = chunkPos + new Vector3i(x, y, z); var data = _data[x, y, z]; if (data == null) { return; } chunk.Natural = false; chunk.Modified = true; if (data.OverrideBlocks) { if (!(data.Snapshot is BlockSnapshotAir)) { empty = false; } snapshots[x, z, y] = UpdateSnapshot(data.Snapshot, blockPos, region2d); return; } var snapshot = snapshots[x, z, y]; if (snapshot != null && !(snapshot is BlockSnapshotAir) && !(snapshot is BlockSnapshotTallGrass)) { return; } if (!(data.Snapshot is BlockSnapshotAir)) { empty = false; } snapshots[x, z, y] = UpdateSnapshot(data.Snapshot, blockPos, region2d); }); return(empty); }
public override void Load(Stream stream, BinaryFormatter formatter, uint version, World2dRegion region2d) { base.Load(stream, formatter, version, region2d); _visibleFaces = (byte)formatter.Deserialize(stream); _upside = (bool)formatter.Deserialize(stream); }