SpreadToProcedure class

Пакет: com.hypixel.hytale.builtin.randomtick.procedures

Файл: com/hypixel/hytale/builtin/randomtick/procedures/SpreadToProcedure.java

implements: RandomTickProcedure

Поля (45)

МодификаторыТипИмя
final BuilderCodec<SpreadToProcedure> CODEC
continue
continue
continue
continue
continue
continue
continue
continue
return
return
WorldTimeResource var10
double var11
int[] var13
Ref var14
BlockSection var15
int var16
FluidSection var17
int var18
BlockType var19
int var20
int var21
int var26
int var27
int var28
BlockSection var29
var29
Ref var30
int var31
int var32
var32
var32
Ref var33
BlockSection var34
Fluid var35
int var36
int var37
Fluid var38
int var39
int var41
Ref var42
BlockType var43
FluidSection var44
int var45
IntSet var9

Методы (24)

МодификаторыВозвратСигнатура
private boolean fluidAllowedAboveboolean fluidAllowedAbove(int[] var1, int var2)
for for(int var40 = this.minY; var40 <= this.maxY; var40++)
for for(Vector3i var25 : this.spreadDirections)
for for(int var6 : var1)
for for(int var1 = 0; var1 < this.allowedAboveFluidIds.length; var1++)
if if(var14 != null)
if if(var15 != null)
if if(var17 != null)
if if(this.revertBlock != null)
if if(var20 != Integer.MIN_VALUE)
if if(var13 != null)
if if(var39 >= this.requiredLightLevel)
if if(var30 == null)
if if(var29 == null)
if if(this.requireEmptyAboveTarget)
if if(var33 == null)
if if(var34 == null)
if if(var13 != null)
if if(var42 == null)
if if(var44 == null)
if if(var1 == null)
if if(var6 == var2)
if if(this.allowedAboveFluidIndexes != null && this.allowedAboveFluidIndexes[0] == Integer.MIN_VALUE)
if if(this.allowedAboveFluidIds == null)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.randomtick.procedures;

class="kw">import com.hypixel.hytale.assetstore.AssetRegistry;
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.array.ArrayCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.math.vector.Vector3iUtil;
class="kw">import com.hypixel.hytale.protocol.BlockMaterial;
class="kw">import com.hypixel.hytale.protocol.DrawType;
class="kw">import com.hypixel.hytale.protocol.Opacity;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktick.config.RandomTickProcedure;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.fluid.Fluid;
class="kw">import com.hypixel.hytale.server.core.modules.time.WorldTimeResource;
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 it.unimi.dsi.fastutil.ints.IntSet;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3i;

