package com.hypixel.hytale.server.worldgen.loader.zone; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.stream.JsonReader; import com.hypixel.hytale.common.map.IWeightedMap; import com.hypixel.hytale.common.map.WeightedMap; import com.hypixel.hytale.procedurallib.json.JsonLoader; import com.hypixel.hytale.procedurallib.json.SeedString; import com.hypixel.hytale.server.worldgen.SeedStringResource; import com.hypixel.hytale.server.worldgen.biome.TileBiome; import com.hypixel.hytale.server.worldgen.loader.biome.TileBiomeJsonLoader; import com.hypixel.hytale.server.worldgen.loader.context.BiomeFileContext; import com.hypixel.hytale.server.worldgen.loader.context.ZoneFileContext; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map.Entry; import javax.annotation.Nonnull; public class ZoneBiomesJsonLoader extends JsonLoader> { protected final ZoneFileContext zoneContext; public ZoneBiomesJsonLoader(SeedString seed, Path dataFolder, JsonElement json, ZoneFileContext zone) { super(seed, dataFolder, json); this.zoneContext = zone; } public IWeightedMap load() { WeightedMap.Builder builder = WeightedMap.builder(TileBiome.EMPTY_ARRAY); for (Entry biomeEntry : this.zoneContext.getTileBiomes()) { TileBiome biome = this.loadBiome(biomeEntry.getValue()); builder.put(biome, biome.getWeight()); } if (builder.size() <= 0) { throw new IllegalArgumentException("Could not find any tile biomes for this zone!"); } else { return builder.build(); } } @Nonnull protected TileBiome loadBiome(@Nonnull BiomeFileContext biomeContext) { try { JsonReader reader = new JsonReader(Files.newBufferedReader(biomeContext.getPath())); TileBiome var4; try { JsonElement biomeJson = JsonParser.parseReader(reader); var4 = new TileBiomeJsonLoader(this.seed, this.dataFolder, biomeJson, biomeContext).load(); } catch (Throwable var6) { try { reader.close(); } catch (Throwable var5) { var6.addSuppressed(var5); } throw var6; } reader.close(); return var4; } catch (Throwable var7) { throw new Error(String.format("Error while loading tile biome \"%s\" from \"%s\"", biomeContext.getName(), biomeContext.getPath().toString()), var7); } } public interface Constants { String ERROR_BIOME_FILES_NULL = "Biome files error occured."; String ERROR_BIOME_FAILED = "Error while loading tile biome \"%s\" from \"%s\""; String ERROR_NO_TILE_BIOMES = "Could not find any tile biomes for this zone!"; String FILE_TILE_PREFIX = "Tile."; String FILE_TILE_SUFFIX = ".json"; } }