public static BlockRow getAt(Vector2 pos) { if (pos.x != (int)pos.x || pos.y != (int)pos.y) { Logger.Error("Tried to load a chunk at an invalid position! (" + pos.ToString() + ")"); return(null); } if (Main.instance.world.persistentRows.ContainsKey(pos)) { return(Main.instance.world.persistentRows[pos]); } var chunk = Main.instance.getChunkAt(new Vector3(pos.x, 0f, pos.y), false); if (chunk != null && chunk.IsGenerated()) { var row2 = chunk.getRowAt((int)(pos.x - (chunk.position.x * 16)), (int)(pos.y - (chunk.position.y * 16))); return(row2); } var row = new BlockRow(); /* * var x = i - (Mathf.Floor(i / 16) * 16) + id.x * 16; * var z = Mathf.Floor(i / 16) + id.y * 16;*/ var y = 60 + (int)(Perlin.Noise(Main.instance.perlinX + pos.x * 0.1f, Main.instance.perlinY + pos.y * 0.1f) * 3); var stoneHeight = Mathf.FloorToInt(y * 0.85f); row.blocks.Add(new RowBlocks(0, stoneHeight - 1, Blocks.STONE)); row.blocks.Add(new RowBlocks(stoneHeight, y - 1, Blocks.DIRT)); row.blocks.Add(new RowBlocks(y, y, Blocks.GRASS)); //blocks of air... that's f*****g stupid. Just handle null references properly. //row.blocks.Add(new RowBlocks(y + 1, 256, Blocks.AIR)); return(row); }
//handles the generating of each row private int SpawnBlockRow(int numBlockRows, int tier) { GameObject newObject = Instantiate(_blockRowPrefab, new Vector3(0f, 3.75f - numBlockRows * 0.4f, 0), Quaternion.identity, this.transform); BlockRow blockRow = newObject.GetComponent <BlockRow>(); int rowPoints = blockRow.initBlockRow(tier); return(rowPoints); }
public BlockRow getRowAt(int x, int y) { if (x >= 16 || x < 0 || y < 0 || y >= 16) { return(BlockRow.getAt(new Vector2(position.x * 16 + x, position.y * 16 + y))); } int location = x + (y * 16); return(blocks[location]); }
void Generate() { for (var i = 0; i < blocks.Length; i++) { var x = i - (Mathf.Floor(i / 16) * 16) + position.x * 16; var z = Mathf.Floor(i / 16) + position.y * 16; //var y = 16 + (int)(Perlin.Noise(Main.instance.perlinX + x * 0.1f, Main.instance.perlinY + z * 0.1f) * 3); blocks[i] = BlockRow.getAt(new Vector2(x, z)); } doneGenerating = false; RegenerateModel(); doneGenerating = true; }
public static BlockRow getNaturalRowAt(int x, int y) { return(BlockRow.getAt(new Vector2(x, y))); }