the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "StringHelpers.h"
3#include "net.minecraft.world.level.levelgen.flat.h"
4#include "net.minecraft.world.level.tile.h"
5#include "FlatGeneratorInfo.h"
6
7const wstring FlatGeneratorInfo::STRUCTURE_VILLAGE = L"village";
8const wstring FlatGeneratorInfo::STRUCTURE_BIOME_SPECIFIC = L"biome_1";
9const wstring FlatGeneratorInfo::STRUCTURE_STRONGHOLD = L"stronghold";
10const wstring FlatGeneratorInfo::STRUCTURE_MINESHAFT = L"mineshaft";
11const wstring FlatGeneratorInfo::STRUCTURE_BIOME_DECORATION = L"decoration";
12const wstring FlatGeneratorInfo::STRUCTURE_LAKE = L"lake";
13const wstring FlatGeneratorInfo::STRUCTURE_LAVA_LAKE = L"lava_lake";
14const wstring FlatGeneratorInfo::STRUCTURE_DUNGEON = L"dungeon";
15
16FlatGeneratorInfo::FlatGeneratorInfo()
17{
18 biome = 0;
19}
20
21FlatGeneratorInfo::~FlatGeneratorInfo()
22{
23 for(AUTO_VAR(it, layers.begin()); it != layers.end(); ++it)
24 {
25 delete *it;
26 }
27}
28
29int FlatGeneratorInfo::getBiome()
30{
31 return biome;
32}
33
34void FlatGeneratorInfo::setBiome(int biome)
35{
36 this->biome = biome;
37}
38
39unordered_map<wstring, unordered_map<wstring, wstring> > *FlatGeneratorInfo::getStructures()
40{
41 return &structures;
42}
43
44vector<FlatLayerInfo *> *FlatGeneratorInfo::getLayers()
45{
46 return &layers;
47}
48
49void FlatGeneratorInfo::updateLayers()
50{
51 int y = 0;
52
53 for(AUTO_VAR(it, layers.begin()); it != layers.end(); ++it)
54 {
55 FlatLayerInfo *layer = *it;
56 layer->setStart(y);
57 y += layer->getHeight();
58 }
59}
60
61wstring FlatGeneratorInfo::toString()
62{
63 return L"";
64#if 0
65 StringBuilder builder = new StringBuilder();
66
67 builder.append(SERIALIZATION_VERSION);
68 builder.append(";");
69
70 for (int i = 0; i < layers.size(); i++)
71 {
72 if (i > 0) builder.append(",");
73 builder.append(layers.get(i).toString());
74 }
75
76 builder.append(";");
77 builder.append(biome);
78
79 if (!structures.isEmpty())
80 {
81 builder.append(";");
82 int structCount = 0;
83
84 for (Map.Entry<String, Map<String, String>> structure : structures.entrySet())
85 {
86 if (structCount++ > 0) builder.append(",");
87 builder.append(structure.getKey().toLowerCase());
88
89 Map<String, String> options = structure.getValue();
90 if (!options.isEmpty())
91 {
92 builder.append("(");
93 int optionCount = 0;
94
95 for (Map.Entry<String, String> option : options.entrySet())
96 {
97 if (optionCount++ > 0) builder.append(" ");
98 builder.append(option.getKey());
99 builder.append("=");
100 builder.append(option.getValue());
101 }
102
103 builder.append(")");
104 }
105 }
106 }
107 else
108 {
109 builder.append(";");
110 }
111
112 return builder.toString();
113#endif
114}
115
116FlatLayerInfo *FlatGeneratorInfo::getLayerFromString(const wstring &input, int yOffset)
117{
118 return NULL;
119#if 0
120 std::vector<std::wstring> parts = stringSplit(input, L'x');
121
122 int height = 1;
123 int id;
124 int data = 0;
125
126 if (parts.size() == 2)
127 {
128 height = _fromString<int>(parts[0]);
129 if (yOffset + height >= Level::maxBuildHeight) height = Level::maxBuildHeight - yOffset;
130 if (height < 0) height = 0;
131 }
132
133 wstring identity = parts[parts.size() - 1];
134 parts = stringSplit(identity, L':');
135
136 id = _fromString<int>(parts[0]);
137 if (parts.size() > 1) data = _from_String<int>(parts[1]);
138
139 if (Tile::tiles[id] == NULL)
140 {
141 id = 0;
142 data = 0;
143 }
144
145 if (data < 0 || data > 15) data = 0;
146
147 FlatLayerInfo *result = new FlatLayerInfo(height, id, data);
148 result->setStart(yOffset);
149 return result;
150#endif
151}
152
153vector<FlatLayerInfo *> *FlatGeneratorInfo::getLayersFromString(const wstring &input)
154{
155 if (input.empty()) return NULL;
156
157 vector<FlatLayerInfo *> *result = new vector<FlatLayerInfo *>();
158 std::vector<std::wstring> depths = stringSplit(input, L',');
159
160 int yOffset = 0;
161
162 for(AUTO_VAR(it, depths.begin()); it != depths.end(); ++it)
163 {
164 FlatLayerInfo *layer = getLayerFromString(*it, yOffset);
165 if (layer == NULL) return NULL;
166 result->push_back(layer);
167 yOffset += layer->getHeight();
168 }
169
170 return result;
171}
172
173FlatGeneratorInfo *FlatGeneratorInfo::fromValue(const wstring &input)
174{
175 return getDefault();
176
177#if 0
178 if (input.empty()) return getDefault();
179 std::vector<std::wstring> parts = stringSplit(input, L';');
180
181 int version = parts.size() == 1 ? 0 : Mth::getInt(parts[0], 0);
182 if (version < 0 || version > SERIALIZATION_VERSION) return getDefault();
183
184 FlatGeneratorInfo *result = new FlatGeneratorInfo();
185 int index = parts.size() == 1 ? 0 : 1;
186 vector<FlatLayerInfo *> *layers = getLayersFromString(parts[index++]);
187
188 if (layers == NULL || layers->isEmpty())
189 {
190 delete layers;
191 return getDefault();
192 }
193
194 result->getLayers()->addAll(layers);
195 delete layers;
196 result->updateLayers();
197
198 int biome = Biome::plains_Id;
199 if (version > 0 && parts.size() > index) biome = Mth::getInt(parts[index++], biome);
200 result->setBiome(biome);
201
202 if (version > 0 && parts.size() > index)
203 {
204 std::vector<std::wstring> structures = stringSplit(parts[index++], L',');
205
206 for(AUTO_VAR(it, structures.begin()); it != structures.end(); ++it)
207 {
208 std::vector<std::wstring> separated = stringSplit(parts[index++], L"\\(");
209
210 unordered_map<wstring, wstring> structureOptions;
211
212 if (separated[0].length() > 0)
213 {
214 (*result->getStructures())[separated[0]] = structureOptions;
215
216 if (separated.size() > 1 && separated[1].endsWith(L")") && separated[1].length() > 1)
217 {
218 String[] options = separated[1].substring(0, separated[1].length() - 1).split(" ");
219
220 for (int option = 0; option < options.length; option++)
221 {
222 String[] split = options[option].split("=", 2);
223 if (split.length == 2) structureOptions[split[0]] = split[1];
224 }
225 }
226 }
227 }
228 }
229 else
230 {
231 (* (result->getStructures()) )[STRUCTURE_VILLAGE] = unordered_map<wstring, wstring>();
232 }
233
234 return result;
235#endif
236}
237
238FlatGeneratorInfo *FlatGeneratorInfo::getDefault()
239{
240 FlatGeneratorInfo *result = new FlatGeneratorInfo();
241
242 result->setBiome(Biome::plains->id);
243 result->getLayers()->push_back(new FlatLayerInfo(1, Tile::unbreakable_Id));
244 result->getLayers()->push_back(new FlatLayerInfo(2, Tile::dirt_Id));
245 result->getLayers()->push_back(new FlatLayerInfo(1, Tile::grass_Id));
246 result->updateLayers();
247 (* (result->getStructures()) )[STRUCTURE_VILLAGE] = unordered_map<wstring, wstring>();
248
249 return result;
250}