BlockIdMatcher class

Пакет: com.hypixel.hytale.server.core.modules.interaction.interaction.config.client

Файл: com/hypixel/hytale/server/core/modules/interaction/interaction/config/client/BlockConditionInteraction.java

implements: NetworkSerializable<com.hypixel.hytale.protocol.BlockIdMatcher>

Поля (6)

МодификаторыТипИмя
public static final BuilderCodec<BlockConditionInteraction.BlockIdMatcher> CODEC
protected String id
protected String state
protected String tag
protected int tagIndex
com.hypixel.hytale.protocol.BlockIdMatcher var1

Методы (5)

МодификаторыВозвратСигнатура
if if(var0.tag != null)
if if(this.id != null)
if if(this.state != null)
public com.hypixel.hytale.protocol.BlockIdMatcher toPacketpublic com.hypixel.hytale.protocol.BlockIdMatcher toPacket()
public String toStringpublic String toString()

Исходный код

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

class="kw">import com.hypixel.hytale.assetstore.AssetExtraInfo;
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.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.protocol.BlockFace;
class="kw">import com.hypixel.hytale.protocol.GameMode;
class="kw">import com.hypixel.hytale.protocol.Interaction;
class="kw">import com.hypixel.hytale.protocol.InteractionState;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.protocol.PlaceMode;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.Rotation;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.RotationTuple;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.Item;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.io.NetworkSerializable;
class="kw">import com.hypixel.hytale.server.core.modules.entity.player.PlayerSettings;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
class="kw">import it.unimi.dsi.fastutil.ints.IntSet;
class="kw">import java.util.Arrays;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3i;

class="kw">public class BlockConditionInteraction class="kw">extends SimpleBlockInteraction {
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<BlockConditionInteraction> CODEC = BuilderCodec.builder(
         BlockConditionInteraction.class, BlockConditionInteraction::new, SimpleBlockInteraction.CODEC
      )
      .documentation("Tests the target block and executes `Next` if it matches all the conditions, otherwise `Failed` is run.")
      .<BlockConditionInteraction.BlockMatcher[]>appendInherited(
         new KeyedCodec<>("Matchers", new ArrayCodec<>(BlockConditionInteraction.BlockMatcher.CODEC, BlockConditionInteraction.BlockMatcher[]::new)),
         (var0, var1) -> var0.matchers = var1,
         var0 -> var0.matchers,
         (var0, var1) -> var0.matchers = var1.matchers
      )
      .documentation("The matchers to test the block against.")
      .add()
      .build();
   class="kw">private BlockConditionInteraction.BlockMatcher[] matchers;

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

   @Override
   class="kw">protected void interactWithBlock(
      @Nonnull World var1,
      @Nonnull CommandBuffer<EntityStore> var2,
      @Nonnull InteractionType var3,
      @Nonnull InteractionContext var4,
      @Nullable ItemStack var5,
      @Nonnull Vector3i var6,
      @Nonnull CooldownHandler var7
   ) {
      BlockFace var8 = var4.getClientState().blockFace;
      this.doInteraction(var4, var1, var6, var8);
   }

   @Override
   class="kw">protected void simulateInteractWithBlock(
      @Nonnull InteractionType var1, @Nonnull InteractionContext var2, @Nullable ItemStack var3, @Nonnull World var4, @Nonnull Vector3i var5
   ) {
      var2.getState().blockFace = BlockFace.Up;
      this.doInteraction(var2, var4, var5, var2.getState().blockFace);
   }

