VerticalDirection enum

Пакет: com.hypixel.hytale.builtin.adventure.farming.config.stages.spread

Файл: com/hypixel/hytale/builtin/adventure/farming/config/stages/spread/DirectionalGrowthBehaviour.java

Поля (1)

МодификаторыТипИмя
private final int value

Методы (2)

МодификаторыВозвратСигнатура
abstract UPWARDS UPWARDS(1)
public int getValuepublic int getValue()

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.adventure.farming.config.stages.spread;

class="kw">import com.hypixel.hytale.builtin.adventure.farming.states.FarmingBlock;
class="kw">import com.hypixel.hytale.builtin.blockphysics.BlockPhysicsSystems;
class="kw">import com.hypixel.hytale.builtin.blockphysics.BlockPhysicsUtil;
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.validation.Validators;
class="kw">import com.hypixel.hytale.common.map.IWeightedElement;
class="kw">import com.hypixel.hytale.common.map.IWeightedMap;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.math.range.IntRange;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.math.util.FastRandom;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.math.util.TrigMathUtil;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.blocktype.component.BlockPhysics;
class="kw">import com.hypixel.hytale.server.core.codec.WeightedMapCodec;
class="kw">import com.hypixel.hytale.server.core.modules.block.BlockModule;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.BlockChunk;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.BlockOperations;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.FluidSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import javax.annotation.Nonnull;

class="kw">public class DirectionalGrowthBehaviour class="kw">extends SpreadGrowthBehaviour {
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<DirectionalGrowthBehaviour> CODEC = BuilderCodec.builder(
         DirectionalGrowthBehaviour.class, DirectionalGrowthBehaviour::new, BASE_CODEC
      )
      .append(
         new KeyedCodec<>(
            "GrowthBlockTypes", new WeightedMapCodec<>(DirectionalGrowthBehaviour.BlockTypeWeight.CODEC, new DirectionalGrowthBehaviour.BlockTypeWeight[0])
         ),
         (var0, var1) -> var0.blockTypes = var1,
         var0 -> var0.blockTypes
      )
      .documentation("Defines a map of the possible BlockType to spread.")
      .addValidator(Validators.nonNull())
      .add()
      .<IntRange>append(new KeyedCodec<>("Horizontal", IntRange.CODEC), (var0, var1) -> var0.horizontalRange = var1, var0 -> var0.horizontalRange)
      .documentation("Defines if the spread can happen horizontally. The range must be set with positive integers.")
      .add()
      .<IntRange>append(new KeyedCodec<>("Vertical", IntRange.CODEC), (var0, var1) -> var0.verticalRange = var1, var0 -> var0.verticalRange)
      .documentation("Defines if the spread can happen vertically. The range must be set with positive integers.")
      .add()
      .<DirectionalGrowthBehaviour.VerticalDirection>append(
         new KeyedCodec<>("VerticalDirection", new EnumCodec<>(DirectionalGrowthBehaviour.VerticalDirection.class)),
         (var0, var1) -> var0.verticalDirection = var1,
         var0 -> var0.verticalDirection
      )
      .documentation("Defines in which direction the vertical spread should happen. Possible values are: 'Upwards' and 'Downwards', class="kw">default value: 'Upwards'.")
      .addValidator(Validators.nonNull())
      .add()
      .build();
   class="kw">private class="kw">static class="kw">final int PLACE_BLOCK_TRIES = 100;
   class="kw">protected IWeightedMap<DirectionalGrowthBehaviour.BlockTypeWeight> blockTypes;
   class="kw">protected IntRange horizontalRange;
   class="kw">protected IntRange verticalRange;
   class="kw">protected DirectionalGrowthBehaviour.VerticalDirection verticalDirection = DirectionalGrowthBehaviour.VerticalDirection.BOTH;

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

   class="kw">public IWeightedMap<DirectionalGrowthBehaviour.BlockTypeWeight> getBlockTypes() {
      class="kw">return this.blockTypes;
   }