class="kw">public class SpreadToProcedure class="kw">implements RandomTickProcedure {
   class="kw">public class="kw">static class="kw">final BuilderCodec<SpreadToProcedure> CODEC = BuilderCodec.builder(SpreadToProcedure.class, SpreadToProcedure::new)
      .appendInherited(
         new KeyedCodec<>("SpreadDirections", new ArrayCodec<>(Vector3iUtil.CODEC, Vector3i[]::new)),
         (var0, var1) -> var0.spreadDirections = var1,
         var0 -> var0.spreadDirections,
         (var0, var1) -> var0.spreadDirections = var1.spreadDirections
      )
      .documentation("The directions this block can spread in.")
      .addValidator(Validators.nonNull())
      .add()
      .<Integer>appendInherited(
         new KeyedCodec<>("MinY", Codec.INTEGER), (var0, var1) -> var0.minY = var1, var0 -> var0.minY, (var0, var1) -> var0.minY = var1.minY
      )
      .documentation(
         "The minimum Y level this block can spread to, relative to the current block. For example, a value of -1 means the block can spread to blocks one level below it."
      )
      .add()
      .<Integer>appendInherited(
         new KeyedCodec<>("MaxY", Codec.INTEGER), (var0, var1) -> var0.maxY = var1, var0 -> var0.maxY, (var0, var1) -> var0.maxY = var1.maxY
      )
      .documentation(
         "The maximum Y level this block can spread to, relative to the current block. For example, a value of 1 means the block can spread to blocks one level above it."
      )
      .add()
      .<String>appendInherited(new KeyedCodec<>("AllowedTag", Codec.STRING), (var0, var1) -> {
         var0.allowedTag = var1;
         var0.allowedTagIndex = AssetRegistry.getOrCreateTagIndex(var1);
      }, var0 -> var0.allowedTag, (var0, var1) -> {
         var0.allowedTag = var1.allowedTag;
         var0.allowedTagIndex = var1.allowedTagIndex;
      })
      .documentation("The asset tag that the block can spread to.")
      .addValidator(Validators.nonNull())
      .add()
      .<Boolean>appendInherited(
         new KeyedCodec<>("RequireEmptyAboveTarget", Codec.BOOLEAN),
         (var0, var1) -> var0.requireEmptyAboveTarget = var1,
         var0 -> var0.requireEmptyAboveTarget,
         (var0, var1) -> var0.requireEmptyAboveTarget = var1.requireEmptyAboveTarget
      )
      .documentation("Whether the block requires an empty block above the target block to spread.")
      .add()
      .<String[]>appendInherited(
         new KeyedCodec<>("AllowedAboveFluids", Codec.STRING_ARRAY),
         (var0, var1) -> var0.allowedAboveFluidIds = var1,
         var0 -> var0.allowedAboveFluidIds,
         (var0, var1) -> var0.allowedAboveFluidIds = var1.allowedAboveFluidIds
      )
      .documentation("List of fluids that spreading is allowed to occur under. Null will allow spreading under any fluid.")
      .addValidator(Fluid.VALIDATOR_CACHE.getArrayValidator().late())
      .add()
      .<Integer>appendInherited(
         new KeyedCodec<>("RequiredLightLevel", Codec.INTEGER),
         (var0, var1) -> var0.requiredLightLevel = var1,
         var0 -> var0.requiredLightLevel,
         (var0, var1) -> var0.requiredLightLevel = var1.requiredLightLevel
      )
      .documentation("The minimum light level required for the block to spread.")
      .addValidator(Validators.range(0, 15))
      .add()
      .<String>appendInherited(
         new KeyedCodec<>("RevertBlock", Codec.STRING),
         (var0, var1) -> var0.revertBlock = var1,
         var0 -> var0.revertBlock,
         (var0, var1) -> var0.revertBlock = var1.revertBlock
      )
      .documentation("If specified, the block will revert to this block if it is covered by another block.")
      .addValidatorLate(() -> BlockType.VALIDATOR_CACHE.getValidator().late())
      .add()
      .build();
   class="kw">private Vector3i[] spreadDirections;
   class="kw">private int minY = 0;
   class="kw">private int maxY = 0;
   class="kw">private String allowedTag;
   class="kw">private int allowedTagIndex = Integer.MIN_VALUE;
   class="kw">private boolean requireEmptyAboveTarget = true;
   class="kw">private String[] allowedAboveFluidIds;
   @Nullable
   class="kw">private class="kw">transient int[] allowedAboveFluidIndexes = new int[]{Integer.MIN_VALUE};
   class="kw">private int requiredLightLevel = 6;
   class="kw">private String revertBlock;

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

