Constants interface

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

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

Поля (16)

МодификаторыТипИмя
String ERROR_LOADING_ENVIRONMENT
String ERROR_UNKNOWN_SHAPE_NAME
String ERROR_UNKOWN_CONSTRUCTOR_NODE_SHAPE
String KEY_CHILDREN
String KEY_CHILD_COUNT_BOUNDS
String KEY_COVER
String KEY_ENVIRONMENT
String KEY_FILLING
String KEY_FILLING_TYPES
String KEY_FILLING_WEIGHT
String KEY_HEIGHT_THRESHOLDS
String KEY_PREFABS
String KEY_PRIORITY
String KEY_TYPE
String SEED_CHILD_ENTRY_SUFFIX
String SEED_COVER_SUFFIX

Исходный код

Показать/скрыть
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.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.DefaultCoordinateCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.HeightThresholdCoordinateCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.ICoordinateCondition;
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.SeedString;
class="kw">import com.hypixel.hytale.procedurallib.supplier.IDoubleRange;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.environment.config.Environment;
class="kw">import com.hypixel.hytale.server.core.prefab.selection.mask.BlockPattern;
class="kw">import com.hypixel.hytale.server.worldgen.SeedStringResource;
class="kw">import com.hypixel.hytale.server.worldgen.cave.CaveNodeType;
class="kw">import com.hypixel.hytale.server.worldgen.cave.prefab.CavePrefabContainer;
class="kw">import com.hypixel.hytale.server.worldgen.cave.shape.CaveNodeShapeEnum;
class="kw">import com.hypixel.hytale.server.worldgen.loader.cave.shape.CylinderCaveNodeShapeGeneratorJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.cave.shape.DistortedCaveNodeShapeGeneratorJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.cave.shape.EllipsoidCaveNodeShapeGeneratorJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.cave.shape.EmptyLineCaveNodeShapeGeneratorJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.cave.shape.PipeCaveNodeShapeGeneratorJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.cave.shape.PrefabCaveNodeShapeGeneratorJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.context.CaveFileContext;
class="kw">import com.hypixel.hytale.server.worldgen.loader.context.ZoneFileContext;
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 java.nio.file.Path;
class="kw">import java.util.Locale;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class CaveNodeTypeJsonLoader class="kw">extends JsonLoader<SeedStringResource, CaveNodeType> {
   class="kw">protected class="kw">final String name;
   class="kw">protected class="kw">final CaveNodeTypeStorage storage;
   class="kw">protected class="kw">final ZoneFileContext zoneContext;
   class="kw">protected class="kw">final CaveFileContext caveContext;

   class="kw">public CaveNodeTypeJsonLoader(
      @Nonnull SeedString<SeedStringResource> var1, Path var2, JsonElement var3, String var4, CaveNodeTypeStorage var5, ZoneFileContext var6
   ) {
      super(var1.append(".CaveNodeType-" + var4), var2, var3);
      this.name = var4;
      this.storage = var5;
      this.zoneContext = var6;
      this.caveContext = new CaveFileContext(var4, var6);
   }

   @Nonnull
   class="kw">public CaveNodeType load() {
      CaveNodeType var1 = new CaveNodeType(
         this.name,
         this.loadPrefabs(),
         this.loadFillings(),
         this.loadShapeGenerator(),
         this.loadHeightCondition(),
         this.loadChildCountBounds(),
         this.loadCovers(),
         this.loadPriority(),
         this.loadEnvironment()
      );
      this.storage.add(this.name, var1);
      var1.setChildren(this.loadChildren());
      class="kw">return var1;
   }

