CavePrefabConfigJsonLoader class

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

Файл: com/hypixel/hytale/server/worldgen/loader/cave/CavePrefabConfigJsonLoader.java

extends: JsonLoader<SeedStringResource, CavePrefabContainer.CavePrefabEntry.CavePrefabConfig>

Поля (31)

МодификаторыТипИмя
String ERROR_ROTATIONS_MUST_POSITIVE
String ERROR_ROTATIONS_UNKOWN
String ERROR_ROTATIONS_UNKOWN_TYPE
String KEY_BIOME_MASK
String KEY_BLOCK_MASK
String KEY_DISPLACEMENT
String KEY_HEIGHT_THRESHOLD
String KEY_ITERATIONS
String KEY_NOISE_MASK
String KEY_PLACEMENT
String KEY_ROTATIONS
String SEED_STRING_BIOME_MASK_TYPE
PrefabRotation[] var1
var1
var1
CavePrefabPlacement var1
var1
IIntCondition var1
var1
BlockMaskCondition var1
var1
IDoubleCoordinateHashSupplier var1
var1
ICoordinateRndCondition var1
var1
JsonElement var2
ZoneFileContext var2
JsonArray var3
String var5
String var9
final ZoneFileContext zoneContext

Методы (2)

МодификаторыВозвратСигнатура
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("Array for rotations must have at least one entry or left away to allow random rotation")
for for(int var4 = 0; var4 < var1.length; var4++)

Исходный код

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

class="kw">import com.google.gson.JsonArray;
class="kw">import com.google.gson.JsonElement;
class="kw">import com.hypixel.hytale.procedurallib.condition.ConstantIntCondition;
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.ICoordinateCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.ICoordinateRndCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.IIntCondition;
class="kw">import com.hypixel.hytale.procedurallib.json.DoubleRangeJsonLoader;
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.procedurallib.supplier.ConstantDoubleCoordinateHashSupplier;
class="kw">import com.hypixel.hytale.procedurallib.supplier.DoubleRangeCoordinateHashSupplier;
class="kw">import com.hypixel.hytale.procedurallib.supplier.IDoubleCoordinateHashSupplier;
class="kw">import com.hypixel.hytale.procedurallib.supplier.IDoubleRange;
class="kw">import com.hypixel.hytale.server.core.prefab.PrefabRotation;
class="kw">import com.hypixel.hytale.server.worldgen.SeedStringResource;
class="kw">import com.hypixel.hytale.server.worldgen.cave.CavePrefabPlacement;
class="kw">import com.hypixel.hytale.server.worldgen.cave.prefab.CavePrefabContainer;
class="kw">import com.hypixel.hytale.server.worldgen.loader.biome.BiomeMaskJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.context.ZoneFileContext;
class="kw">import com.hypixel.hytale.server.worldgen.loader.prefab.BlockPlacementMaskJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.util.condition.BlockMaskCondition;
class="kw">import java.nio.file.Path;
class="kw">import java.util.Arrays;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class CavePrefabConfigJsonLoader class="kw">extends JsonLoader<SeedStringResource, CavePrefabContainer.CavePrefabEntry.CavePrefabConfig> {
   class="kw">private class="kw">final ZoneFileContext zoneContext;

   class="kw">public CavePrefabConfigJsonLoader(@Nonnull SeedString<SeedStringResource> var1, Path var2, JsonElement var3, ZoneFileContext var4) {
      super(var1.append(".CavePrefabConfig"), var2, var3);
      this.zoneContext = var4;
   }

   @Nonnull
   class="kw">public CavePrefabContainer.CavePrefabEntry.CavePrefabConfig load() {
      class="kw">return new CavePrefabContainer.CavePrefabEntry.CavePrefabConfig(
         this.loadRotations(),
         this.loadPlacement(),
         this.loadBiomeMask(),
         this.loadBlockMask(),
         this.loadIterations(),
         this.loadDisplacementSupplier(),
         this.loadNoiseCondition(),
         this.loadHeightCondition()
      );
   }