   @Override
   class="kw">public void onRandomTick(Store<ChunkStore> var1, CommandBuffer<ChunkStore> var2, BlockSection var3, int var4, int var5, int var6, int var7, BlockType var8) {
      IntSet var9 = BlockType.getAssetMap().getIndexesForTag(this.allowedTagIndex);
      WorldTimeResource var10 = var2.getExternalData().getWorld().getEntityStore().getStore().getResource(WorldTimeResource.getResourceType());
      double var11 = var10.getSunlightFactor();
      int[] var13 = this.getAllowedAboveFluidIndexes();
      Ref var14 = var1.getExternalData().getChunkSectionReferenceAtBlock(var4, var5 + 1, var6);
      if (var14 != null) {
         BlockSection var15 = var2.getComponent(var14, BlockSection.getComponentType());
         if (var15 != null) {
            int var16 = ChunkUtil.indexBlock(var4, var5 + 1, var6);
            FluidSection var17 = var2.getComponent(var14, FluidSection.getComponentType());
            if (var17 != null) {
               if (this.revertBlock != null) {
                  int var18 = var15.get(var16);
                  BlockType var19 = BlockType.getAssetMap().getAsset(var18);
                  if (var19 != null
                     && var19.getMaterial() == BlockMaterial.Solid
                     && var19.getOpacity() == Opacity.Solid
                     && (var19.getDrawType() == DrawType.Cube || var19.getDrawType() == DrawType.CubeWithModel)) {
                     int var20 = BlockType.getAssetMap().getIndex(this.revertBlock);
                     if (var20 != Integer.MIN_VALUE) {
                        var3.set(var4, var5, var6, var20, 0, 0);
                        class="kw">return;
                     }
                  }

                  if (var13 != null) {
                     Fluid var38 = var17.getFluid(var16);
                     int var21 = BlockType.getAssetMap().getIndex(this.revertBlock);
                     if (var21 != Integer.MIN_VALUE && var38 != null && !this.fluidAllowedAbove(var13, Fluid.getAssetMap().getIndex(var38.getId()))) {
                        var3.set(var4, var5, var6, var21, 0, 0);
                        class="kw">return;
                     }
                  }
               }

               int var36 = (int)(var15.getLocalLight().getSkyLight(var16) * var11);
               int var37 = var15.getLocalLight().getBlockLightIntensity(var16);
               int var39 = Math.max(var36, var37);
               if (var39 >= this.requiredLightLevel) {
                  for (int var40 = this.minY; var40 <= this.maxY; var40++) {
                     for (Vector3i var25 : this.spreadDirections) {
                        int var26 = var4 + var25.x;
                        int var27 = var5 + var25.y + var40;
                        int var28 = var6 + var25.z;
                        BlockSection var29 = var3;
                        if (!ChunkUtil.isSameChunkSection(var4, var5, var6, var26, var27, var28)) {
                           Ref var30 = var1.getExternalData().getChunkSectionReferenceAtBlock(var26, var27, var28);
                           if (var30 == null) {
                              class="kw">continue;
                           }

                           var29 = var2.getComponent(var30, BlockSection.getComponentType());
                           if (var29 == null) {
                              class="kw">continue;
                           }
                        }

                        int var41 = ChunkUtil.indexBlock(var26, var27, var28);
                        int var31 = var29.get(var41);
                        if (var9.contains(var31)) {
                           if (this.requireEmptyAboveTarget) {
                              int var32;
                              if (ChunkUtil.isSameChunkSection(var26, var27, var28, var26, var27 + 1, var28)) {
                                 var32 = var29.get(ChunkUtil.indexBlock(var26, var27 + 1, var28));
                              } else {
                                 Ref var33 = var1.getExternalData().getChunkSectionReferenceAtBlock(var26, var27 + 1, var28);
                                 if (var33 == null) {
                                    class="kw">continue;
                                 }

                                 BlockSection var34 = var2.getComponent(var33, BlockSection.getComponentType());
                                 if (var34 == null) {
                                    class="kw">continue;
                                 }

                                 var32 = var34.get(ChunkUtil.indexBlock(var26, var27 + 1, var28));
                              }

                              BlockType var43 = BlockType.getAssetMap().getAsset(var32);
                              if (var43 == null || var43.getMaterial() != BlockMaterial.Empty) {
                                 class="kw">continue;
                              }
                           }

                           if (var13 != null) {
                              Ref var42 = var1.getExternalData().getChunkSectionReferenceAtBlock(var26, var27 + 1, var28);
                              if (var42 == null) {
                                 class="kw">continue;
                              }

                              FluidSection var44 = var2.getComponent(var42, FluidSection.getComponentType());
                              if (var44 == null) {
                                 class="kw">continue;
                              }

                              int var45 = ChunkUtil.indexBlock(var26, var27 + 1, var28);
                              Fluid var35 = var44.getFluid(var45);
                              if (var35 != null && !this.fluidAllowedAbove(var13, Fluid.getAssetMap().getIndex(var35.getId()))) {
                                 class="kw">continue;
                              }
                           }

                           var29.set(var41, var7, 0, 0);
                        }
                     }
                  }
               }
            }
         }
      }
   }

   class="kw">private boolean fluidAllowedAbove(int[] var1, int var2) {
      if (var1 == null) {
         class="kw">return true;
      }

      for (int var6 : var1) {
         if (var6 == var2) {
            class="kw">return true;
         }
      }

      class="kw">return false;
   }

   @Nullable
   class="kw">private int[] getAllowedAboveFluidIndexes() {
      if (this.allowedAboveFluidIndexes != null && this.allowedAboveFluidIndexes[0] == Integer.MIN_VALUE) {
         if (this.allowedAboveFluidIds == null) {
            this.allowedAboveFluidIndexes = null;
         } else {
            this.allowedAboveFluidIndexes = new int[this.allowedAboveFluidIds.length];

            for (int var1 = 0; var1 < this.allowedAboveFluidIds.length; var1++) {
               this.allowedAboveFluidIndexes[var1] = Fluid.getAssetMap().getIndex(this.allowedAboveFluidIds[var1]);
            }
         }
      }

      class="kw">return this.allowedAboveFluidIndexes;
   }
}