WeightedSizeFlockAsset class

Пакет: com.hypixel.hytale.server.flock.config

Файл: com/hypixel/hytale/server/flock/config/WeightedSizeFlockAsset.java

extends: FlockAsset

Поля (2)

МодификаторыТипИмя
final BuilderCodec<WeightedSizeFlockAsset> CODEC
int var1

Методы (2)

МодификаторыВозвратСигнатура
public int getMinSizeint getMinSize()
public double[] getSizeWeightsdouble[] getSizeWeights()

Исходный код

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

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.validation.Validators;
class="kw">import com.hypixel.hytale.codec.validation.validator.DoubleArrayValidator;
class="kw">import com.hypixel.hytale.math.random.RandomExtra;
class="kw">import java.util.Arrays;
class="kw">import javax.annotation.Nonnull;

class="kw">public class WeightedSizeFlockAsset class="kw">extends FlockAsset {
   class="kw">public class="kw">static class="kw">final BuilderCodec<WeightedSizeFlockAsset> CODEC = BuilderCodec.builder(
         WeightedSizeFlockAsset.class, WeightedSizeFlockAsset::new, FlockAsset.ABSTRACT_CODEC
      )
      .documentation("A flock definition where the initial random size is picked from a weighted map of sizes.")
      .<Integer>appendInherited(
         new KeyedCodec<>("MinSize", Codec.INTEGER), (var0, var1) -> var0.minSize = var1, var0 -> var0.minSize, (var0, var1) -> var0.minSize = var1.minSize
      )
      .documentation("The absolute minimum size to spawn the flock with.")
      .addValidator(Validators.nonNull())
      .addValidator(Validators.greaterThanOrEqual(0))
      .add()
      .<double[]>appendInherited(
         new KeyedCodec<>("SizeWeights", Codec.DOUBLE_ARRAY),
         (var0, var1) -> var0.sizeWeights = var1,
         var0 -> var0.sizeWeights,
         (var0, var1) -> var0.sizeWeights = var1.sizeWeights
      )
      .documentation(
         "An array of weights which is used in conjunction with the **MinSize** to determine the weighted size of the flock. The first value in the array corresponds to the weight of the minimum size and each successive value to a flock larger by one. e.g. If **MinSize** is 2 and **SizeWeights** is [ 25, 75 ], there will be a 25% chance that the flock will spawn with a size of 2 and a 75% chance that the flock will spawn with a size of 3. As these are weights, they do not need to add up to 100 and their percentage is relative to the total sum."
      )
      .addValidator(Validators.nonNull())
      .addValidator(new DoubleArrayValidator(Validators.greaterThan(0.0)))
      .add()
      .build();
   class="kw">protected int minSize;
   class="kw">protected double[] sizeWeights;

   class="kw">protected WeightedSizeFlockAsset() {
   }

   class="kw">public int getMinSize() {
      class="kw">return this.minSize;
   }

   class="kw">public double[] getSizeWeights() {
      class="kw">return this.sizeWeights;
   }

   @Override
   class="kw">public int getMinFlockSize() {
      class="kw">return this.minSize;
   }

   @Override
   class="kw">public int pickFlockSize() {
      int var1 = RandomExtra.pickWeightedIndex(this.sizeWeights);
      class="kw">return Math.max(this.minSize, 1) + var1;
   }

   @Nonnull
   @Override
   class="kw">public String toString() {
      class="kw">return "WeightedSizeFlockAsset{minSize=" + this.minSize + ", sizeWeights=" + Arrays.toString(this.sizeWeights) + "} " + super.toString();
   }
}