33import com .google .gson .*;
44import mmd .orespawn .OreSpawn ;
55import mmd .orespawn .api .DimensionLogic ;
6- import mmd .orespawn .api .SpawnEntry ;
76import mmd .orespawn .api .OreSpawnAPI ;
7+ import mmd .orespawn .api .SpawnEntry ;
88import mmd .orespawn .api .SpawnLogic ;
99import net .minecraft .block .state .IBlockState ;
1010import net .minecraft .world .biome .Biome ;
11- import net .minecraftforge .fml .common .Loader ;
12- import net .minecraftforge .fml .common .ModContainer ;
1311import org .apache .commons .io .Charsets ;
1412import org .apache .commons .io .FileUtils ;
1513import org .apache .commons .lang3 .StringEscapeUtils ;
@@ -25,68 +23,64 @@ public enum OreSpawnWriter {
2523 public void writeSpawnEntries () {
2624 Gson gson = new GsonBuilder ().setPrettyPrinting ().create ();
2725
28- Loader . instance (). getActiveModList (). stream (). map ( ModContainer :: getModId ). forEach ( id -> {
29- SpawnLogic logic = OreSpawn . API . getSpawnLogic ( id );
26+ for ( Map . Entry < String , SpawnLogic > entry : OreSpawn . API . getAllSpawnLogic (). entrySet ()) {
27+ Map < Integer , DimensionLogic > dimensions = entry . getValue (). getAllDimensions ( );
3028
31- if (logic != null ) {
32- Map <Integer , DimensionLogic > dimensions = logic .getAllDimensions ();
29+ JsonArray array = new JsonArray ();
3330
34- JsonArray array = new JsonArray ();
31+ for (Map .Entry <Integer , DimensionLogic > dimension : dimensions .entrySet ()) {
32+ JsonObject object = new JsonObject ();
3533
36- for (Map .Entry <Integer , DimensionLogic > dimension : dimensions .entrySet ()) {
37- JsonObject object = new JsonObject ();
38-
39- if (dimension .getKey () != OreSpawnAPI .DIMENSION_WILDCARD ) {
40- object .addProperty ("dimension" , dimension .getKey ());
41- }
42-
43- JsonArray ores = new JsonArray ();
44- Collection <SpawnEntry > entries = dimension .getValue ().getEntries ();
34+ if (dimension .getKey () != OreSpawnAPI .DIMENSION_WILDCARD ) {
35+ object .addProperty ("dimension" , dimension .getKey ());
36+ }
4537
46- for ( SpawnEntry entry : entries ) {
47- JsonObject ore = new JsonObject ();
38+ JsonArray ores = new JsonArray ();
39+ Collection < SpawnEntry > entries = dimension . getValue (). getEntries ();
4840
49- ore .addProperty ("block" , entry .getState ().getBlock ().getRegistryName ().toString ());
41+ for (SpawnEntry spawnEntry : entries ) {
42+ JsonObject ore = new JsonObject ();
5043
51- if (entry .getState () != entry .getState ().getBlock ().getDefaultState ()) {
52- ore .addProperty ("state" , this .serializeBlockState (entry .getState ()));
53- }
44+ ore .addProperty ("block" , spawnEntry .getState ().getBlock ().getRegistryName ().toString ());
5445
55- ore .addProperty ("size" , entry .getSize ());
56- ore .addProperty ("variation" , entry .getVariation ());
57- ore .addProperty ("frequency" , entry .getFrequency ());
58- ore .addProperty ("min_height" , entry .getMinHeight ());
59- ore .addProperty ("max_height" , entry .getMaxHeight ());
46+ if (spawnEntry .getState () != spawnEntry .getState ().getBlock ().getDefaultState ()) {
47+ ore .addProperty ("state" , this .serializeBlockState (spawnEntry .getState ()));
48+ }
6049
61- Biome [] biomeArray = entry .getBiomes ();
50+ ore .addProperty ("size" , spawnEntry .getSize ());
51+ ore .addProperty ("variation" , spawnEntry .getVariation ());
52+ ore .addProperty ("frequency" , spawnEntry .getFrequency ());
53+ ore .addProperty ("min_height" , spawnEntry .getMinHeight ());
54+ ore .addProperty ("max_height" , spawnEntry .getMaxHeight ());
6255
63- if (biomeArray != null && biomeArray .length != 0 ) {
64- JsonArray biomes = new JsonArray ();
56+ Biome [] biomeArray = spawnEntry .getBiomes ();
6557
66- for (Biome biome : biomeArray ) {
67- biomes .add (new JsonPrimitive (biome .getRegistryName ().toString ()));
68- }
58+ if (biomeArray != null && biomeArray .length != 0 ) {
59+ JsonArray biomes = new JsonArray ();
6960
70- ore .add ("biomes" , biomes );
61+ for (Biome biome : biomeArray ) {
62+ biomes .add (new JsonPrimitive (biome .getRegistryName ().toString ()));
7163 }
7264
73- ores .add (ore );
65+ ore .add ("biomes" , biomes );
7466 }
7567
76- object .add ("ores" , ores );
77-
78- array .add (object );
68+ ores .add (ore );
7969 }
8070
81- String json = gson . toJson ( array );
71+ object . add ( "ores" , ores );
8272
83- try {
84- FileUtils .writeStringToFile (new File ("." + File .separator + "orespawn" , id + ".json" ), StringEscapeUtils .unescapeJson (json ), Charsets .UTF_8 );
85- } catch (IOException e ) {
86- e .printStackTrace ();
87- }
73+ array .add (object );
8874 }
89- });
75+
76+ String json = gson .toJson (array );
77+
78+ try {
79+ FileUtils .writeStringToFile (new File ("." + File .separator + "orespawn" , entry .getKey () + ".json" ), StringEscapeUtils .unescapeJson (json ), Charsets .UTF_8 );
80+ } catch (IOException e ) {
81+ e .printStackTrace ();
82+ }
83+ }
9084 }
9185
9286 private String serializeBlockState (IBlockState state ) {
0 commit comments