Rule class

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

Файл: com/hypixel/hytale/builtin/worldgen/modifier/content/common/BlockMask.java

Поля (24)

МодификаторыТипИмя
public static final BuilderCodec<BlockMask.Rule> CODEC
protected static final ListPool<BlockFluidEntry> POOL
protected boolean any
protected String[] blocks
protected boolean empty
protected String[] fluids
IndexedLookupTableAssetMap var1
String var10
ObjectIterator var10
int var11
String var11
int var12
int var16
int var17
BlockTypeAssetMap var2
IndexedLookupTableAssetMap var2
int var21
BlockMaskCondition.MaskEntry var21
int var26
LongOpenHashSet var3
BlockTypeAssetMap var3
ObjectSet var8
ObjectIterator var9
ObjectSet var9

Методы (21)

МодификаторыВозвратСигнатура
abstract return new HashSetBlockFluidConditionreturn new HashSetBlockFluidCondition(var3)
public IBlockFluidCondition buildConditionpublic IBlockFluidCondition buildCondition()
public BlockMaskCondition.MaskEntry buildMaskEntrypublic BlockMaskCondition.MaskEntry buildMaskEntry(boolean var1)
for for(String var7 : this.blocks)
for for(String var15 : this.fluids)
for for(String var20 : this.fluids)
for for(String var8 : this.blocks)
for for(String var16 : this.fluids)
for for(String var25 : this.fluids)
if if(this.any)
if if(!this.empty && this.blocks.length == 0 && this.fluids.length == 0)
if if(this.empty)
if if(var11 != 1)
if if(var16 != 1)
if if(var21 != 1)
if if(this.any)
if if(!this.empty && this.blocks.length == 0 && this.fluids.length == 0)
if if(this.empty)
if if(var12 != 1)
if if(var17 != 1)
if if(var26 != 1)

Исходный код

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

class="kw">import com.hypixel.hytale.assetstore.map.BlockTypeAssetMap;
class="kw">import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap;
class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.content.Codecs;
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.common.util.ArrayUtil;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.procedurallib.condition.ConstantBlockFluidCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.IBlockFluidCondition;
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.worldgen.util.BlockFluidEntry;
class="kw">import com.hypixel.hytale.server.worldgen.util.ListPool;
class="kw">import com.hypixel.hytale.server.worldgen.util.ResolvedBlockArray;
class="kw">import com.hypixel.hytale.server.worldgen.util.condition.BlockMaskCondition;
class="kw">import com.hypixel.hytale.server.worldgen.util.condition.FilteredBlockFluidCondition;
class="kw">import com.hypixel.hytale.server.worldgen.util.condition.HashSetBlockFluidCondition;
class="kw">import it.unimi.dsi.fastutil.longs.Long2ObjectMaps;
class="kw">import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectIterator;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectSet;
class="kw">import javax.annotation.Nonnull;

class="kw">public class BlockMask {
   class="kw">public class="kw">static class="kw">final BuilderCodec<BlockMask> CODEC = BuilderCodec.builder(BlockMask.class, BlockMask::new)
      .documentation("Defines a block mask that filters which blocks and fluids can be replaced, using include and exclude rules to control placement targets")
      .<BlockMask.Rule>append(new KeyedCodec<>("Include", BlockMask.Rule.CODEC), (var0, var1) -> var0.include = var1, var0 -> var0.include)
      .documentation("Set of block and fluid types that should be included by this mask")
      .add()
      .<BlockMask.Rule>append(new KeyedCodec<>("Exclude", BlockMask.Rule.CODEC), (var0, var1) -> var0.exclude = var1, var0 -> var0.exclude)
      .documentation("Set of block and fluid types that should be excluded by this mask")
      .add()
      .afterDecode(BlockMask::rebuild)
      .build();
   class="kw">public class="kw">static class="kw">final BlockMask REPLACE_ANY = new BlockMask() {
      {
         this.include.any = true;
         this.rebuild();
      }
   };
   class="kw">public class="kw">static class="kw">final BlockMask REPLACE_EMPTY = new BlockMask() {
      {
         this.include.empty = true;
         this.rebuild();
      }
   };
   class="kw">public class="kw">static class="kw">final BlockMask REPLACE_SOLID = new BlockMask() {
      {
         this.include.any = true;
         this.exclude.empty = true;
         this.rebuild();
      }
   };
   class="kw">protected BlockMask.Rule include = new BlockMask.Rule();
   class="kw">protected BlockMask.Rule exclude = new BlockMask.Rule();
   @Nonnull
   class="kw">protected class="kw">transient BlockMaskCondition mask = BlockMaskCondition.DEFAULT_TRUE;
   @Nonnull
   class="kw">protected class="kw">transient IBlockFluidCondition condition = ConstantBlockFluidCondition.DEFAULT_TRUE;

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

   @Nonnull
   class="kw">public BlockMaskCondition getBlockMask() {
      class="kw">return this.mask;
   }

   @Nonnull
   class="kw">public IBlockFluidCondition getCondition() {
      class="kw">return this.condition;
   }

   class="kw">protected void rebuild() {
      this.condition = new FilteredBlockFluidCondition(this.exclude.buildCondition(), this.include.buildCondition());
      this.mask = new BlockMaskCondition();
      this.mask
         .set(
            new BlockMaskCondition.Mask(new BlockMaskCondition.MaskEntry[]{this.exclude.buildMaskEntry(false), this.include.buildMaskEntry(true)}),
            Long2ObjectMaps.emptyMap()
         );
   }