   class="kw">public IntRange getHorizontalRange() {
      class="kw">return this.horizontalRange;
   }

   class="kw">public IntRange getVerticalRange() {
      class="kw">return this.verticalRange;
   }

   class="kw">public DirectionalGrowthBehaviour.VerticalDirection getVerticalDirection() {
      class="kw">return this.verticalDirection;
   }

   @Override
   class="kw">public void execute(
      @Nonnull ComponentAccessor<ChunkStore> var1, @Nonnull Ref<ChunkStore> var2, @Nonnull Ref<ChunkStore> var3, int var4, int var5, int var6, float var7
   ) {
      int var8 = 0;
      int var9 = 0;
      FastRandom var10 = new FastRandom();
      DirectionalGrowthBehaviour.BlockTypeWeight var11 = this.blockTypes.get(var10);
      if (var11 != null) {
         String var12 = var11.getBlockTypeKey();
         World var13 = var1.getExternalData().getWorld();
         ChunkStore var14 = var13.getChunkStore();
         Store var15 = var14.getStore();

         for (int var16 = 0; var16 < 100; var16++) {
            if (this.horizontalRange != null) {
               double var17 = (float) (Math.PI * 2) * var10.nextFloat();
               int var19 = this.horizontalRange.getInt(var10.nextFloat());
               var8 = MathUtil.fastRound(var19 * TrigMathUtil.cos(var17));
               var9 = MathUtil.fastRound(var19 * TrigMathUtil.sin(var17));
            }

            int var24 = var4 + var8;
            int var18 = var5;
            int var26 = var6 + var9;
            int var20 = ChunkUtil.chunkCoordinate(var24);
            int var21 = ChunkUtil.chunkCoordinate(var26);
            Ref var22 = var14.getChunkReference(ChunkUtil.indexChunk(var20, var21));
            if (var22 != null && var22.isValid()) {
               if (this.verticalRange != null) {
                  int var23 = class="kw">switch (this.verticalDirection) {
                     case DOWNWARDS, UPWARDS -> this.verticalDirection.getValue();
                     case BOTH -> var10.nextBoolean() ? 1 : -1;
                  };
                  var18 += this.verticalRange.getInt(var10.nextFloat()) * var23;
               } else {
                  BlockChunk var27 = var15.getComponent(var22, BlockChunk.getComponentType());
                  if (var27 == null) {
                     class="kw">continue;
                  }

                  var18 = var27.getHeight(var24, var26) + 1;
               }

               if (this.tryPlaceBlock(var13, var24, var18, var26, var12, 0)) {
                  int var28 = var18;
                  var13.execute(() -> {
                     Ref var8 = var14.getChunkSectionReferenceAtBlock(var24, var28, var26);
                     if (var8 != null && var8.isValid()) {
                        BlockSection var9 = var15.getComponent(var8, BlockSection.getComponentType());
                        if (var9 != null) {
                           BlockType var10 = BlockType.getAssetMap().getAsset(var12);
                           if (var10 != null) {
                              if (BlockOperations.testPlaceBlock(var15, var9, var24, var28, var26, var10, 0)) {
                                 BlockOperations.setBlock(var14, var8, var24, var28, var26, BlockType.getAssetMap().getIndex(var12), var10, 0, 0, 0);
                                 decaySpread(var1, var8, var24, var28, var26, var7);
                              }
                           }
                        }
                     }
                  });
                  class="kw">return;
               }
            }
         }
      }
   }

   class="kw">private class="kw">static void decaySpread(@Nonnull ComponentAccessor<ChunkStore> var0, @Nonnull Ref<ChunkStore> var1, int var2, int var3, int var4, float var5) {
      Ref var6 = BlockModule.getBlockEntity(var0, var1, var2, var3, var4);
      if (var6 != null) {
         FarmingBlock var7 = var0.getComponent(var6, FarmingBlock.getComponentType());
         if (var7 != null) {
            var7.setSpreadRate(var5);
         }
      }
   }

