Entry class

Пакет: com.hypixel.hytale.builtin.worldgen.modifier.content.prefab

Файл: com/hypixel/hytale/builtin/worldgen/modifier/content/prefab/PrefabContent.java

Поля (5)

МодификаторыТипИмя
public static final ArrayCodec<PrefabContent.Entry> ARRAY_CODEC
public static final BuilderCodec<PrefabContent.Entry> CODEC
public static final PrefabContent.Entry[] EMPTY_ARRAY
private String path
private double weight

Исходный код

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

class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.content.Content;
class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.content.common.BlockMask;
class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.content.common.HeightMask;
class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.content.common.NoiseMask;
class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.event.ModifyEvent;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.codecs.EnumCodec;
class="kw">import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
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.json.SeedString;
class="kw">import com.hypixel.hytale.server.core.asset.type.environment.config.Environment;
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.WorldGenPrefabLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.WorldGenPrefabSupplier;
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 javax.annotation.Nonnull;

class="kw">public class="kw">abstract class PrefabContent class="kw">implements Content {
   class="kw">public class="kw">static class="kw">final BuilderCodec<PrefabContent> CODEC = BuilderCodec.abstractBuilder(PrefabContent.class)
      .append(new KeyedCodec<>("Prefabs", PrefabContent.Entry.ARRAY_CODEC), (var0, var1) -> var0.prefabs = var1, var0 -> var0.prefabs)
      .documentation("Weighted list of prefab paths to randomly choose from")
      .add()
      .<BlockMask>append(new KeyedCodec<>("BlockMask", BlockMask.CODEC), (var0, var1) -> var0.blockMask = var1, var0 -> var0.blockMask)
      .documentation("The types of blocks that the prefab's blocks can replace")
      .add()
      .<NoiseMask>append(new KeyedCodec<>("NoiseMask", NoiseMask.CODEC), (var0, var1) -> var0.noiseMask = var1, var0 -> var0.noiseMask)
      .documentation("The horizontal noise mask for the prefab placement position")
      .add()
      .<HeightMask>append(new KeyedCodec<>("HeightMask", HeightMask.CODEC), (var0, var1) -> var0.heightMask = var1, var0 -> var0.heightMask)
      .documentation("The height range mask for the prefab placement position")
      .add()
      .<Integer>append(new KeyedCodec<>("OffsetY", Codec.INTEGER), (var0, var1) -> var0.offsetY = var1, var0 -> var0.offsetY)
      .documentation("The vertical offset for the prefab placement position")
      .add()
      .<PrefabRotation[]>append(
         new KeyedCodec<>("Rotations", new ArrayCodec<>(new EnumCodec<>(PrefabRotation.class), PrefabRotation[]::new)),
         (var0, var1) -> var0.rotations = var1,
         var0 -> var0.rotations
      )
      .documentation("The rotation directions that the prefab can be randomly placed in")
      .add()
      .<Environment>append(new KeyedCodec<>("Environment", Environment.CODEC), (var0, var1) -> var0.environment = var1, var0 -> var0.environment)
      .documentation("The environment to place where the prefab is placed")
      .add()
      .afterDecode(PrefabContent::rebuild)
      .build();
   class="kw">protected PrefabContent.Entry[] prefabs = PrefabContent.Entry.EMPTY_ARRAY;
   class="kw">protected NoiseMask noiseMask = NoiseMask.DEFAULT;
   class="kw">protected HeightMask heightMask = HeightMask.DEFAULT;
   class="kw">protected BlockMask blockMask = BlockMask.REPLACE_ANY;
   class="kw">protected int offsetY = 0;
   class="kw">protected PrefabRotation[] rotations = PrefabRotation.VALUES;
   class="kw">protected Environment environment = Environment.UNKNOWN;
   class="kw">protected class="kw">transient ICoordinateDoubleSupplier offset = ConstantCoordinateDoubleSupplier.DEFAULT_ZERO;

   class="kw">public PrefabContent() {
   }

   @Override
   class="kw">public Content.Type type() {
      class="kw">return Content.Type.BIOME_PREFAB;
   }

   @Override
   class="kw">public class="kw">abstract <T> void applyTo(ModifyEvent<T> var1) class="kw">throws Exception;

   class="kw">protected void rebuild() {
      this.offset = new ConstantCoordinateDoubleSupplier(this.offsetY);
   }

   class="kw">protected IWeightedMap<WorldGenPrefabSupplier> buildPrefabs(@Nonnull SeedString<SeedStringResource> var1) {
      WorldGenPrefabLoader var2 = var1.get().getLoader();
      WeightedMap.Builder var3 = WeightedMap.builder(WorldGenPrefabSupplier.EMPTY_ARRAY);

      for (PrefabContent.Entry var7 : this.prefabs) {
         WorldGenPrefabSupplier[] var8 = var2.get(var7.path);
         if (var8 != null) {
            for (WorldGenPrefabSupplier var12 : var8) {
               var3.put(var12, var7.weight);
            }
         }
      }

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

   class="kw">public class="kw">static class Entry {
      class="kw">public class="kw">static class="kw">final BuilderCodec<PrefabContent.Entry> CODEC = BuilderCodec.builder(PrefabContent.Entry.class, PrefabContent.Entry::new)
         .append(new KeyedCodec<>("Path", Codec.STRING), (var0, var1) -> var0.path = var1, var0 -> var0.path)
         .documentation("The path of the prefab")
         .add()
         .<Double>append(new KeyedCodec<>("Weight", Codec.DOUBLE), (var0, var1) -> var0.weight = var1, var0 -> var0.weight)
         .addValidator(Validators.range(0.0, 100.0))
         .documentation("The random chance of the path being chosen")
         .add()
         .build();
      class="kw">public class="kw">static class="kw">final ArrayCodec<PrefabContent.Entry> ARRAY_CODEC = new ArrayCodec<>(CODEC, PrefabContent.Entry[]::new);
      class="kw">public class="kw">static class="kw">final PrefabContent.Entry[] EMPTY_ARRAY = new PrefabContent.Entry[0];
      class="kw">private String path = "";
      class="kw">private double weight = 1.0;

      class="kw">public Entry() {
      }
   }
}