HyCodeYourTale
classpublicPriority 3

ZoneBiomesJsonLoader

com.hypixel.hytale.server.worldgen.loader.zone.ZoneBiomesJsonLoader

extends JsonLoader>

1

Methods

1

Public Methods

1

Fields

1

Constructors

Constructors

public
ZoneBiomesJsonLoader(SeedString<SeedStringResource> seed, Path dataFolder, JsonElement json, ZoneFileContext zone)

Methods

Public Methods (1)

public
IWeightedMap<TileBiome> load()

Fields

Protected Fields (1)

protectedZoneFileContext zoneContext

Inheritance

Parent
Current
Interface
Child

Use mouse wheel to zoom, drag to pan. Click nodes to navigate.

Related Classes

Source Code

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<SeedStringResource, IWeightedMap<TileBiome>> {
   protected final ZoneFileContext zoneContext;

   public ZoneBiomesJsonLoader(SeedString<SeedStringResource> seed, Path dataFolder, JsonElement json, ZoneFileContext zone) {
      super(seed, dataFolder, json);
      this.zoneContext = zone;
   }

   public IWeightedMap<TileBiome> load() {
      WeightedMap.Builder<TileBiome> builder = WeightedMap.builder(TileBiome.EMPTY_ARRAY);

      for (Entry<String, BiomeFileContext> 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";
   }
}