forked from Cubitect/cubiomes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_markers_dynmap_to_csv.cpp
More file actions
269 lines (242 loc) · 8.33 KB
/
export_markers_dynmap_to_csv.cpp
File metadata and controls
269 lines (242 loc) · 8.33 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include "finders.h"
#include <stdio.h>
#include <math.h>
#include <locale.h>
#include <windows.h>
#include <fstream>
#include <string>
#include <iostream>
#define NUM_STRONGHOLDS 128 // Define the maximum number of strongholds
// Tableau des noms des structures
const char* structureNames[] = {
"Elément du terrain",
"Pyramide du désert",
"Temple de la jungle",
"Cabane de sorcière",
"Iglou",
"Village",
"Ruine océanique",
"Epave",
"Monument sous-marin",
"Manoir",
"Avant-poste",
"Portail en ruine",
"Portail en ruine (Nether)",
"Cité ancienne",
"Trésor",
"Mine abandonnée",
"Puit du désert",
"Géode",
"Forteresse",
"Vestige de bastion",
"Cité de l'End",
"Passerelle de l'End",
"Ile de l'End",
"Ruine de sentier",
"Chambre des épreuves"
};
// Fonction pour obtenir l'icône en fonction du type de structure
const char* getStructureIcon(int structureType)
{
switch (structureType)
{
case Ancient_City: return "skull";
case Bastion: return "building";
case Desert_Pyramid: return "temple";
case Desert_Well: return "beer";
case End_City: return "house";
case End_Gateway: return "portal";
case End_Island: return "pirateflag";
case Feature: return "default";
case Fortress: return "tower";
case Geode: return "diamond";
case Igloo: return "walk";
case Jungle_Temple: return "temple";
case Mansion: return "bighouse";
case Mineshaft: return "minecart";
case Monument: return "temple";
case Ocean_Ruin: return "tower";
case Outpost: return "lighthouse";
case Ruined_Portal: return "portal";
case Ruined_Portal_N: return "portal";
case Shipwreck: return "anchor";
case Swamp_Hut: return "door";
case Trail_Ruins: return "factory";
case Treasure: return "chest";
case Trial_Chambers: return "key";
case Village: return "house";
default: return "pin";
}
}
// Fonction pour lire la seed à partir du fichier server.properties
uint64_t getSeedFromProperties(const std::string& filePath)
{
std::ifstream file(filePath);
std::string line;
uint64_t seed = 0;
if (file.is_open())
{
while (std::getline(file, line))
{
if (line.find("level-seed") != std::string::npos)
{
size_t pos = line.find("=");
if (pos != std::string::npos)
{
std::string seedStr = line.substr(pos + 1);
seed = std::stoll(seedStr);
break;
}
}
}
file.close();
}
else
{
std::cerr << "Impossible d'ouvrir le fichier " << filePath << std::endl;
}
return seed;
}
// Fonction pour trouver des structures dans une zone spécifiée
void findStructures(FILE *file, int structureType, int mc, int dim, uint64_t seed,
int x0, int z0, int x1, int z1)
{
// Initialisation du générateur de biomes
Generator g;
setupGenerator(&g, mc, 0);
applySeed(&g, dim, seed);
// Configuration de la structure
StructureConfig sconf;
if (!getStructureConfig(structureType, mc, &sconf))
return; // Version ou structure incorrecte
// Segmentation de la zone en régions de structure
double blocksPerRegion = sconf.regionSize * 16.0;
int rx0 = (int) floor(x0 / blocksPerRegion);
int rz0 = (int) floor(z0 / blocksPerRegion);
int rx1 = (int) ceil(x1 / blocksPerRegion);
int rz1 = (int) ceil(z1 / blocksPerRegion);
int i, j;
// Parcours des régions de structure
for (j = rz0; j <= rz1; j++)
{
for (i = rx0; i <= rx1; i++)
{
// Vérification de la tentative de génération de structure dans la région (i, j)
Pos pos;
if (!getStructurePos(structureType, mc, seed, i, j, &pos))
continue; // Cette région n'est pas adaptée
if (pos.x < x0 || pos.x > x1 || pos.z < z0 || pos.z > z1)
continue; // La structure est en dehors de la zone spécifiée
if (!isViableStructurePos(structureType, &g, pos.x, pos.z, 0))
continue; // Les biomes ne sont pas viables
else if (mc >= MC_1_18)
{
// Certaines structures dans 1.18+ dépendent du terrain
if (!isViableStructureTerrain(structureType, &g, pos.x, pos.z))
continue;
}
// Affichage des coordonnées de la structure trouvée
// printf("Structure %s trouvée à : %d, %d (icon: %s)\n", structureNames[structureType], pos.x, pos.z, getStructureIcon(structureType));
// Écriture des coordonnées de la structure trouvée dans le fichier CSV
fprintf(file, "%s,%d,%d,%s\n", structureNames[structureType], pos.x, pos.z, getStructureIcon(structureType));
}
}
}
// Fonction pour rechercher les Strongholds
void findStrongholds(FILE *file, int mc, int dim, uint64_t seed)
{
// Initialisation de l'itérateur pour les Strongholds
StrongholdIter sh;
Pos pos;
// Initialisation du générateur pour les vérifications de biomes
Generator g;
setupGenerator(&g, mc, 0);
applySeed(&g, dim, seed);
// Initialisation du premier Stronghold
initFirstStronghold(&sh, mc, seed);
// Parcours des Strongholds
do
{
// Vérification des biomes et obtention de la position exacte
if (nextStronghold(&sh, &g))
{
pos = sh.pos;
// Affichage des coordonnées du Stronghold trouvé
// printf("Stronghold trouvé à : %d, %d (icon: gear)\n", pos.x, pos.z);
// Écriture des coordonnées du Stronghold dans le fichier CSV
fprintf(file, "Fort,%d,%d,gear\n", pos.x, pos.z);
}
} while (sh.index < NUM_STRONGHOLDS); // Continue jusqu'à ce que tous les Strongholds soient parcourus
}
// Fonction principale
int main()
{
// Configuration de la locale pour utiliser UTF-8
setlocale(LC_ALL, "fr_FR.UTF-8");
// Configuration de la console pour utiliser UTF-8
SetConsoleOutputCP(CP_UTF8);
// Chemin vers le fichier server.properties
std::string filePath = "../../Serveur-Minecraft/server.properties";
// Lire la seed à partir du fichier server.properties
uint64_t seed = getSeedFromProperties(filePath);
// Vérifier si la seed a été correctement lue
if (seed == 0)
{
std::cerr << "Erreur : Seed non trouvée dans le fichier server.properties" << std::endl;
return 1;
}
// Définition du rayon de recherche
int r = 20000;
// Variables pour la version de Minecraft et la dimension
int mcVersion = MC_1_21_3;
int dimension = DIM_OVERWORLD;
// Liste des types de structures à rechercher
int structures[] = {
Ancient_City,
// Bastion,
Desert_Pyramid,
Desert_Well,
// End_City,
// End_Gateway,
// End_Island,
// Feature, // for locations of temple generation attempts pre 1.13
// Fortress,
Geode,
Igloo,
Jungle_Temple,
Mansion,
Mineshaft,
Monument,
Ocean_Ruin,
Outpost,
Ruined_Portal,
// Ruined_Portal_N,
Shipwreck,
Swamp_Hut,
Trail_Ruins,
Treasure,
Trial_Chambers,
Village
};
// Ouverture du fichier CSV pour écrire les résultats
FILE *file = fopen("export_markers_dynmap.csv", "w");
if (!file)
{
perror("Échec de l'ouverture du fichier");
return 1;
}
// Écriture de l'en-tête du fichier CSV
fprintf(file, "structureType,x,z,icon\n");
// Recherche des Strongholds
printf("Recherche des forts (seed : %lld, version : %d, dimension : %d)...\n", seed, mcVersion, dimension);
findStrongholds(file, mcVersion, dimension, seed);
// Recherche des autres structures
printf("Recherche des structures dans un rayon de %d blocs (seed : %lld, version : %d, dimension : %d)...\n", r, seed, mcVersion, dimension);
for (int i = 0; i < sizeof(structures) / sizeof(structures[0]); i++)
{
findStructures(file, structures[i], mcVersion, dimension, seed, -r, -r, +r, +r);
}
// Fermeture du fichier CSV
fclose(file);
return 0;
}