Пример #1
0
 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));
 }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
 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);
 }