   @Nonnull
   class="kw">protected CaveNodeType.CaveNodeChildEntry[] loadChildren() {
      try (ListPool.Resource var1 = CaveNodeType.CHILD_POOL.acquire()) {
         JsonElement var2 = this.get("Children");
         if (var2 != null) {
            if (var2.isJsonArray()) {
               JsonArray var3 = var2.getAsJsonArray();

               for (int var4 = 0; var4 < var3.size(); var4++) {
                  var1.add(
                     new CaveNodeChildEntryJsonLoader(
                           this.seed.append(String.format(".Child-%s", var4)), this.dataFolder, this.getOrLoad(var3.get(var4)), this.storage
                        )
                        .load()
                  );
               }
            } else {
               var1.add(
                  new CaveNodeChildEntryJsonLoader(this.seed.append(String.format(".Child-%s", 0)), this.dataFolder, this.getOrLoad(var2), this.storage).load()
               );
            }
         }

         class="kw">return var1.toArray();
      }
   }

   @Nullable
   class="kw">protected CavePrefabContainer loadPrefabs() {
      CavePrefabContainer var1 = null;
      if (this.has("Prefabs")) {
         ZoneFileContext var2 = this.zoneContext.matchContext(this.json, "Prefabs");
         CaveFileContext var3 = new CaveFileContext(this.name, this.caveContext.getPath(), var2);
         var1 = new CavePrefabContainerJsonLoader(this.seed, this.dataFolder, this.get("Prefabs"), var3).load();
      }

      class="kw">return var1;
   }

   @Nonnull
   class="kw">protected IWeightedMap<BlockFluidEntry> loadFillings() {
      WeightedMap.Builder var1 = WeightedMap.builder(BlockFluidEntry.EMPTY_ARRAY);
      JsonElement var2 = this.get("Filling");
      if (var2 == null || var2.isJsonNull()) {
         var1.put(new BlockFluidEntry(0, 0, 0), 1.0);
      } else if (var2.isJsonObject()) {
         JsonObject var3 = var2.getAsJsonObject();
         JsonArray var4 = var3.getAsJsonArray("Types");
         JsonArray var5 = var3.getAsJsonArray("Weight");
         ResolvedBlockArray var6 = new ResolvedBlockArrayJsonLoader(this.seed, this.dataFolder, var4).load();

         for (int var7 = 0; var7 < var4.size(); var7++) {
            var1.put(var6.getEntries()[var7], var5.get(var7).getAsDouble());
         }
      } else if (var2.isJsonArray()) {
         JsonArray var8 = var2.getAsJsonArray();
         ResolvedBlockArray var10 = new ResolvedBlockArrayJsonLoader(this.seed, this.dataFolder, var8).load();

         for (int var12 = 0; var12 < var8.size(); var12++) {
            var1.put(var10.getEntries()[var12], 1.0);
         }
      } else {
         BlockPattern.BlockEntry var9 = BlockPattern.BlockEntry.decode(var2.getAsString());
         int var11 = BlockType.getAssetMap().getIndex(var9.blockTypeKey());
         if (var11 == Integer.MIN_VALUE) {
            throw new IllegalArgumentException("Unknown key! " + var9);
         }

         var1.put(new BlockFluidEntry(var11, var9.rotation(), 0), 1.0);
      }

      class="kw">return var1.build();
   }

   @Nonnull
   class="kw">protected CaveNodeShapeEnum.CaveNodeShapeGenerator loadShapeGenerator() {
      if (this.has("Type")) {
         JsonElement var1 = this.get("Type");
         String var2 = var1.getAsString();

         try {
            class="kw">return class="kw">switch (CaveNodeShapeEnum.valueOf(var2.toUpperCase(Locale.ROOT))) {
               case PIPE -> new PipeCaveNodeShapeGeneratorJsonLoader(this.seed, this.dataFolder, this.json).load();
               case CYLINDER -> new CylinderCaveNodeShapeGeneratorJsonLoader(this.seed, this.dataFolder, this.json).load();
               case PREFAB -> new PrefabCaveNodeShapeGeneratorJsonLoader(this.seed, this.dataFolder, this.json).load();
               case ELLIPSOID -> new EllipsoidCaveNodeShapeGeneratorJsonLoader(this.seed, this.dataFolder, this.json).load();
               case EMPTY_LINE -> new EmptyLineCaveNodeShapeGeneratorJsonLoader(this.seed, this.dataFolder, this.json).load();
               case DISTORTED -> new DistortedCaveNodeShapeGeneratorJsonLoader(this.seed, this.dataFolder, this.json).load();
            };
         } catch (Throwable var4) {
            throw new Error(String.format("Could not find Shape by the name %s in Json: %s", var2, var1), var4);
         }
      } else {
         class="kw">return new PipeCaveNodeShapeGeneratorJsonLoader(this.seed, this.dataFolder, this.json).load();
      }
   }