   class="kw">private void doInteraction(@Nonnull InteractionContext var1, @Nonnull World var2, @Nonnull Vector3i var3, @Nonnull BlockFace var4) {
      ChunkStore var5 = var2.getChunkStore();
      Store var6 = var5.getStore();
      Ref var7 = var5.getChunkSectionReferenceAtBlock(var3.x, var3.y, var3.z);
      if (var7 != null && var7.isValid()) {
         BlockSection var8 = var6.getComponent(var7, BlockSection.getComponentType());
         if (var8 != null) {
            BlockType var9 = BlockType.getAssetMap().getAsset(var8.get(var3.x, var3.y, var3.z));
            if (var9 != null) {
               RotationTuple var10 = var8.getRotation(var3.x, var3.y, var3.z);
               Item var11 = var9.getItem();
               if (var11 == null) {
                  var1.getState().state = InteractionState.Failed;
               } else {
                  boolean var12 = false;
                  BlockConditionInteraction.BlockMatcher[] var13 = this.matchers;
                  int var14 = var13.length;
                  int var15 = 0;

                  while (var15 < var14) {
                     label90: {
                        label101: {
                           BlockConditionInteraction.BlockMatcher var16 = var13[var15];
                           if (var16.face != BlockFace.None) {
                              BlockFace var17 = var16.face;
                              if (!var16.staticFace) {
                                 Rotation var18 = var10.yaw();
                                 Rotation var19 = var10.pitch();
                                 com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace var20 = com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace.rotate(
                                    com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace.fromProtocolFace(var17), var18, var19
                                 );
                                 var17 = com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace.toProtocolFace(var20);
                              }

                              if (!var17.equals(var4)) {
                                 break label101;
                              }
                           }

                           if (var16.block == null) {
                              break label90;
                           }

                           label82:
                           if (var16.block.id == null || var16.block.id.equals(var11.getId())) {
                              if (var16.block.state != null) {
                                 String var25 = var9.getStateForBlock(var9);
                                 if (var25 == null) {
                                    var25 = "class="kw">default";
                                 }

                                 if (!var16.block.state.equals(var25)) {
                                    break label82;
                                 }
                              }

                              if (var16.block.tag == null) {
                                 break label90;
                              }

                              AssetExtraInfo.Data var26 = var9.getData();
                              if (var26 != null) {
                                 Int2ObjectMap var27 = var26.getTags();
                                 if (var27.containsKey(var16.block.tagIndex)) {
                                    break label90;
                                 }
                              }
                           }
                        }

                        var15++;
                        class="kw">continue;
                     }

                     var12 = true;
                     break;
                  }

                  if (var12) {
                     CommandBuffer var21 = var1.getCommandBuffer();
                     Ref var22 = var1.getEntity();
                     if (var21 != null && var22 != null) {
                        Player var23 = var21.getComponent(var22, Player.getComponentType());
                        if (var23 != null && var23.getGameMode() == GameMode.Creative) {
                           PlayerSettings var24 = var21.getComponent(var22, PlayerSettings.getComponentType());
                           if (var24 != null && var24.creativeSettings().placeMode() != PlaceMode.Default) {
                              var12 = false;
                           }
                        }
                     }
                  }

                  if (var12) {
                     var1.getState().state = InteractionState.Finished;
                  } else {
                     var1.getState().state = InteractionState.Failed;
                  }
               }
            }
         }
      }
   }

   @Nonnull
   @Override
   class="kw">protected Interaction generatePacket() {
      class="kw">return new com.hypixel.hytale.protocol.BlockConditionInteraction();
   }

   @Override
   class="kw">protected void configurePacket(Interaction var1) {
      super.configurePacket(var1);
      com.hypixel.hytale.protocol.BlockConditionInteraction var2 = (com.hypixel.hytale.protocol.BlockConditionInteraction)var1;
      if (this.matchers != null) {
         var2.matchers = new com.hypixel.hytale.protocol.BlockMatcher[this.matchers.length];

         for (int var3 = 0; var3 < this.matchers.length; var3++) {
            var2.matchers[var3] = this.matchers[var3].toPacket();
         }
      }
   }

   @Nonnull
   @Override
   class="kw">public String toString() {
      class="kw">return "BlockConditionInteraction{matchers=" + Arrays.toString(this.matchers) + "} " + super.toString();
   }

