public static IBlock GetBlock(this IMap self, Point3L blockLocation) { throw new System.NotImplementedException("Does not currently work for negative numbers"); return self[blockLocation][(byte)(blockLocation.X % (long)Constants.CHUNK_SIZE_X), (byte)(blockLocation.Y % (long)Constants.CHUNK_SIZE_Y), (byte)(blockLocation.Z % (long)Constants.CHUNK_SIZE_Z)]; }
protected Point3L calcChunkLocation(Point3L blockLocation) { return new Point3L( blockLocation.X / Constants.CHUNK_SIZE_X * Constants.CHUNK_SIZE_X - (blockLocation.X < 0 ? Constants.CHUNK_SIZE_X : (byte)0), blockLocation.Y / Constants.CHUNK_SIZE_Y * Constants.CHUNK_SIZE_Y - (blockLocation.Y < 0 ? Constants.CHUNK_SIZE_Y : (byte)0), blockLocation.Z / Constants.CHUNK_SIZE_Z * Constants.CHUNK_SIZE_Z - (blockLocation.Z < 0 ? Constants.CHUNK_SIZE_Z : (byte)0) ); }
public IBlock GenerateBlock(Point3L location) { if (location.X * location.X + location.Y * location.Y + location.Z * location.Z < _radiusSquared) { return _block; } else { return null; } }
private IChunk createChunk(Point3L chunkLocation) { IChunk chunk = _kernel.Get<IChunk>(); for (byte x = 0; x < Constants.CHUNK_SIZE_X; x++) for (byte y = 0; y < Constants.CHUNK_SIZE_Y; y++) for (byte z = 0; z < Constants.CHUNK_SIZE_Z; z++) { chunk[x, y, z] = _generator.GenerateBlock(chunkLocation + new Point3L(x, y, z)); } chunk.Location = chunkLocation; return chunk; }
// IDictionary<Point3L,double> _dict = new Dictionary<Point3L,double>(); // private double _getNoise(Point3L location) { // //double val; // //if(!_dict.TryGetValue(location, out val)) { // val = ((_perlinNoise.GetValue(location.X, location.Z, 10) + 1.0) / 2.0); // _dict.Add(location,val); // } // return val; // } public IBlock GenerateBlock(Point3L location) { double value = ((_perlinNoise.GetValue(location.X, location.Z, 10) + 1.0) / 2.0); if (((double)(maxHeight - location.Y)) / (double)(maxHeight) > value) { if(value < .25) return _stoneBlock; else return _block; } else { return null; } }
public override IChunk this[Point3L blockLocation] { get { IChunk ret = base[blockLocation]; if (ret == null) { Point3L chunkLocation = calcChunkLocation(blockLocation); ret = createChunk(chunkLocation); this[chunkLocation] = ret; } return ret; } protected set { base[blockLocation] = value; } }
public virtual IChunk this[Point3L blockLocation] { get { IChunk chunk; Point3L chunkLocation = calcChunkLocation(blockLocation); if (!_chunks.TryGetValue(chunkLocation, out chunk)) return chunk; return null; } protected set { IChunk chunk; Point3L chunkLocation = calcChunkLocation(blockLocation); if (_chunks.TryGetValue(chunkLocation, out chunk)) { if (chunk == value) return; _chunks[chunkLocation] = value; } else _chunks.Add(chunkLocation, value); if (ChunkChanged != null) ChunkChanged(this, new ChangedEventArgs<IChunk>(chunk, value)); } }
public BlockChangedEventArgs(Point3L blockLocation, IBlock oldValue, IBlock newValue) { BlockLocation = blockLocation; OldValue = oldValue; NewValue = newValue; }