LoopRandomOperation class

Пакет: com.hypixel.hytale.builtin.buildertools.scriptedbrushes.operations.sequential.flowcontrol.loops

Файл: com/hypixel/hytale/builtin/buildertools/scriptedbrushes/operations/sequential/flowcontrol/loops/LoopRandomOperation.java

extends: SequenceBrushOperation

Поля (3)

МодификаторыТипИмя
final int MAX_REPETITIONS
return
int var5

Методы (5)

МодификаторыВозвратСигнатура
if if(this.repetitionsRemaining == -1)
if if(var5 > 100)
if if(this.repetitionsRemaining == 0)
private int randomlyChooseRepetitionsAmountint randomlyChooseRepetitionsAmount()
abstract super super("Loop Operations Random Amount", "Loop the execution of instructions a random amount of times", false)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.buildertools.scriptedbrushes.operations.sequential.flowcontrol.loops;

class="kw">import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.BrushConfig;
class="kw">import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.BrushConfigCommandExecutor;
class="kw">import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.operations.system.SequenceBrushOperation;
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.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.server.core.codec.PairCodec;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import it.unimi.dsi.fastutil.Pair;
class="kw">import java.util.concurrent.ThreadLocalRandom;
class="kw">import javax.annotation.Nonnull;

class="kw">public class LoopRandomOperation class="kw">extends SequenceBrushOperation {
   class="kw">public class="kw">static class="kw">final int MAX_REPETITIONS = 100;
   class="kw">public class="kw">static class="kw">final int IDLE_STATE = -1;
   class="kw">public class="kw">static class="kw">final BuilderCodec<LoopRandomOperation> CODEC = BuilderCodec.builder(LoopRandomOperation.class, LoopRandomOperation::new)
      .append(new KeyedCodec<>("StoredIndexName", Codec.STRING), (var0, var1) -> var0.indexNameArg = var1, var0 -> var0.indexNameArg)
      .documentation("The name of the previously stored index to begin the loop at. Note: This can only be an index previous to the current.")
      .add()
      .<PairCodec.IntegerPair>append(
         new KeyedCodec<>("RangeOfAdditionalRepetitions", PairCodec.IntegerPair.CODEC),
         (var0, var1) -> var0.repetitionsArg = var1.toPair(),
         var0 -> PairCodec.IntegerPair.fromPair(var0.repetitionsArg)
      )
      .documentation(
         "The minimum and maximum of a range, randomly choosing the amount of additional times to repeat the loop after the initial, normal execution"
      )
      .add()
      .documentation("Loop the execution of instructions a random amount of times")
      .build();
   @Nonnull
   class="kw">public String indexNameArg = "Undefined";
   @Nonnull
   class="kw">public Pair<Integer, Integer> repetitionsArg = Pair.of(1, 1);
   class="kw">private int repetitionsRemaining = -1;

   class="kw">public LoopRandomOperation() {
      super("Loop Operations Random Amount", "Loop the execution of instructions a random amount of times", false);
   }

   @Override
   class="kw">public void resetInternalState() {
      this.repetitionsRemaining = -1;
   }

   @Override
   class="kw">public void modifyBrushConfig(
      @Nonnull Ref<EntityStore> var1, @Nonnull BrushConfig var2, @Nonnull BrushConfigCommandExecutor var3, @Nonnull ComponentAccessor<EntityStore> var4
   ) {
      if (this.repetitionsRemaining == -1) {
         int var5 = this.randomlyChooseRepetitionsAmount();
         if (var5 > 100) {
            var2.setErrorFlag("Cannot have more than 100 repetitions");
            class="kw">return;
         }

         this.repetitionsRemaining = var5;
      }

      if (this.repetitionsRemaining == 0) {
         this.repetitionsRemaining = -1;
      } else {
         this.repetitionsRemaining--;
         var3.loadOperatingIndex(this.indexNameArg, false);
      }
   }

   class="kw">private int randomlyChooseRepetitionsAmount() {
      class="kw">return ((Integer)this.repetitionsArg.left()).equals(this.repetitionsArg.right())
         ? (Integer)this.repetitionsArg.left()
         : ThreadLocalRandom.current().nextInt((Integer)this.repetitionsArg.left(), (Integer)this.repetitionsArg.right() + 1);
   }
}