   class="kw">private boolean tryPlaceBlock(@Nonnull World var1, int var2, int var3, int var4, @Nonnull String var5, int var6) {
      ChunkStore var7 = var1.getChunkStore();
      Ref var8 = var7.getChunkSectionReferenceAtBlock(var2, var3, var4);
      if (var8 != null && var8.isValid()) {
         Store var9 = var7.getStore();
         BlockSection var10 = var9.getComponent(var8, BlockSection.getComponentType());
         assert var10 != null;
         if (var10.get(var2, var3, var4) != 0) {
            class="kw">return false;
         }

         if (!this.validatePosition(var1, var2, var3, var4)) {
            class="kw">return false;
         }

         BlockType var11 = BlockType.getAssetMap().getAsset(var5);
         if (var11 == null) {
            class="kw">return false;
         }

         if (!BlockOperations.testPlaceBlock(var9, var10, var2, var3, var4, var11, var6)) {
            class="kw">return false;
         }

         BlockPhysics var12 = var9.getComponent(var8, BlockPhysics.getComponentType());
         assert var12 != null;
         FluidSection var13 = var9.getComponent(var8, FluidSection.getComponentType());
         assert var13 != null;
         int var14 = var10.getFiller(var2, var3, var4);
         int var15 = ChunkUtil.chunkCoordinate(var2);
         int var16 = ChunkUtil.chunkCoordinate(var3);
         int var17 = ChunkUtil.chunkCoordinate(var4);
         BlockPhysicsSystems.CachedAccessor var18 = BlockPhysicsSystems.CachedAccessor.of(var9, var8, var10, var12, var13, var15, var16, var17, 14);
         class="kw">return BlockPhysicsUtil.testBlockPhysics(var18, var10, var12, var13, var2, var3, var4, var11, var6, var14) != 0;
      } else {
         class="kw">return false;
      }
   }

   @Nonnull
   @Override
   class="kw">public String toString() {
      class="kw">return "DirectionalGrowthBehaviour{blockTypes="
         + this.blockTypes
         + ", horizontalRange="
         + this.horizontalRange
         + ", verticalRange="
         + this.verticalRange
         + ", verticalDirection="
         + this.verticalDirection
         + "} "
         + super.toString();
   }

   class="kw">public class="kw">static class BlockTypeWeight class="kw">implements IWeightedElement {
      @Nonnull
      class="kw">public class="kw">static class="kw">final BuilderCodec<DirectionalGrowthBehaviour.BlockTypeWeight> CODEC = BuilderCodec.builder(
            DirectionalGrowthBehaviour.BlockTypeWeight.class, DirectionalGrowthBehaviour.BlockTypeWeight::new
         )
         .append(new KeyedCodec<>("Weight", Codec.DOUBLE), (var0, var1) -> var0.weight = var1, var0 -> var0.weight)
         .documentation("Defines the probability to have this entry.")
         .addValidator(Validators.greaterThan(0.0))
         .add()
         .<String>append(new KeyedCodec<>("BlockType", Codec.STRING), (var0, var1) -> var0.blockTypeKey = var1, var0 -> var0.blockTypeKey)
         .documentation("Defines the BlockType that'll be spread")
         .addValidator(Validators.nonNull())
         .add()
         .build();
      class="kw">protected double weight = 1.0;
      class="kw">protected String blockTypeKey;

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

      @Override
      class="kw">public double getWeight() {
         class="kw">return this.weight;
      }

      class="kw">public String getBlockTypeKey() {
         class="kw">return this.blockTypeKey;
      }

      @Nonnull
      @Override
      class="kw">public String toString() {
         class="kw">return "BlockTypeWeight{weight=" + this.weight + ", blockTypeKey=" + this.blockTypeKey + "}";
      }
   }

   class="kw">private enum VerticalDirection {
      DOWNWARDS(-1),
      BOTH(0),
      UPWARDS(1);

      class="kw">private class="kw">final int value;

      VerticalDirection(int nullxx) {
         this.value = nullxx;
      }

      class="kw">public int getValue() {
         class="kw">return this.value;
      }
   }
}