CoverContainerJsonLoader class

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

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

extends: JsonLoader<SeedStringResource, CoverContainer>

Поля (36)

МодификаторыТипИмя
String ERROR_NO_ENTRIES
String ERROR_NO_TYPE
String ERROR_OFFSETS_ARRAY_SIZE
String ERROR_WEIGHTS_ARRAY_SIZE
String KEY_ENTRY_DENSITY
String KEY_ENTRY_HEIGHT_THRESHOLD
String KEY_ENTRY_NOISE_MASK
String KEY_ENTRY_OFFSET
String KEY_ENTRY_ON_WATER
String KEY_ENTRY_PARENT
String KEY_ENTRY_TYPE
String KEY_ENTRY_WEIGHT
ResolvedBlockArray var1
double var1
var1
ICoordinateRndCondition var1
var1
IBlockFluidCondition var1
var1
CoverContainer.CoverContainerEntry.CoverContainerEntryPart var10
JsonObject var2
int[] var2
JsonElement var2
ResolvedBlockArray var2
JsonArray var3
int[] var3
LongSet var3
JsonObject var4
WeightedMap.Builder var4
JsonArray var4
BlockFluidEntry var6
int var6
JsonArray var7
int var7
ModifyEvent.SeedGenerator var8
double var8

Методы (17)