   class="kw">public class="kw">static class BlockIdMatcher class="kw">implements NetworkSerializable<com.hypixel.hytale.protocol.BlockIdMatcher> {
      @Nonnull
      class="kw">public class="kw">static class="kw">final BuilderCodec<BlockConditionInteraction.BlockIdMatcher> CODEC = BuilderCodec.builder(
            BlockConditionInteraction.BlockIdMatcher.class, BlockConditionInteraction.BlockIdMatcher::new
         )
         .appendInherited(new KeyedCodec<>("Id", Codec.STRING), (var0, var1) -> var0.id = var1, var0 -> var0.id, (var0, var1) -> var0.id = var1.id)
         .addValidatorLate(() -> BlockType.VALIDATOR_CACHE.getValidator().late())
         .documentation("Match against a specific block id.")
         .add()
         .<String>appendInherited(
            new KeyedCodec<>("State", Codec.STRING), (var0, var1) -> var0.state = var1, var0 -> var0.state, (var0, var1) -> var0.state = var1.state
         )
         .documentation("Match against specific block state.")
         .add()
         .<String>appendInherited(new KeyedCodec<>("Tag", Codec.STRING), (var0, var1) -> var0.tag = var1, var0 -> var0.tag, (var0, var1) -> var0.tag = var1.tag)
         .documentation("Match against specific block tag.")
         .add()
         .afterDecode(var0 -> {
            if (var0.tag != null) {
               var0.tagIndex = AssetRegistry.getOrCreateTagIndex(var0.tag);
            }
         })
         .build();
      class="kw">protected String id;
      class="kw">protected String state;
      class="kw">protected String tag;
      class="kw">protected int tagIndex = Integer.MIN_VALUE;

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

      @Nonnull
      class="kw">public com.hypixel.hytale.protocol.BlockIdMatcher toPacket() {
         com.hypixel.hytale.protocol.BlockIdMatcher var1 = new com.hypixel.hytale.protocol.BlockIdMatcher();
         if (this.id != null) {
            var1.id = this.id;
         }

         if (this.state != null) {
            var1.state = this.state;
         }

         var1.tagIndex = this.tagIndex;
         class="kw">return var1;
      }

      @Nonnull
      @Override
      class="kw">public String toString() {
         class="kw">return "BlockIdMatcher{id='" + this.id + "', state='" + this.state + "', tag='" + this.tag + "'}";
      }
   }

   class="kw">public class="kw">static class BlockMatcher class="kw">implements NetworkSerializable<com.hypixel.hytale.protocol.BlockMatcher> {
      @Nonnull
      class="kw">public class="kw">static class="kw">final BuilderCodec<BlockConditionInteraction.BlockMatcher> CODEC = BuilderCodec.builder(
            BlockConditionInteraction.BlockMatcher.class, BlockConditionInteraction.BlockMatcher::new
         )
         .appendInherited(
            new KeyedCodec<>("Block", BlockConditionInteraction.BlockIdMatcher.CODEC),
            (var0, var1) -> var0.block = var1,
            var0 -> var0.block,
            (var0, var1) -> var0.block = var1.block
         )
         .documentation("Match against block values")
         .add()
         .<com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace>appendInherited(
            new KeyedCodec<>("Face", com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace.CODEC),
            (var0, var1) -> var0.face = com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace.toProtocolFace(var1),
            var0 -> com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace.fromProtocolFace(var0.face),
            (var0, var1) -> var0.face = var1.face
         )
         .documentation("Match against a specific block face.")
         .add()
         .<Boolean>appendInherited(
            new KeyedCodec<>("StaticFace", Codec.BOOLEAN),
            (var0, var1) -> var0.staticFace = var1,
            var0 -> var0.staticFace,
            (var0, var1) -> var0.staticFace = var1.staticFace
         )
         .documentation("Whether the face matching is unaffected by the block rotation or not.")
         .add()
         .build();
      class="kw">protected BlockConditionInteraction.BlockIdMatcher block;
      class="kw">protected BlockFace face = BlockFace.None;
      class="kw">protected boolean staticFace;

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

      @Nonnull
      class="kw">public com.hypixel.hytale.protocol.BlockMatcher toPacket() {
         com.hypixel.hytale.protocol.BlockMatcher var1 = new com.hypixel.hytale.protocol.BlockMatcher();
         if (this.block != null) {
            var1.block = this.block.toPacket();
         }

         if (this.face != null) {
            var1.face = this.face;
         }

         var1.staticFace = this.staticFace;
         class="kw">return var1;
      }

      @Nonnull
      @Override
      class="kw">public String toString() {
         class="kw">return "BlockMatcher{block=" + this.block + ", face=" + this.face + ", staticFace=" + this.staticFace + "}";
      }
   }
}