public Structure(string name, Vector3I size, Vector3I root, string[] palette, int[] data) : base(name) { this.Size = size; this.Root = root; ushort[] paletteIDs = new ushort[palette.Length]; _Blocks = new ushort[data.Length]; //create palette ids for (int i = 0; i < palette.Length; i++) { paletteIDs[i] = ItemCache.GetIndex(palette[i]); } //create blocks for (int i = 0; i < data.Length; i++) { _Blocks[i] = paletteIDs[data[i]]; } _Cache.Add(this); }
public static ushort[] CreateTerrain(int chunkx, int chunky, bool save = false, bool erase = false) { ushort[] blocks = new ushort[Chunk.Width * Chunk.Height * Chunk.Depth]; string id; ushort cacheindex = 0; Dictionary <string, ushort> idscache = new Dictionary <string, ushort>(); for (int z = 0; z < Chunk.Depth; z++) { for (int y = 0; y < Chunk.Height; y++) { for (int x = 0; x < Chunk.Width; x++) { id = "winecrash:air"; const float scale = 0.025F; const float contScale = 0.001F; const float mountainScale = 0.005F; const float shiftX = 0; //Début des farlands : 16000000 | Grosses Farlands : 200000000 const float shiftZ = 0; //todo: auré tu fais chier avec tes commentaires. const float caveScale = 0.1F; const float thresold = 0.3F; float xsample = (chunkx * Chunk.Width + shiftX + x); float ysample = (chunky * Chunk.Depth + shiftZ + z); float continentValue = continents.GetValue(xsample * contScale, ysample * contScale); double continentalHeight = WMath.Remap(WMath.Clamp(Math.Exp(continentValue), 0.0, 65.0), -1.0D, 1.0D, 55.0D, 63.0D); float landValue = details.GetValue(xsample * scale, ysample * scale); double landHeight = WMath.Remap(landValue, -1.0D, 1.0D, 0.0D, 30.0D); float mountainValue = (float)WMath.Remap(mountainMult.GetValue(xsample * mountainScale, ysample * mountainScale), -1.0, 1.0, 0.0, 1.0); mountainValue = (float)WMath.Clamp(Math.Pow(mountainValue, 4.0), 0.0, 1.0); double final = continentalHeight + (landHeight * mountainValue); int height = (int)final; bool waterlevel = height < 64; if (y == height) { if (waterlevel) { id = "winecrash:sand"; //sand } else { id = "winecrash:grass"; //grass } } else if (y < height) { if (y > height - 3) { if (waterlevel) { id = "winecrash:sand"; //sand } else { id = "winecrash:dirt"; //dirt } } else { id = "winecrash:stone"; } } /*if(isCave) * { * id = "winecrash:air"; * }*/ if (y == 2) { if (World.WorldRandom.NextDouble() < 0.33D) { id = "winecrash:bedrock"; } } else if (y == 1) { if (World.WorldRandom.NextDouble() < 0.66D) { id = "winecrash:bedrock"; } } else if (y == 0) { id = "winecrash:bedrock"; } if (!idscache.TryGetValue(id, out cacheindex)) { cacheindex = ItemCache.GetIndex(id); idscache.Add(id, cacheindex); } //Server.Log(id); blocks[x + Chunk.Width * y + Chunk.Width * Chunk.Height * z] = cacheindex;//new Block(id); } } } if (save) { string fileName = "save/" + $"c{chunkx}_{chunky}.json"; if (erase) { File.WriteAllText(fileName, ToJSON(blocks)); } else if (!File.Exists(fileName)) { File.WriteAllText(fileName, ToJSON(blocks)); } } return(blocks); }
private static ushort[] LoadFromSave(string path) { JsonSerializer serializer = new JsonSerializer(); using (StreamReader sr = File.OpenText(path)) using (JsonTextReader jtr = new JsonTextReader(sr)) { JSONChunk dc = (JSONChunk)serializer.Deserialize(jtr, typeof(JSONChunk)); ushort[] blocks = new ushort[Chunk.Width * Chunk.Height * Chunk.Depth]; int chunkindex = 0; for (int z = 0; z < Chunk.Depth; z++) { for (int y = 0; y < Chunk.Height; y++) { for (int x = 0; x < Chunk.Width; x++) { blocks[x + Chunk.Width * y + Chunk.Width * Chunk.Height * z] = ItemCache.GetIndex(dc.Palette[dc.Data[chunkindex++]]); } } } return(blocks); } }