forked from minecraft-dotnet/Substrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
141 lines (120 loc) · 5.05 KB
/
Program.cs
File metadata and controls
141 lines (120 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using Substrate;
using Substrate.Nbt;
using Substrate.Core;
using System.IO;
// FlatMap is an example of generating worlds from scratch with Substrate.
// It will produce a completely flat, solid map with grass, dirt, stone,
// and bedrock layers. On a powerful workstation, creating 400 of these
// chunks only takes a few seconds.
namespace FlatMap
{
class Program
{
static void Main (string[] args)
{
if (args.Length < 2) {
Console.WriteLine("Usage: flatmap <type> <target_dir>");
Console.WriteLine("Available Types: alpha, beta, anvil");
return;
}
string dest = args[1];
int xmin = -20;
int xmax = 20;
int zmin = -20;
int zmaz = 20;
NbtVerifier.InvalidTagType += (e) =>
{
throw new Exception("Invalid Tag Type: " + e.TagName + " [" + e.Tag + "]");
};
NbtVerifier.InvalidTagValue += (e) =>
{
throw new Exception("Invalid Tag Value: " + e.TagName + " [" + e.Tag + "]");
};
NbtVerifier.MissingTag += (e) =>
{
throw new Exception("Missing Tag: " + e.TagName);
};
if (!Directory.Exists(dest))
Directory.CreateDirectory(dest);
// This will instantly create any necessary directory structure
NbtWorld world;
switch (args[0]) {
case "alpha": world = AlphaWorld.Create(dest); break;
case "beta": world = BetaWorld.Create(dest); break;
case "anvil": world = AnvilWorld.Create(dest); break;
default: throw new Exception("Invalid world type specified.");
}
IChunkManager cm = world.GetChunkManager();
// We can set different world parameters
world.Level.LevelName = "Flatlands";
world.Level.Spawn = new SpawnPoint(20, 70, 20);
// world.Level.SetDefaultPlayer();
// We'll let MC create the player for us, but you could use the above
// line to create the SSP player entry in level.dat.
// We'll create chunks at chunk coordinates xmin,zmin to xmax,zmax
for (int xi = xmin; xi < xmax; xi++) {
for (int zi = zmin; zi < zmaz; zi++) {
// This line will create a default empty chunk, and create a
// backing region file if necessary (which will immediately be
// written to disk)
ChunkRef chunk = cm.CreateChunk(xi, zi);
// This will suppress generating caves, ores, and all those
// other goodies.
chunk.IsTerrainPopulated = true;
// Auto light recalculation is horrifically bad for creating
// chunks from scratch, because we're placing thousands
// of blocks. Turn it off.
chunk.Blocks.AutoLight = false;
// Set the blocks
FlatChunk(chunk, 64);
// Reset and rebuild the lighting for the entire chunk at once
chunk.Blocks.RebuildHeightMap();
chunk.Blocks.RebuildBlockLight();
chunk.Blocks.RebuildSkyLight();
Console.WriteLine("Built Chunk {0},{1}", chunk.X, chunk.Z);
// Save the chunk to disk so it doesn't hang around in RAM
cm.Save();
}
}
// Save all remaining data (including a default level.dat)
// If we didn't save chunks earlier, they would be saved here
world.Save();
}
static void FlatChunk (ChunkRef chunk, int height)
{
// Create bedrock
for (int y = 0; y < 2; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
chunk.Blocks.SetID(x, y, z, (int)BlockType.BEDROCK);
}
}
}
// Create stone
for (int y = 2; y < height - 5; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
chunk.Blocks.SetID(x, y, z, (int)BlockType.STONE);
}
}
}
// Create dirt
for (int y = height - 5; y < height - 1; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
chunk.Blocks.SetID(x, y, z, (int)BlockType.DIRT);
}
}
}
// Create grass
for (int y = height - 1; y < height; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
chunk.Blocks.SetID(x, y, z, (int)BlockType.GRASS);
}
}
}
}
}
}