   @Nonnull
   class="kw">protected ICoordinateCondition loadHeightCondition() {
      ICoordinateCondition var1 = DefaultCoordinateCondition.DEFAULT_TRUE;
      if (this.has("HeightThreshold")) {
         IHeightThresholdInterpreter var2 = new HeightThresholdInterpreterJsonLoader<>(this.seed, this.dataFolder, this.get("HeightThreshold"), 320).load();
         var1 = new HeightThresholdCoordinateCondition(var2);
      }

      class="kw">return var1;
   }

   @Nullable
   class="kw">protected IDoubleRange loadChildCountBounds() {
      IDoubleRange var1 = null;
      if (this.has("ChildCountBounds")) {
         var1 = new DoubleRangeJsonLoader<>(this.seed, this.dataFolder, this.get("ChildCountBounds")).load();
      }

      class="kw">return var1;
   }

   @Nonnull
   class="kw">protected CaveNodeType.CaveNodeCoverEntry[] loadCovers() {
      try (ListPool.Resource var1 = CaveNodeType.COVER_POOL.acquire()) {
         JsonElement var2 = this.get("Cover");
         if (var2 != null) {
            if (var2.isJsonArray()) {
               JsonArray var3 = var2.getAsJsonArray();

               for (int var4 = 0; var4 < var3.size(); var4++) {
                  var1.add(new CaveNodeCoverEntryJsonLoader(this.seed.append(String.format("-cover#%s", var4)), this.dataFolder, var3.get(var4)).load());
               }
            } else {
               var1.add(new CaveNodeCoverEntryJsonLoader(this.seed, this.dataFolder, var2).load());
            }
         }

         ModifyEvent.SeedGenerator var7 = new ModifyEvent.SeedGenerator<>(this.seed);
         ModifyEvent.dispatch(
            ModifyEvents.CaveCovers.class,
            new ModifyEvents.CaveCovers(
               this.seed, this.caveContext, var1, var2x -> new CaveNodeCoverEntryJsonLoader(var7.next(), this.dataFolder, this.loadFile(var2x)).load()
            )
         );
         class="kw">return var1.toArray();
      }
   }

   class="kw">protected int loadPriority() {
      int var1 = 0;
      if (this.has("Priority")) {
         var1 = this.get("Priority").getAsInt();
      }

      class="kw">return var1;
   }

   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;
   }

   class="kw">public class="kw">interface Constants {
      String KEY_CHILDREN = "Children";
      String KEY_PREFABS = "Prefabs";
      String KEY_FILLING = "Filling";
      String KEY_FILLING_TYPES = "Types";
      String KEY_FILLING_WEIGHT = "Weight";
      String KEY_TYPE = "Type";
      String KEY_HEIGHT_THRESHOLDS = "HeightThreshold";
      String KEY_CHILD_COUNT_BOUNDS = "ChildCountBounds";
      String KEY_COVER = "Cover";
      String KEY_PRIORITY = "Priority";
      String KEY_ENVIRONMENT = "Environment";
      String SEED_COVER_SUFFIX = "-cover#%s";
      String SEED_CHILD_ENTRY_SUFFIX = ".Child-%s";
      String ERROR_UNKNOWN_SHAPE_NAME = "Could not find Shape by the name %s in Json: %s";
      String ERROR_UNKOWN_CONSTRUCTOR_NODE_SHAPE = "Could not find Constructor for %s CaveNodeShape";
      String ERROR_LOADING_ENVIRONMENT = "Error while looking up environment \"%s\"!";
   }
}