   @Nonnull
   class="kw">protected PrefabRotation[] loadRotations() {
      PrefabRotation[] var1 = PrefabRotation.VALUES;
      if (this.has("Rotations")) {
         JsonElement var2 = this.get("Rotations");
         if (var2.isJsonArray()) {
            JsonArray var3 = var2.getAsJsonArray();
            if (var3.size() <= 0) {
               throw new IllegalArgumentException("Array for rotations must have at least one entry or left away to allow random rotation");
            }

            var1 = new PrefabRotation[var3.size()];

            for (int var4 = 0; var4 < var1.length; var4++) {
               String var5 = var3.get(var4).getAsString();

               try {
                  var1[var4] = PrefabRotation.valueOf(var5);
               } catch (Throwable var8) {
                  throw new Error(String.format(CavePrefabConfigJsonLoader.Constants.ERROR_ROTATIONS_UNKOWN, var5), var8);
               }
            }
         } else {
            if (!var2.isJsonPrimitive()) {
               throw new Error(String.format("\"Rotations\" is not an array nor a string, other types are not supported! Given: %s", var2));
            }

            var1 = new PrefabRotation[1];
            String var9 = var2.getAsString();

            try {
               var1[0] = PrefabRotation.valueOf(var9);
            } catch (Throwable var7) {
               throw new Error(String.format(CavePrefabConfigJsonLoader.Constants.ERROR_ROTATIONS_UNKOWN, var9), var7);
            }
         }
      }

      class="kw">return var1;
   }

   @Nonnull
   class="kw">protected CavePrefabPlacement loadPlacement() {
      CavePrefabPlacement var1 = CavePrefabPlacement.DEFAULT;
      if (this.has("Placement")) {
         var1 = CavePrefabPlacement.valueOf(this.get("Placement").getAsString());
      }

      class="kw">return var1;
   }

   @Nullable
   class="kw">protected IIntCondition loadBiomeMask() {
      IIntCondition var1 = ConstantIntCondition.DEFAULT_TRUE;
      if (this.has("BiomeMask")) {
         ZoneFileContext var2 = this.zoneContext.matchContext(this.json, "BiomeMask");
         var1 = new BiomeMaskJsonLoader(this.seed, this.dataFolder, this.get("BiomeMask"), "Prefab", var2).load();
      }

      class="kw">return var1;
   }

   @Nullable
   class="kw">protected BlockMaskCondition loadBlockMask() {
      BlockMaskCondition var1 = BlockMaskCondition.DEFAULT_TRUE;
      if (this.has("Mask")) {
         var1 = new BlockPlacementMaskJsonLoader(this.seed, this.dataFolder, this.getRaw("Mask")).load();
      }

      class="kw">return var1;
   }

   @Nullable
   class="kw">protected IDoubleRange loadIterations() {
      class="kw">return new DoubleRangeJsonLoader<>(this.seed, this.dataFolder, this.get("Iterations"), 5.0).load();
   }

   @Nonnull
   class="kw">protected IDoubleCoordinateHashSupplier loadDisplacementSupplier() {
      IDoubleCoordinateHashSupplier var1 = ConstantDoubleCoordinateHashSupplier.ZERO;
      if (this.has("Displacement")) {
         var1 = new DoubleRangeCoordinateHashSupplier(new DoubleRangeJsonLoader<>(this.seed, this.dataFolder, this.get("Displacement"), 0.0).load());
      }

      class="kw">return var1;
   }

   @Nonnull
   class="kw">protected ICoordinateCondition loadNoiseCondition() {
      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;
   }

   class="kw">public class="kw">interface Constants {
      String KEY_ROTATIONS = "Rotations";
      String KEY_PLACEMENT = "Placement";
      String KEY_BIOME_MASK = "BiomeMask";
      String KEY_BLOCK_MASK = "Mask";
      String KEY_ITERATIONS = "Iterations";
      String KEY_DISPLACEMENT = "Displacement";
      String KEY_NOISE_MASK = "NoiseMask";
      String KEY_HEIGHT_THRESHOLD = "HeightThreshold";
      String SEED_STRING_BIOME_MASK_TYPE = "Prefab";
      String ERROR_ROTATIONS_MUST_POSITIVE = "Array for rotations must have at least one entry or left away to allow random rotation";
      String ERROR_ROTATIONS_UNKOWN = "Could not find rotation \"%s\". Allowed: " + Arrays.toString(PrefabRotation.VALUES);
      String ERROR_ROTATIONS_UNKOWN_TYPE = "\"Rotations\" is not an array nor a string, other types are not supported! Given: %s";
   }
}