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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
#include "stdafx.h"
#include "StringHelpers.h"
#include "net.minecraft.world.level.levelgen.flat.h"
#include "net.minecraft.world.level.tile.h"
#include "FlatGeneratorInfo.h"
const wstring FlatGeneratorInfo::STRUCTURE_VILLAGE = L"village";
const wstring FlatGeneratorInfo::STRUCTURE_BIOME_SPECIFIC = L"biome_1";
const wstring FlatGeneratorInfo::STRUCTURE_STRONGHOLD = L"stronghold";
const wstring FlatGeneratorInfo::STRUCTURE_MINESHAFT = L"mineshaft";
const wstring FlatGeneratorInfo::STRUCTURE_BIOME_DECORATION = L"decoration";
const wstring FlatGeneratorInfo::STRUCTURE_LAKE = L"lake";
const wstring FlatGeneratorInfo::STRUCTURE_LAVA_LAKE = L"lava_lake";
const wstring FlatGeneratorInfo::STRUCTURE_DUNGEON = L"dungeon";
FlatGeneratorInfo::FlatGeneratorInfo()
{
biome = 0;
}
FlatGeneratorInfo::~FlatGeneratorInfo()
{
for(auto& layer : layers)
{
delete layer;
}
}
int FlatGeneratorInfo::getBiome()
{
return biome;
}
void FlatGeneratorInfo::setBiome(int biome)
{
this->biome = biome;
}
unordered_map<wstring, unordered_map<wstring, wstring> > *FlatGeneratorInfo::getStructures()
{
return &structures;
}
vector<FlatLayerInfo *> *FlatGeneratorInfo::getLayers()
{
return &layers;
}
void FlatGeneratorInfo::updateLayers()
{
int y = 0;
for(auto& layer : layers)
{
layer->setStart(y);
y += layer->getHeight();
}
}
wstring FlatGeneratorInfo::toString()
{
return L"";
#if 0
StringBuilder builder = new StringBuilder();
builder.append(SERIALIZATION_VERSION);
builder.append(";");
for (size_t i = 0; i < layers.size(); i++)
{
if (i > 0) builder.append(",");
builder.append(layers.get(i).toString());
}
builder.append(";");
builder.append(biome);
if (!structures.isEmpty())
{
builder.append(";");
int structCount = 0;
for (Map.Entry<String, Map<String, String>> structure : structures.entrySet())
{
if (structCount++ > 0) builder.append(",");
builder.append(structure.getKey().toLowerCase());
Map<String, String> options = structure.getValue();
if (!options.isEmpty())
{
builder.append("(");
int optionCount = 0;
for (Map.Entry<String, String> option : options.entrySet())
{
if (optionCount++ > 0) builder.append(" ");
builder.append(option.getKey());
builder.append("=");
builder.append(option.getValue());
}
builder.append(")");
}
}
}
else
{
builder.append(";");
}
return builder.toString();
#endif
}
FlatLayerInfo *FlatGeneratorInfo::getLayerFromString(const wstring &input, int yOffset)
{
return nullptr;
#if 0
std::vector<std::wstring> parts = stringSplit(input, L'x');
int height = 1;
int id;
int data = 0;
if (parts.size() == 2)
{
height = _fromString<int>(parts[0]);
if (yOffset + height >= Level::maxBuildHeight) height = Level::maxBuildHeight - yOffset;
if (height < 0) height = 0;
}
wstring identity = parts[parts.size() - 1];
parts = stringSplit(identity, L':');
id = _fromString<int>(parts[0]);
if (parts.size() > 1) data = _from_String<int>(parts[1]);
if (Tile::tiles[id] == nullptr)
{
id = 0;
data = 0;
}
if (data < 0 || data > 15) data = 0;
FlatLayerInfo *result = new FlatLayerInfo(height, id, data);
result->setStart(yOffset);
return result;
#endif
}
vector<FlatLayerInfo *> *FlatGeneratorInfo::getLayersFromString(const wstring &input)
{
if (input.empty()) return nullptr;
vector<FlatLayerInfo *> *result = new vector<FlatLayerInfo *>();
std::vector<std::wstring> depths = stringSplit(input, L',');
int yOffset = 0;
for(auto& depth : depths)
{
FlatLayerInfo *layer = getLayerFromString(depth, yOffset);
if (layer == nullptr) return nullptr;
result->push_back(layer);
yOffset += layer->getHeight();
}
return result;
}
FlatGeneratorInfo *FlatGeneratorInfo::fromValue(const wstring &input)
{
return getDefault();
#if 0
if (input.empty()) return getDefault();
std::vector<std::wstring> parts = stringSplit(input, L';');
int version = parts.size() == 1 ? 0 : Mth::getInt(parts[0], 0);
if (version < 0 || version > SERIALIZATION_VERSION) return getDefault();
FlatGeneratorInfo *result = new FlatGeneratorInfo();
int index = parts.size() == 1 ? 0 : 1;
vector<FlatLayerInfo *> *layers = getLayersFromString(parts[index++]);
if (layers == nullptr || layers->isEmpty())
{
delete layers;
return getDefault();
}
result->getLayers()->addAll(layers);
delete layers;
result->updateLayers();
int biome = Biome::plains_Id;
if (version > 0 && parts.size() > index) biome = Mth::getInt(parts[index++], biome);
result->setBiome(biome);
if (version > 0 && parts.size() > index)
{
std::vector<std::wstring> structures = stringSplit(parts[index++], L',');
for (auto it = structures.begin(); it != structures.end(); ++it)
{
std::vector<std::wstring> separated = stringSplit(parts[index++], L"\\(");
unordered_map<wstring, wstring> structureOptions;
if (separated[0].length() > 0)
{
(*result->getStructures())[separated[0]] = structureOptions;
if (separated.size() > 1 && separated[1].endsWith(L")") && separated[1].length() > 1)
{
String[] options = separated[1].substring(0, separated[1].length() - 1).split(" ");
for (int option = 0; option < options.length; option++)
{
String[] split = options[option].split("=", 2);
if (split.length == 2) structureOptions[split[0]] = split[1];
}
}
}
}
}
else
{
(* (result->getStructures()) )[STRUCTURE_VILLAGE] = unordered_map<wstring, wstring>();
}
return result;
#endif
}
FlatGeneratorInfo *FlatGeneratorInfo::getDefault()
{
FlatGeneratorInfo *result = new FlatGeneratorInfo();
result->setBiome(Biome::plains->id);
result->getLayers()->push_back(new FlatLayerInfo(1, Tile::unbreakable_Id));
result->getLayers()->push_back(new FlatLayerInfo(2, Tile::dirt_Id));
result->getLayers()->push_back(new FlatLayerInfo(1, Tile::grass_Id));
result->updateLayers();
(* (result->getStructures()) )[STRUCTURE_VILLAGE] = unordered_map<wstring, wstring>();
return result;
}
|