Skip to content

Commit

Permalink
Generate terrain around the city (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgosar authored Feb 19, 2023
1 parent b71b7bd commit 660ea4b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 26 deletions.
44 changes: 29 additions & 15 deletions MineCity2000-GUI/MineCity2000.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions MineCity2000-GUI/MineCity2000.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class MineCity2000 : Form
String inputFile = null;
String outputDir = null;
Boolean fillUnderground = false;
Boolean generateTerrain = false;
String buildingsDir = null;
SCMapper mapper = null;
private BackgroundWorker bw = new BackgroundWorker();
Expand Down Expand Up @@ -113,7 +114,7 @@ private void bw_DoWork(object sender, DoWorkEventArgs e)

mapper = new SCMapper(buildingsDir);
mapper.Worker = worker;
MapperOptions options = new MapperOptions(fillUnderground);
MapperOptions options = new MapperOptions(fillUnderground, generateTerrain);
mapper.makeMap(inputFile, outputDir, options);
}
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
Expand All @@ -139,9 +140,14 @@ private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
statusLabel.Text = (e.ProgressPercentage.ToString() + "%");
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
private void fillUndergroundCB_CheckedChanged(object sender, EventArgs e)
{
fillUnderground = ((CheckBox)sender).Checked;
}

private void generateTerrainCB_CheckedChanged(object sender, EventArgs e)
{
generateTerrain = ((CheckBox)sender).Checked;
}
}
}
4 changes: 3 additions & 1 deletion MineCity2000/MapperOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ namespace com.mc2k.MineCity2000
public class MapperOptions
{
public Boolean fillUnderground;
public Boolean generateTerrain;

public MapperOptions(Boolean fillUnderground) {
public MapperOptions(Boolean fillUnderground, Boolean generateTerrain) {
this.fillUnderground = fillUnderground;
this.generateTerrain = generateTerrain;
}
}
}
2 changes: 1 addition & 1 deletion MineCity2000/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static void Main(string[] args)
String buildingsDir = @"..\..\..\buildings";

SCMapper mapper = new SCMapper(buildingsDir);
MapperOptions options = new MapperOptions(true);
MapperOptions options = new MapperOptions(false, false);
mapper.makeMap(inputFile, outputDir, options);
}
}
Expand Down
11 changes: 7 additions & 4 deletions MineCity2000/SCMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ public void makeMap(String inputFile, String outputDir, MapperOptions options)
reportProgress();

double[] playerPosition = new double[] { 128.0, terrainHeights[128][128] + 20, 128.0 };
createLevelDat(outputDir, data.getCityName(), playerPosition);
createLevelDat(outputDir, data.getCityName(), playerPosition, options);

_progress = 16;
reportProgress();

//map
createCityRegions(outputDir, data, terrainHeights, options);

createBorderRegions(outputDir);
if (!options.generateTerrain)
{
createBorderRegions(outputDir);
}

_progress = 100;
reportProgress();
Expand Down Expand Up @@ -677,9 +680,9 @@ public static void prepareDir(String outputDir)
dir.CreateSubdirectory("region");
}

public static void createLevelDat(String outputDir, String cityName, double[] playerPos)
public static void createLevelDat(String outputDir, String cityName, double[] playerPos, MapperOptions options)
{
LevelDat ld = new LevelDat(cityName, playerPos);
LevelDat ld = new LevelDat(cityName, playerPos, options.generateTerrain);
ld.saveToFile(outputDir + "\\level.dat");
}

Expand Down
9 changes: 6 additions & 3 deletions MinecraftEditor/LevelDat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ namespace com.mc2k.MinecraftEditor
public class LevelDat
{
private String _levelName;
private String _generatorName;
private double[] _playerPos;

public LevelDat(String levelName, double[] playerPosition)
public LevelDat(String levelName, double[] playerPosition, Boolean generateTerrain)
{
_levelName = levelName;
_playerPos = playerPosition;
_generatorName = generateTerrain ? "default" : "flat";
}

public CompoundNBTTag toNBTTag()
{
TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
long timestamp = (long)t.TotalSeconds;
Random random = new Random();

List<AnyNBTTag> subTags = new List<AnyNBTTag>();

Expand All @@ -31,7 +34,7 @@ public CompoundNBTTag toNBTTag()
subTags.Add(new LongNBTTag("LastPlayed", timestamp * 1000));
subTags.Add(new PlayerData(_playerPos).toNBTTag());
subTags.Add(new ByteNBTTag("initialized", (byte)1));
subTags.Add(new LongNBTTag("RandomSeed", 0L));
subTags.Add(new LongNBTTag("RandomSeed", (long)random.Next()));
subTags.Add(new IntNBTTag("GameType", 1));
subTags.Add(new ByteNBTTag("MapFeatures", (byte)0));
subTags.Add(new IntNBTTag("version", 19133));
Expand All @@ -44,7 +47,7 @@ public CompoundNBTTag toNBTTag()
subTags.Add(new IntNBTTag("SpawnY", (int)_playerPos[1]));
subTags.Add(new IntNBTTag("SpawnZ", (int)_playerPos[2]));
subTags.Add(new StringNBTTag("LevelName",_levelName));
subTags.Add(new StringNBTTag("generatorName", "flat"));
subTags.Add(new StringNBTTag("generatorName",_generatorName));
subTags.Add(new LongNBTTag("SizeOnDisk", 0L));
subTags.Add(new IntNBTTag("rainTime", int.MaxValue));
subTags.Add(new IntNBTTag("generatorVersion", 0));
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ With the second browse button, choose your Minecraft install directory. It might

If you want the underground area to be filled instead of empty (So you don't fall into the ground after digging for a bit), select the "Fill underground area" checkbox. But be warned that this also increases the conversion time and RAM requirements.

If you want Minecraft to automatically generate its own terrain around the city instead of having an obsidian wall, select the "Generate terrain around the city" option.

After you choose both of these, click "Convert!". And when the processing is done, you can close this window, open Minecraft and you should see your city among the saved games.

Your antivirus might think that MineCity 2000 is a virus. It's not.
Expand Down
Binary file modified release/mc2k-release.rar
Binary file not shown.

0 comments on commit 660ea4b

Please sign in to comment.