PrefabContainerEntryJsonLoader class

Пакет: com.hypixel.hytale.server.worldgen.loader.container

Файл: com/hypixel/hytale/server/worldgen/loader/container/PrefabContainerJsonLoader.java

extends: JsonLoader<SeedStringResource, PrefabContainer.PrefabContainerEntry>

Поля (6)

МодификаторыТипИмя
private final FileLoadingContext context
IWeightedMap var1
int var1
var1
PrefabPatternGenerator var2
String var2

Методы (4)

МодификаторыВозвратСигнатура
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("Could not find prefab pattern. Keyword: Pattern")
if if(var1 == Integer.MIN_VALUE)
public PrefabContainer.PrefabContainerEntry loadpublic PrefabContainer.PrefabContainerEntry load()
protected int loadEnvironmentprotected int loadEnvironment()

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.worldgen.loader.container;

class="kw">import com.google.gson.JsonArray;
class="kw">import com.google.gson.JsonElement;
class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.event.ModifyEvent;
class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.event.ModifyEvents;
class="kw">import com.hypixel.hytale.common.map.IWeightedMap;
class="kw">import com.hypixel.hytale.procedurallib.json.JsonLoader;
class="kw">import com.hypixel.hytale.procedurallib.json.SeedString;
class="kw">import com.hypixel.hytale.server.core.asset.type.environment.config.Environment;
class="kw">import com.hypixel.hytale.server.worldgen.SeedStringResource;
class="kw">import com.hypixel.hytale.server.worldgen.container.PrefabContainer;
class="kw">import com.hypixel.hytale.server.worldgen.loader.WorldGenPrefabSupplier;
class="kw">import com.hypixel.hytale.server.worldgen.loader.context.BiomeFileContext;
class="kw">import com.hypixel.hytale.server.worldgen.loader.context.FileLoadingContext;
class="kw">import com.hypixel.hytale.server.worldgen.loader.prefab.PrefabPatternGeneratorJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.prefab.WeightedPrefabMapJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.prefab.PrefabPatternGenerator;
class="kw">import com.hypixel.hytale.server.worldgen.util.ListPool;
class="kw">import java.nio.file.Path;
class="kw">import javax.annotation.Nonnull;

class="kw">public class PrefabContainerJsonLoader class="kw">extends JsonLoader<SeedStringResource, PrefabContainer> {
   @Nonnull
   class="kw">protected class="kw">final BiomeFileContext biomeContext;
   @Nonnull
   class="kw">protected class="kw">final FileLoadingContext fileContext;

   class="kw">public PrefabContainerJsonLoader(@Nonnull SeedString<SeedStringResource> var1, Path var2, JsonElement var3, @Nonnull BiomeFileContext var4) {
      super(var1.append(".PrefabContainer"), var2, var3);
      this.biomeContext = var4;
      this.fileContext = var4.getParentContext().getParentContext();
   }

   @Nonnull
   class="kw">public PrefabContainer load() {
      class="kw">return new PrefabContainer(this.loadEntries());
   }

   @Nonnull
   class="kw">protected PrefabContainer.PrefabContainerEntry[] loadEntries() {
      JsonArray var1 = this.mustGetArray("Entries", EMPTY_ARRAY);

      try (ListPool.Resource var2 = PrefabContainer.ENTRY_POOL.acquire()) {
         for (int var3 = 0; var3 < var1.size(); var3++) {
            try {
               var2.add(
                  new PrefabContainerJsonLoader.PrefabContainerEntryJsonLoader(this.seed.append("-" + var3), this.dataFolder, var1.get(var3), this.fileContext)
                     .load()
               );
            } catch (Throwable var6) {
               throw new Error(String.format("Failed to load prefab container entry #%s.", var3), var6);
            }
         }

         ModifyEvent.SeedGenerator var8 = new ModifyEvent.SeedGenerator<>(this.seed);
         ModifyEvent.dispatch(
            ModifyEvents.BiomePrefabs.class,
            new ModifyEvents.BiomePrefabs(
               this.seed,
               this.biomeContext,
               var2,
               var2x -> new PrefabContainerJsonLoader.PrefabContainerEntryJsonLoader(var8.next(), this.dataFolder, this.loadFile(var2x), this.fileContext)
                  .load()
            )
         );
         class="kw">return var2.toArray();
      }
   }

   class="kw">public class="kw">interface Constants {
      String KEY_ENTRIES = "Entries";
      String KEY_ENTRY_PREFAB = "Prefab";
      String KEY_ENTRY_WEIGHT = "Weight";
      String KEY_ENTRY_PATTERN = "Pattern";
      String KEY_ENVIRONMENT = "Environment";
      String ERROR_FAIL_ENTRY = "Failed to load prefab container entry #%s.";
      String ERROR_LOADING_ENVIRONMENT = "Error while looking up environment \"%s\"!";
      String ERROR_ENTRY_NO_PATTERN = "Could not find prefab pattern. Keyword: Pattern";
   }

   class="kw">public class="kw">static class PrefabContainerEntryJsonLoader class="kw">extends JsonLoader<SeedStringResource, PrefabContainer.PrefabContainerEntry> {
      class="kw">private class="kw">final FileLoadingContext context;

      class="kw">public PrefabContainerEntryJsonLoader(@Nonnull SeedString<SeedStringResource> var1, Path var2, JsonElement var3, FileLoadingContext var4) {
         super(var1.append(".PrefabContainerEntry"), var2, var3);
         this.context = var4;
      }

      @Nonnull
      class="kw">public PrefabContainer.PrefabContainerEntry load() {
         IWeightedMap var1 = new WeightedPrefabMapJsonLoader(this.seed, this.dataFolder, this.json, "Prefab", "Weight").load();
         if (!this.has("Pattern")) {
            throw new IllegalArgumentException("Could not find prefab pattern. Keyword: Pattern");
         }

         PrefabPatternGenerator var2 = new PrefabPatternGeneratorJsonLoader(this.seed, this.dataFolder, this.get("Pattern"), this.context).load();
         class="kw">return new PrefabContainer.PrefabContainerEntry(var1, var2, this.loadEnvironment());
      }

      class="kw">protected int loadEnvironment() {
         int var1 = Integer.MIN_VALUE;
         if (this.has("Environment")) {
            String var2 = this.get("Environment").getAsString();
            var1 = Environment.getAssetMap().getIndex(var2);
            if (var1 == Integer.MIN_VALUE) {
               throw new Error(String.format("Error while looking up environment \"%s\"!", var2));
            }
         }

         class="kw">return var1;
      }
   }
}