МодификаторыВозвратСигнатура
public CoverContainerEntryJsonLoaderpublic CoverContainerEntryJsonLoader(@Nonnull SeedString<SeedStringResource> var1, Path var2, JsonElement var3)
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("Could not find type array for cover container! Keyword: Type")
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("Weight array size does not equal size of types array")
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("There are no blocks in this cover container!")
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("Offset array size does not equal size of types array")
for for(int var5 = 0; var5 < var1; var5++)
abstract for for(int var3 = 0; var3 < var7.size()
abstract for for(int var5 = 0; var5 < var1.size()
public CoverContainer.CoverContainerEntry loadpublic CoverContainer.CoverContainerEntry load()
protected double loadDensityprotected double loadDensity()
protected IWeightedMap<CoverContainer.CoverContainerEntry.CoverContainerEntryPart> loadEntriesprotected IWeightedMap<CoverContainer.CoverContainerEntry.CoverContainerEntryPart> loadEntries()
protected ICoordinateRndCondition loadHeightConditionprotected ICoordinateRndCondition loadHeightCondition()
protected ICoordinateCondition loadMapConditionprotected ICoordinateCondition loadMapCondition()
protected int[] loadOffsetArrayprotected int[] loadOffsetArray(int var1)
protected boolean loadOnWaterprotected boolean loadOnWater()
protected IBlockFluidCondition loadParentsprotected IBlockFluidCondition loadParents()
abstract super super(var1, var2, var3)

Исходный код

Показать/скрыть
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.google.gson.JsonObject;
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.common.map.WeightedMap;
class="kw">import com.hypixel.hytale.procedurallib.condition.ConstantBlockFluidCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.DefaultCoordinateRndCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.HeightCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.IBlockFluidCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.ICoordinateCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.ICoordinateRndCondition;
class="kw">import com.hypixel.hytale.procedurallib.json.HeightThresholdInterpreterJsonLoader;
class="kw">import com.hypixel.hytale.procedurallib.json.JsonLoader;
class="kw">import com.hypixel.hytale.procedurallib.json.NoiseMaskConditionJsonLoader;
class="kw">import com.hypixel.hytale.procedurallib.json.SeedString;
class="kw">import com.hypixel.hytale.server.worldgen.SeedStringResource;
class="kw">import com.hypixel.hytale.server.worldgen.container.CoverContainer;
class="kw">import com.hypixel.hytale.server.worldgen.loader.context.BiomeFileContext;
class="kw">import com.hypixel.hytale.server.worldgen.loader.util.ResolvedBlockArrayJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.util.BlockFluidEntry;
class="kw">import com.hypixel.hytale.server.worldgen.util.ListPool;
class="kw">import com.hypixel.hytale.server.worldgen.util.ResolvedBlockArray;
class="kw">import com.hypixel.hytale.server.worldgen.util.condition.HashSetBlockFluidCondition;
class="kw">import it.unimi.dsi.fastutil.longs.LongSet;
class="kw">import java.nio.file.Path;
class="kw">import java.util.Arrays;
class="kw">import javax.annotation.Nonnull;

class="kw">public class CoverContainerJsonLoader class="kw">extends JsonLoader<SeedStringResource, CoverContainer> {
   @Nonnull
   class="kw">protected class="kw">final BiomeFileContext biomeContext;

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

   @Nonnull
   class="kw">public CoverContainer load() {
      try (ListPool.Resource var1 = CoverContainer.ENTY_POOL.acquire()) {
         if (this.json != null && this.json.isJsonArray()) {
            JsonArray var7 = this.json.getAsJsonArray();

            for (int var3 = 0; var3 < var7.size(); var3++) {
               JsonObject var4 = var7.get(var3).getAsJsonObject();
               var1.add(new CoverContainerJsonLoader.CoverContainerEntryJsonLoader(this.seed.append("-" + var3), this.dataFolder, var4).load());
            }
         } else if (this.json != null && this.json.isJsonObject()) {
            JsonObject var2 = this.json.getAsJsonObject();
            var1.add(new CoverContainerJsonLoader.CoverContainerEntryJsonLoader(this.seed.append("-0"), this.dataFolder, var2).load());
         }

         ModifyEvent.SeedGenerator var8 = new ModifyEvent.SeedGenerator<>(this.seed);
         ModifyEvent.dispatch(
            ModifyEvents.BiomeCovers.class,
            new ModifyEvents.BiomeCovers(
               this.seed,
               this.biomeContext,
               var1,
               var2x -> new CoverContainerJsonLoader.CoverContainerEntryJsonLoader(var8.next(), this.dataFolder, this.loadFile(var2x)).load()
            )
         );
         class="kw">return new CoverContainer(var1.toArray());
      }
   }

   class="kw">public class="kw">interface Constants {
      String KEY_ENTRY_TYPE = "Type";
      String KEY_ENTRY_WEIGHT = "Weight";
      String KEY_ENTRY_DENSITY = "Density";
      String KEY_ENTRY_NOISE_MASK = "NoiseMask";
      String KEY_ENTRY_HEIGHT_THRESHOLD = "HeightThreshold";
      String KEY_ENTRY_OFFSET = "Offset";
      String KEY_ENTRY_PARENT = "Parent";
      String KEY_ENTRY_ON_WATER = "OnWater";
      String ERROR_NO_TYPE = "Could not find type array for cover container! Keyword: Type";
      String ERROR_NO_ENTRIES = "There are no blocks in this cover container!";
      String ERROR_WEIGHTS_ARRAY_SIZE = "Weight array size does not equal size of types array";
      String ERROR_OFFSETS_ARRAY_SIZE = "Offset array size does not equal size of types array";
   }

   class="kw">public class="kw">static class CoverContainerEntryJsonLoader class="kw">extends JsonLoader<SeedStringResource, CoverContainer.CoverContainerEntry> {
      class="kw">public CoverContainerEntryJsonLoader(@Nonnull SeedString<SeedStringResource> var1, Path var2, JsonElement var3) {
         super(var1.append(".CoverContainerEntry"), var2, var3);
      }

      @Nonnull
      class="kw">public CoverContainer.CoverContainerEntry load() {
         class="kw">return new CoverContainer.CoverContainerEntry(
            this.loadEntries(), this.loadMapCondition(), this.loadHeightCondition(), this.loadParents(), this.loadDensity(), this.loadOnWater()
         );
      }

      @Nonnull
      class="kw">protected IWeightedMap<CoverContainer.CoverContainerEntry.CoverContainerEntryPart> loadEntries() {
         if (!this.has("Type")) {
            throw new IllegalArgumentException("Could not find type array for cover container! Keyword: Type");
         }

         ResolvedBlockArray var1 = new ResolvedBlockArrayJsonLoader(this.seed, this.dataFolder, this.get("Type")).load();
         int[] var2 = this.loadOffsetArray(var1.size());
         JsonArray var3 = this.has("Weight") ? this.get("Weight").getAsJsonArray() : null;
         if (var3 != null && var3.size() != var1.size()) {
            throw new IllegalArgumentException("Weight array size does not equal size of types array");
         }

         WeightedMap.Builder var4 = WeightedMap.builder(CoverContainer.CoverContainerEntry.CoverContainerEntryPart.EMPTY_ARRAY);

         for (int var5 = 0; var5 < var1.size(); var5++) {
            BlockFluidEntry var6 = var1.getEntries()[var5];
            int var7 = var2[var5];
            double var8 = var3 == null ? 1.0 : var3.get(var5).getAsDouble();
            CoverContainer.CoverContainerEntry.CoverContainerEntryPart var10 = new CoverContainer.CoverContainerEntry.CoverContainerEntryPart(var6, var7);
            var4.put(var10, var8);
         }

         if (var4.size() <= 0) {
            throw new IllegalArgumentException("There are no blocks in this cover container!");
         } else {
            class="kw">return var4.build();
         }
      }

      class="kw">protected int[] loadOffsetArray(int var1) {
         JsonElement var2 = this.get("Offset");
         int[] var3 = new int[var1];
         if (var2 == null || var2.isJsonNull()) {
            Arrays.fill(var3, 0);
         } else if (var2.isJsonArray()) {
            JsonArray var4 = var2.getAsJsonArray();
            if (var4.size() != var1) {
               throw new IllegalArgumentException("Offset array size does not equal size of types array");
            }

            for (int var5 = 0; var5 < var1; var5++) {
               var3[var5] = var4.get(var5).getAsInt();
            }
         } else {
            int var6 = var2.getAsInt();
            Arrays.fill(var3, var6);
         }

         class="kw">return var3;
      }

      class="kw">protected double loadDensity() {
         double var1 = 1.0;
         if (this.has("Density")) {
            var1 = this.get("Density").getAsDouble();
         }

         class="kw">return var1;
      }

      @Nonnull
      class="kw">protected ICoordinateCondition loadMapCondition() {
         class="kw">return new NoiseMaskConditionJsonLoader<>(this.seed, this.dataFolder, this.get("NoiseMask")).load();
      }

      @Nonnull
      class="kw">protected ICoordinateRndCondition loadHeightCondition() {
         ICoordinateRndCondition var1 = DefaultCoordinateRndCondition.DEFAULT_TRUE;
         if (this.has("HeightThreshold")) {
            var1 = new HeightCondition(new HeightThresholdInterpreterJsonLoader<>(this.seed, this.dataFolder, this.get("HeightThreshold"), 320).load());
         }

         class="kw">return var1;
      }

      @Nonnull
      class="kw">protected IBlockFluidCondition loadParents() {
         IBlockFluidCondition var1 = ConstantBlockFluidCondition.DEFAULT_TRUE;
         if (this.has("Parent")) {
            ResolvedBlockArray var2 = new ResolvedBlockArrayJsonLoader(this.seed, this.dataFolder, this.get("Parent")).load();
            LongSet var3 = var2.getEntrySet();
            var1 = new HashSetBlockFluidCondition(var3);
         }

         class="kw">return var1;
      }

      class="kw">protected boolean loadOnWater() {
         class="kw">return this.has("OnWater") && this.get("OnWater").getAsBoolean();
      }
   }
}