   class="kw">public class="kw">static class Rule {
      class="kw">public class="kw">static class="kw">final BuilderCodec<BlockMask.Rule> CODEC = BuilderCodec.builder(BlockMask.Rule.class, BlockMask.Rule::new)
         .documentation("Defines a block mask rule specifying which blocks and fluids to match, using any, empty, or explicit block and fluid lists")
         .<Boolean>append(new KeyedCodec<>("Any", Codec.BOOLEAN), (var0, var1) -> var0.any = var1, var0 -> var0.any)
         .documentation("Flag indicating the rule matches on any block or fluid")
         .add()
         .<Boolean>append(new KeyedCodec<>("Empty", Codec.BOOLEAN), (var0, var1) -> var0.empty = var1, var0 -> var0.empty)
         .documentation("Flag indicating the rule matches on the empty block")
         .add()
         .<String[]>append(new KeyedCodec<>("Blocks", Codecs.BLOCK_TYPE_ARRAY), (var0, var1) -> var0.blocks = var1, var0 -> var0.blocks)
         .documentation("List of blocks that this rule should match on")
         .add()
         .<String[]>append(new KeyedCodec<>("Fluids", Codecs.FLUID_TYPE_ARRAY), (var0, var1) -> var0.fluids = var1, var0 -> var0.fluids)
         .documentation("List of fluids that this rule should match on")
         .add()
         .build();
      class="kw">protected class="kw">static class="kw">final ListPool<BlockFluidEntry> POOL = new ListPool<>(10, BlockFluidEntry.EMPTY_ARRAY);
      class="kw">protected boolean any = false;
      class="kw">protected boolean empty = false;
      class="kw">protected String[] blocks = ArrayUtil.EMPTY_STRING_ARRAY;
      class="kw">protected String[] fluids = ArrayUtil.EMPTY_STRING_ARRAY;

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

      class="kw">public IBlockFluidCondition buildCondition() {
         if (this.any) {
            class="kw">return ConstantBlockFluidCondition.DEFAULT_TRUE;
         }

         if (!this.empty && this.blocks.length == 0 && this.fluids.length == 0) {
            class="kw">return ConstantBlockFluidCondition.DEFAULT_FALSE;
         }

         IndexedLookupTableAssetMap var1 = Fluid.getAssetMap();
         BlockTypeAssetMap var2 = BlockType.getAssetMap();
         LongOpenHashSet var3 = new LongOpenHashSet();
         if (this.empty) {
            var3.add(MathUtil.packLong(0, 0));
         }

         for (String var7 : this.blocks) {
            ObjectSet var8 = var2.getSubKeys(var7);
            ObjectIterator var9 = var8.iterator();

            while (var9.hasNext()) {
               String var10 = (String)var9.next();
               int var11 = var2.getIndex(var10);
               if (var11 != 1) {
                  var3.add(MathUtil.packLong(var11, 0));

                  for (String var15 : this.fluids) {
                     int var16 = var1.getIndex(var15);
                     if (var16 != 1) {
                        var3.add(MathUtil.packLong(var11, var16));
                     }
                  }
               }
            }
         }

         for (String var20 : this.fluids) {
            int var21 = var1.getIndex(var20);
            if (var21 != 1) {
               var3.add(MathUtil.packLong(0, var21));
            }
         }

         class="kw">return new HashSetBlockFluidCondition(var3);
      }

      class="kw">public BlockMaskCondition.MaskEntry buildMaskEntry(boolean var1) {
         if (this.any) {
            class="kw">return var1 ? BlockMaskCondition.MaskEntry.WILDCARD_TRUE : BlockMaskCondition.MaskEntry.WILDCARD_FALSE;
         }

         if (!this.empty && this.blocks.length == 0 && this.fluids.length == 0) {
            class="kw">return var1 ? BlockMaskCondition.MaskEntry.WILDCARD_FALSE : BlockMaskCondition.MaskEntry.WILDCARD_TRUE;
         }

         IndexedLookupTableAssetMap var2 = Fluid.getAssetMap();
         BlockTypeAssetMap var3 = BlockType.getAssetMap();

         try (ListPool.Resource var4 = POOL.acquire()) {
            if (this.empty) {
               var4.add(BlockFluidEntry.EMPTY);
            }

            for (String var8 : this.blocks) {
               ObjectSet var9 = var3.getSubKeys(var8);
               ObjectIterator var10 = var9.iterator();

               while (var10.hasNext()) {
                  String var11 = (String)var10.next();
                  int var12 = var3.getIndex(var11);
                  if (var12 != 1) {
                     var4.add(new BlockFluidEntry(var12, 0, 0));

                     for (String var16 : this.fluids) {
                        int var17 = var2.getIndex(var16);
                        if (var17 != 1) {
                           var4.add(new BlockFluidEntry(var12, 0, var17));
                        }
                     }
                  }
               }
            }

            for (String var25 : this.fluids) {
               int var26 = var2.getIndex(var25);
               if (var26 != 1) {
                  var4.add(new BlockFluidEntry(0, 0, var26));
               }
            }

            BlockMaskCondition.MaskEntry var21 = new BlockMaskCondition.MaskEntry(false, var1);
            var21.set(new ResolvedBlockArray(var4.toArray()), var1);
            class="kw">return var21;
         }
      }
   }
}