Constants interface

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

Файл: com/hypixel/hytale/server/worldgen/loader/prefab/PrefabPatternGeneratorJsonLoader.java

Поля (20)

МодификаторыТипИмя
Integer DEFAULT_EXCLUSION_RADIUS
Integer DEFAULT_MAX_SIZE
Boolean DEFAULT_SUBMERGE
String ERROR_DEEP_SEARCH
String ERROR_NO_GRID_GENERATOR
String KEY_BASE_CHECKS
String KEY_CATEGORY
String KEY_DEEP_SEARCH
String KEY_DISPLACEMENT
String KEY_EXCLUSION_RADIUS
String KEY_FIT_HEIGHTMAP
String KEY_GRID_GENERATOR
String KEY_HEIGHT_THRESHOLD
String KEY_MASK
String KEY_MAX_SIZE
String KEY_NOISE_MASK
String KEY_ON_WATER
String KEY_PARENT
String KEY_ROTATIONS
String KEY_SUBMERGE

Исходный код

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

class="kw">import com.google.gson.JsonArray;
class="kw">import com.google.gson.JsonElement;
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.condition.IHeightThresholdInterpreter;
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.PointGeneratorJsonLoader;
class="kw">import com.hypixel.hytale.procedurallib.json.SeedString;
class="kw">import com.hypixel.hytale.procedurallib.logic.point.IPointGenerator;
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.loader.context.FileLoadingContext;
class="kw">import com.hypixel.hytale.server.worldgen.loader.util.ResolvedBlockArrayJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.prefab.PrefabBaseCheck;
class="kw">import com.hypixel.hytale.server.worldgen.prefab.PrefabCategory;
class="kw">import com.hypixel.hytale.server.worldgen.prefab.PrefabPatternGenerator;
class="kw">import com.hypixel.hytale.server.worldgen.util.LogUtil;
class="kw">import com.hypixel.hytale.server.worldgen.util.ResolvedBlockArray;
class="kw">import com.hypixel.hytale.server.worldgen.util.condition.BlockMaskCondition;
class="kw">import com.hypixel.hytale.server.worldgen.util.condition.HashSetBlockFluidCondition;
class="kw">import com.hypixel.hytale.server.worldgen.util.function.ConstantCoordinateDoubleSupplier;
class="kw">import com.hypixel.hytale.server.worldgen.util.function.ICoordinateDoubleSupplier;
class="kw">import com.hypixel.hytale.server.worldgen.util.function.RandomCoordinateDoubleSupplier;
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 java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class PrefabPatternGeneratorJsonLoader class="kw">extends JsonLoader<SeedStringResource, PrefabPatternGenerator> {
   class="kw">private class="kw">final FileLoadingContext context;

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

   @Nonnull
   class="kw">public PrefabPatternGenerator load() {
      IHeightThresholdInterpreter var1 = this.loadHeightThresholds();
      class="kw">return new PrefabPatternGenerator(
         this.seed.hashCode(),
         this.loadCategory(),
         this.loadPattern(),
         this.loadHeightCondition(var1),
         var1,
         this.loadMask(),
         this.loadMapCondition(),
         this.loadParent(),
         this.loadRotations(),
         this.loadDisplacement(),
         this.loadFitHeightmap(),
         this.loadOnWater(),
         this.loadDeepSearch(var1),
         this.loadSubmerge(),
         this.loadMaxSize(),
         this.loadExclusionRadius(),
         this.loadBaseChecks()
      );
   }

   @Nullable
   class="kw">protected IPointGenerator loadPattern() {
      if (!this.has("GridGenerator")) {
         throw new IllegalArgumentException("Could not find point generator to place prefabs at! Keyword: GridGenerator");
      } else {
         class="kw">return new PointGeneratorJsonLoader<>(this.seed, this.dataFolder, this.get("GridGenerator")).load();
      }
   }

   class="kw">protected PrefabCategory loadCategory() {
      String var1 = this.mustGetString("Category", "");
      if (var1.isEmpty()) {
         class="kw">return PrefabCategory.NONE;
      } else if (!this.context.getPrefabCategories().contains(var1)) {
         LogUtil.getLogger().at(Level.WARNING).log("Could not find prefab category: %s, defaulting to None", var1);
         class="kw">return PrefabCategory.NONE;
      } else {
         class="kw">return this.context.getPrefabCategories().get(var1);
      }
   }

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

   @Nullable
   class="kw">protected IHeightThresholdInterpreter loadHeightThresholds() {
      IHeightThresholdInterpreter var1 = null;
      if (this.has("HeightThreshold")) {
         var1 = new HeightThresholdInterpreterJsonLoader<>(this.seed, this.dataFolder, this.get("HeightThreshold"), 320).load();
      }

      class="kw">return var1;
   }

   @Nonnull
   class="kw">protected ICoordinateRndCondition loadHeightCondition(@Nullable IHeightThresholdInterpreter var1) {
      ICoordinateRndCondition var2 = DefaultCoordinateRndCondition.DEFAULT_TRUE;
      if (var1 != null) {
         var2 = new HeightCondition(var1);
      }

      class="kw">return var2;
   }

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

   @Nullable
   class="kw">protected BlockMaskCondition loadMask() {
      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 PrefabRotation[] loadRotations() {
      PrefabRotation[] var1 = null;
      if (this.has("Rotations")) {
         var1 = loadRotations(this.get("Rotations"));
      }

      class="kw">return var1;
   }

   @Nonnull
   class="kw">protected ICoordinateDoubleSupplier loadDisplacement() {
      ICoordinateDoubleSupplier var1 = ConstantCoordinateDoubleSupplier.DEFAULT_ZERO;
      if (this.has("Displacement")) {
         var1 = new RandomCoordinateDoubleSupplier(new DoubleRangeJsonLoader<>(this.seed, this.dataFolder, this.get("Displacement"), 0.0).load());
      }

      class="kw">return var1;
   }

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

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

   class="kw">protected boolean loadDeepSearch(@Nonnull IHeightThresholdInterpreter var1) {
      boolean var2 = this.has("DeepSearch") && this.get("DeepSearch").getAsBoolean();
      if (var2 && var1 == null) {
         throw new IllegalArgumentException("DeepSearch is enabled but HeightThreshold is not set!");
      } else {
         class="kw">return var2;
      }
   }

   class="kw">protected boolean loadSubmerge() {
      class="kw">return this.mustGetBool("Submerge", PrefabPatternGeneratorJsonLoader.Constants.DEFAULT_SUBMERGE);
   }

   class="kw">protected int loadMaxSize() {
      class="kw">return this.mustGetNumber("MaxSize", PrefabPatternGeneratorJsonLoader.Constants.DEFAULT_MAX_SIZE).intValue();
   }

   class="kw">protected int loadExclusionRadius() {
      class="kw">return this.mustGetNumber("ExclusionRadius", PrefabPatternGeneratorJsonLoader.Constants.DEFAULT_EXCLUSION_RADIUS).intValue();
   }

   @Nonnull
   class="kw">protected PrefabBaseCheck[] loadBaseChecks() {
      class="kw">return PrefabBaseCheck.Loader.loadAll(this, this.get("BaseChecks"));
   }

   @Nullable
   class="kw">public class="kw">static PrefabRotation[] loadRotations(@Nullable JsonElement var0) {
      if (var0 == null) {
         class="kw">return null;
      }

      PrefabRotation[] var1 = null;
      if (var0.isJsonArray()) {
         JsonArray var2 = var0.getAsJsonArray();
         if (var2.size() <= 0) {
            throw new IllegalArgumentException("Array for rotations must be greater than 0 or left away to allow random rotation.");
         }

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

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

            try {
               var1[var3] = PrefabRotation.valueOf(var4);
            } catch (Throwable var7) {
               throw new Error("Could not find rotation \"" + var4 + "\". Allowed: " + Arrays.toString(PrefabRotation.VALUES), var7);
            }
         }
      } else {
         if (!var0.isJsonPrimitive()) {
            throw new IllegalArgumentException("rotations is not an array nor a string, other types are not supported! Given: " + var0);
         }

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

         try {
            var1[0] = PrefabRotation.valueOf(var9);
         } catch (Throwable var6) {
            throw new Error("Could not find rotation \"" + var9 + "\". Allowed: " + Arrays.toString(PrefabRotation.VALUES), var6);
         }
      }

      class="kw">return var1;
   }

   class="kw">public class="kw">interface Constants {
      String KEY_GRID_GENERATOR = "GridGenerator";
      String KEY_PARENT = "Parent";
      String KEY_HEIGHT_THRESHOLD = "HeightThreshold";
      String KEY_NOISE_MASK = "NoiseMask";
      String KEY_MASK = "Mask";
      String KEY_ROTATIONS = "Rotations";
      String KEY_DISPLACEMENT = "Displacement";
      String KEY_FIT_HEIGHTMAP = "FitHeightmap";
      String KEY_ON_WATER = "OnWater";
      String KEY_DEEP_SEARCH = "DeepSearch";
      String KEY_SUBMERGE = "Submerge";
      String KEY_MAX_SIZE = "MaxSize";
      String KEY_EXCLUSION_RADIUS = "ExclusionRadius";
      String KEY_BASE_CHECKS = "BaseChecks";
      String KEY_CATEGORY = "Category";
      String ERROR_NO_GRID_GENERATOR = "Could not find point generator to place prefabs at! Keyword: GridGenerator";
      String ERROR_DEEP_SEARCH = "DeepSearch is enabled but HeightThreshold is not set!";
      Boolean DEFAULT_SUBMERGE = Boolean.FALSE;
      Integer DEFAULT_MAX_SIZE = 5;
      Integer DEFAULT_EXCLUSION_RADIUS = 0;
   }
}