Last active
July 30, 2020 02:13
-
-
Save CorgiTaco/e90a60fc5cdcf9c391eca3be33209e17 to your computer and use it in GitHub Desktop.
Use this to generate biomes from code to json. Tested and used in 20w29a. Code is a bit sloppy but yeah :) PLEASE FOR THE LOVE OF GOD PUT THIS IN ITS OWN EMPTY FOLDER, IF YOU DON'T THE DIRECTORY ITS IN WILL GET THANOS SNAPPED. Here's why https://streamable.com/efrpiw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
MIT License | |
Copyright (c) 2020 Corgi Taco | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE.*/ | |
public class BiomeDataGenerator { | |
//Have this load after everything else. | |
public static void dataGenBiome(String filePath) throws IOException { | |
OptionParser optionParser = new OptionParser(); | |
OptionSpec<Void> optionSpec = optionParser.accepts("help", "Show the help menu").forHelp(); | |
OptionSpec<Void> optionSpec7 = optionParser.accepts("all", "Include all generators"); | |
OptionSpec<String> optionSpec9 = optionParser.accepts("input", "Input folder").withRequiredArg(); | |
OptionSet optionSet = optionParser.parse("-all"); | |
if (!optionSet.has(optionSpec) && optionSet.hasOptions()) { | |
Path path = Paths.get((filePath)); | |
boolean bl = optionSet.has(optionSpec7); | |
DataGenerator dataGenerator = create(path, optionSet.valuesOf(optionSpec9).stream().map((string) -> Paths.get(string)).collect(Collectors.toList())); | |
dataGenerator.run(); | |
} else { | |
optionParser.printHelpOn(System.out); | |
} | |
} | |
public static DataGenerator create(Path output, Collection<Path> inputs) { | |
DataGenerator dataGenerator = new DataGenerator(output, inputs); | |
dataGenerator.install((new SnbtProvider(dataGenerator)).addWriter(new StructureValidatorProvider())); | |
dataGenerator.install(new BiomeDataProvider(dataGenerator)); | |
return dataGenerator; | |
} | |
public static class BiomeDataProvider implements DataProvider { | |
private static final Logger logger = LogManager.getLogger(); | |
private static final Gson gson = (new GsonBuilder()).setPrettyPrinting().create(); | |
private final DataGenerator dataGen; | |
public BiomeDataProvider(DataGenerator dataGenerator) { | |
this.dataGen = dataGenerator; | |
} | |
public void run(DataCache cache) { | |
Path path = this.dataGen.getOutput(); | |
Iterator var3 = BuiltinRegistries.BIOME.getEntries().iterator(); | |
while(var3.hasNext()) { | |
Map.Entry<RegistryKey<Biome>, Biome> entry = (Map.Entry)var3.next(); | |
Path path2 = filePath(path, entry.getKey().getValue(), entry.getValue()); | |
Biome biome = entry.getValue(); | |
Function<Supplier<Biome>, DataResult<JsonElement>> function = JsonOps.INSTANCE.withEncoder(Biome.field_24677); | |
try { | |
Optional optional = ((DataResult)function.apply(() -> biome)).result(); | |
if (optional.isPresent()) { | |
DataProvider.writeToPath(gson, cache, (JsonElement)optional.get(), path2); | |
} else { | |
logger.error("Couldn't serialize biome {}", path2); | |
} | |
} catch (IOException var9) { | |
logger.error("Couldn't save biome {}", path2, var9); | |
} | |
} | |
} | |
private static Path filePath(Path path, Identifier identifier, Biome biome) { | |
if (Objects.requireNonNull(BuiltinRegistries.BIOME.getId(biome)).toString().contains(MODID)) | |
return path.resolve(MODID + "/biomes/" + identifier.getPath() + ".json"); | |
else | |
return path.resolve("minecraft/biomes/" + identifier.getPath() + ".json"); | |
} | |
public String getName() { | |
return "Biomes"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment