Direction enum

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

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

Поля (2)

МодификаторыТипИмя
public static final EnumCodec<HorizontalSelector.Direction> CODEC
private final double yawModifier

Методы (1)

МодификаторыВозвратСигнатура
abstract TO_LEFT TO_LEFT(1.0)

Исходный код

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

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.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.math.hitdetection.HitDetectionExecutor;
class="kw">import com.hypixel.hytale.math.hitdetection.LineOfSightProvider;
class="kw">import com.hypixel.hytale.math.hitdetection.projection.FrustumProjectionProvider;
class="kw">import com.hypixel.hytale.math.hitdetection.view.DirectionViewProvider;
class="kw">import com.hypixel.hytale.math.iterator.BlockIterator;
class="kw">import com.hypixel.hytale.math.shape.Box;
class="kw">import com.hypixel.hytale.math.util.HashUtil;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.protocol.BlockMaterial;
class="kw">import com.hypixel.hytale.protocol.HorizontalSelectorDirection;
class="kw">import com.hypixel.hytale.protocol.SelectorAnchor;
class="kw">import com.hypixel.hytale.server.core.asset.type.blockhitbox.BlockBoundingBoxes;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.modules.debug.DebugUtils;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.BoundingBox;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.none.SelectInteraction;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.AbstractCachedAccessor;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.CachedAccessor;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.core.util.FillerBlockUtil;
class="kw">import java.util.function.BiConsumer;
class="kw">import java.util.function.Predicate;
class="kw">import javax.annotation.Nonnull;
class="kw">import org.joml.Matrix4d;
class="kw">import org.joml.Vector3d;
class="kw">import org.joml.Vector3f;
class="kw">import org.joml.Vector4d;

class="kw">public class HorizontalSelector class="kw">extends SelectorType {
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<HorizontalSelector> CODEC = BuilderCodec.builder(HorizontalSelector.class, HorizontalSelector::new, BASE_CODEC)
      .documentation("A selector that swings in a horizontal arc over a given period of time.")
      .<Double>appendInherited(
         new KeyedCodec<>("Length", Codec.DOUBLE),
         (var0, var1) -> var0.yawLength = Math.toRadians(var1),
         var0 -> Math.toDegrees(var0.yawLength),
         (var0, var1) -> var0.yawLength = var1.yawLength
      )
      .documentation("The angle length in degrees that the arc will cover.")
      .add()
      .<HorizontalSelector.Direction>appendInherited(
         new KeyedCodec<>("Direction", HorizontalSelector.Direction.CODEC),
         (var0, var1) -> var0.direction = var1,
         var0 -> var0.direction,
         (var0, var1) -> var0.direction = var1.direction
      )
      .documentation("The direction the swing should travel in.")
      .addValidator(Validators.nonNull())
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("StartDistance", Codec.DOUBLE),
         (var0, var1) -> var0.startDistance = var1,
         var0 -> var0.startDistance,
         (var0, var1) -> var0.startDistance = var1.startDistance
      )
      .documentation("The distance from the entity that the selector starts its search from.")
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("EndDistance", Codec.DOUBLE),
         (var0, var1) -> var0.endDistance = var1,
         var0 -> var0.endDistance,
         (var0, var1) -> var0.endDistance = var1.endDistance
      )
      .documentation("The distance from the entity that the selector ends its search at.")
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("ExtendTop", Codec.DOUBLE),
         (var0, var1) -> var0.extendTop = var1,
         var0 -> var0.extendTop,
         (var0, var1) -> var0.extendTop = var1.extendTop
      )
      .documentation("The amount to extend the top of the selector by.")
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("ExtendBottom", Codec.DOUBLE),
         (var0, var1) -> var0.extendBottom = var1,
         var0 -> var0.extendBottom,
         (var0, var1) -> var0.extendBottom = var1.extendBottom
      )
      .documentation("The amount to extend the bottom of the selector by.")
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("YawStartOffset", Codec.DOUBLE),
         (var0, var1) -> var0.yawStartOffset = Math.toRadians(var1),
         var0 -> Math.toDegrees(var0.yawStartOffset),
         (var0, var1) -> var0.yawStartOffset = var1.yawStartOffset
      )
      .documentation("The yaw rotation offset in degrees for this selector")
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("PitchOffset", Codec.DOUBLE),
         (var0, var1) -> var0.pitchOffset = Math.toRadians(var1),
         var0 -> Math.toDegrees(var0.pitchOffset),
         (var0, var1) -> var0.pitchOffset = var1.pitchOffset
      )
      .documentation("The pitch rotation offset in degrees for this selector")
      .add()
      .<Double>appendInherited(
         new KeyedCodec<>("RollOffset", Codec.DOUBLE),
         (var0, var1) -> var0.rollOffset = Math.toRadians(var1),
         var0 -> Math.toDegrees(var0.rollOffset),
         (var0, var1) -> var0.rollOffset = var1.rollOffset
      )
      .documentation("The roll rotation offset in degrees for this selector")
      .add()
      .<Boolean>appendInherited(
         new KeyedCodec<>("TestLineOfSight", Codec.BOOLEAN),
         (var0, var1) -> var0.testLineOfSight = var1,
         var0 -> var0.testLineOfSight,
         (var0, var1) -> var0.testLineOfSight = var1.testLineOfSight
      )
      .documentation("Whether to test for line of sight between the user and the target before counting a hit")
      .add()
      .<Boolean>appendInherited(
         new KeyedCodec<>("IgnorePitch", Codec.BOOLEAN),
         (var0, var1) -> var0.ignorePitch = var1,
         var0 -> var0.ignorePitch,
         (var0, var1) -> var0.ignorePitch = var1.ignorePitch
      )
      .documentation("Ignores the entity's look pitch so the selector stays level with the ground.")
      .add()
      .<Boolean>appendInherited(
         new KeyedCodec<>("IgnoreYaw", Codec.BOOLEAN),
         (var0, var1) -> var0.ignoreYaw = var1,
         var0 -> var0.ignoreYaw,
         (var0, var1) -> var0.ignoreYaw = var1.ignoreYaw
      )
      .documentation("Ignores the entity's look yaw, keeping the selector in a fixed world direction (use YawStartOffset to orient it).")
      .add()
      .<SelectorAnchor>appendInherited(
         new KeyedCodec<>("Anchor", new EnumCodec<>(SelectorAnchor.class)),
         (var0, var1) -> var0.anchor = var1,
         var0 -> var0.anchor,
         (var0, var1) -> var0.anchor = var1.anchor
      )
      .documentation(
         "Where the selector anchors vertically: Eyes (class="kw">default) follows the entity's model eye height, Feet anchors at ground level so the same attack asset works across differently sized entities."
      )
      .add()
      .build();
   class="kw">private class="kw">static class="kw">final AbstractCachedAccessor.Registry REGISTRY = new AbstractCachedAccessor.Registry();
   class="kw">private class="kw">static class="kw">final AbstractCachedAccessor.Key<BlockSection> BLOCK_SECTION = REGISTRY.forSection(BlockSection::getComponentType);
   class="kw">private class="kw">static class="kw">final AbstractCachedAccessor.InitFunction ACCESSOR = REGISTRY.threadLocal();
   class="kw">protected double extendTop = 1.0;
   class="kw">protected double extendBottom = 1.0;
   class="kw">protected double yawLength;
   class="kw">protected double yawStartOffset;
   class="kw">protected double pitchOffset;
   class="kw">protected double rollOffset;
   class="kw">protected double startDistance = 0.01;
   class="kw">protected double endDistance;
   class="kw">protected HorizontalSelector.Direction direction;
   class="kw">protected boolean testLineOfSight = true;
   class="kw">protected boolean ignorePitch;
   class="kw">protected boolean ignoreYaw;
   @Nonnull
   class="kw">protected SelectorAnchor anchor = SelectorAnchor.Eyes;

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

   @Nonnull
   @Override
   class="kw">public Selector newSelector() {
      class="kw">return new HorizontalSelector.RuntimeSelector();
   }

   class="kw">public com.hypixel.hytale.protocol.Selector toPacket() {
      com.hypixel.hytale.protocol.HorizontalSelector var1 = new com.hypixel.hytale.protocol.HorizontalSelector();
      var1.extendTop = (float)this.extendTop;
      var1.extendBottom = (float)this.extendBottom;
      var1.yawLength = (float)this.yawLength;
      var1.yawStartOffset = (float)this.yawStartOffset;
      var1.pitchOffset = (float)this.pitchOffset;
      var1.rollOffset = (float)this.rollOffset;
      var1.startDistance = (float)this.startDistance;
      var1.endDistance = (float)this.endDistance;

      var1.direction = class="kw">switch (this.direction) {
         case TO_RIGHT -> HorizontalSelectorDirection.ToRight;
         case TO_LEFT -> HorizontalSelectorDirection.ToLeft;
      };
      var1.testLineOfSight = this.testLineOfSight;
      var1.ignorePitch = this.ignorePitch;
      var1.ignoreYaw = this.ignoreYaw;
      var1.anchor = this.anchor;
      class="kw">return var1;
   }

   class="kw">public enum Direction {
      TO_RIGHT(-1.0),
      TO_LEFT(1.0);

      @Nonnull
      class="kw">public class="kw">static class="kw">final EnumCodec<HorizontalSelector.Direction> CODEC = new EnumCodec<>(HorizontalSelector.Direction.class)
         .documentKey(TO_LEFT, "A arc that starts at the right and moves towards the left.")
         .documentKey(TO_RIGHT, "A arc that starts at the left and moves towards the right.");
      class="kw">private class="kw">final double yawModifier;

      Direction(class="kw">final double nullxx) {
         this.yawModifier = nullxx;
      }
   }

   class="kw">private class RuntimeSelector class="kw">implements Selector {
      @Nonnull
      class="kw">protected HitDetectionExecutor executor = new HitDetectionExecutor();
      @Nonnull
      class="kw">protected Matrix4d modelMatrix = new Matrix4d();
      @Nonnull
      class="kw">protected FrustumProjectionProvider projectionProvider = new FrustumProjectionProvider();
      @Nonnull
      class="kw">protected DirectionViewProvider viewProvider = new DirectionViewProvider();
      class="kw">protected float lastTime;
      class="kw">protected double runTimeDeltaPercentageSum;

      class="kw">private RuntimeSelector() {
      }

      @Override
      class="kw">public void tick(@Nonnull CommandBuffer<EntityStore> var1, @Nonnull Ref<EntityStore> var2, float var3, float var4) {
         float var5 = ModelComponent.getEyeHeight(var2, var1);
         TransformComponent var6 = var1.getComponent(var2, TransformComponent.getComponentType());
         assert var6 != null;
         Vector3d var7 = var6.getPosition();
         HeadRotation var8 = var1.getComponent(var2, HeadRotation.getComponentType());
         assert var8 != null;
         double var9 = var7.x();
         double var11 = var7.y() + (HorizontalSelector.this.anchor == SelectorAnchor.Feet ? 0.0F : var5);
         double var13 = var7.z();
         float var15 = var3 - this.lastTime;
         this.lastTime = var3;
         float var16 = var15 / var4;
         double var17 = HorizontalSelector.this.startDistance / HorizontalSelector.this.endDistance;
         double var19 = HorizontalSelector.this.yawLength * var16;
         double var21 = HorizontalSelector.this.yawLength * this.runTimeDeltaPercentageSum;
         double var23 = 2.0 * HorizontalSelector.this.endDistance * var19 / (float) Math.PI;
         double var25 = (var21 + var19 + HorizontalSelector.this.yawStartOffset) * HorizontalSelector.this.direction.yawModifier;
         double var27 = var23 * var17;
         this.projectionProvider
            .setNear(HorizontalSelector.this.startDistance)
            .setFar(HorizontalSelector.this.endDistance)
            .setLeft(var27)
            .setRight(var27)
            .setBottom(HorizontalSelector.this.extendBottom * var17)
            .setRotation(var25, HorizontalSelector.this.pitchOffset, HorizontalSelector.this.rollOffset)
            .setTop(HorizontalSelector.this.extendTop * var17);
         this.viewProvider
            .setPosition(var9, var11, var13)
            .setDirection(
               HorizontalSelector.this.ignoreYaw ? 0.0 : var8.getRotation().yaw(), HorizontalSelector.this.ignorePitch ? 0.0 : var8.getRotation().pitch()
            );
         this.executor.setOrigin(var9, var11, var13).setProjectionProvider(this.projectionProvider).setViewProvider(this.viewProvider);
         if (HorizontalSelector.this.testLineOfSight) {
            World var29 = var1.getStore().getExternalData().getWorld();
            LineOfSightProvider var30 = (var2x, var4x, var6x, var8x, var10, var12) -> {
               CachedAccessor var14 = HorizontalSelector.ACCESSOR
                  .getAtBlock(
                     var29.getChunkStore().getStore(),
                     MathUtil.floor(var2x),
                     MathUtil.floor(var4x),
                     MathUtil.floor(var6x),
                     (int)(HorizontalSelector.this.endDistance + 1.0)
                  );
               class="kw">return BlockIterator.iterateFromTo(
                  var2x, var4x, var6x, var8x, var10, var12, (var12x, var13x, var14x, var15x, var17x, var19x, var21x, var23x, var25x, var27x) -> {
                     BlockSection var28 = var27x.getComponentSectionAtBlock(var12x, var13x, var14x, HorizontalSelector.BLOCK_SECTION);
                     if (var28 == null) {
                        class="kw">return true;
                     }

                     BlockType var29 = BlockType.getAssetMap().getAsset(var28.get(var12x, var13x, var14x));
                     if (var29 == null) {
                        class="kw">return true;
                     }

                     if (var29.getMaterial() == BlockMaterial.Solid) {
                        int var30 = var29.getHitboxTypeIndex();
                        BlockBoundingBoxes var31 = BlockBoundingBoxes.getAssetMap().getAsset(var30);
                        if (var31 == null) {
                           class="kw">return true;
                        }

                        Vector3d var32 = new Vector3d(var2x, var4x, var6x);
                        Vector3d var33 = new Vector3d(var8x, var10, var12);
                        BlockBoundingBoxes.RotatedVariantBoxes var34 = var31.get(var28.getRotationIndex(var12x, var13x, var14x));

                        for (Box var38 : var34.getDetailBoxes()) {
                           Box var39 = var38.clone().offset(var12x, var13x, var14x);
                           if (var39.intersectsLine(var32, var33)) {
                              class="kw">return false;
                           }
                        }
                     }

                     class="kw">return true;
                  }, var14
               );
            };
            this.executor.setLineOfSightProvider(var30);
         } else {
            this.executor.setLineOfSightProvider(LineOfSightProvider.DEFAULT_TRUE);
         }

         if (SelectInteraction.SHOW_VISUAL_DEBUG) {
            Matrix4d var31 = new Matrix4d();
            var31.identity()
               .translate(var9, var11, var13)
               .rotate(HorizontalSelector.this.ignoreYaw ? 0.0 : var8.getRotation().yaw(), 0.0, 1.0, 0.0)
               .rotate(HorizontalSelector.this.ignorePitch ? 0.0 : var8.getRotation().pitch(), 1.0, 0.0, 0.0);
            Vector3f var32 = new Vector3f(
               (float)HashUtil.random(var2.getIndex(), this.hashCode(), 10L),
               (float)HashUtil.random(var2.getIndex(), this.hashCode(), 11L),
               (float)HashUtil.random(var2.getIndex(), this.hashCode(), 12L)
            );
            DebugUtils.addFrustum(var1.getExternalData().getWorld(), var31, this.projectionProvider.getMatrix(), var32, 5.0F, 1);
         }

         this.runTimeDeltaPercentageSum += var16;
      }

      @Override
      class="kw">public void selectTargetEntities(
         @Nonnull CommandBuffer<EntityStore> var1,
         @Nonnull Ref<EntityStore> var2,
         @Nonnull BiConsumer<Ref<EntityStore>, Vector4d> var3,
         Predicate<Ref<EntityStore>> var4
      ) {
         Selector.selectNearbyEntities(var1, var2, HorizontalSelector.this.endDistance + 3.0, var3x -> {
            BoundingBox var4 = var1.getComponent(var3x, BoundingBox.getComponentType());
            if (var4 != null) {
               Box var5 = var4.getBoundingBox();
               TransformComponent var6 = var1.getComponent(var3x, TransformComponent.getComponentType());
               if (var6 != null) {
                  this.modelMatrix.identity().translate(var6.getPosition()).translate(var5.getMin()).scale(var5.width(), var5.height(), var5.depth());
                  if (this.executor.test(HitDetectionExecutor.CUBE_QUADS, this.modelMatrix)) {
                     var3.accept(var3x, this.executor.getHitLocation());
                  }
               }
            }
         }, var4);
      }

      @Override
      class="kw">public void selectTargetBlocks(@Nonnull CommandBuffer<EntityStore> var1, @Nonnull Ref<EntityStore> var2, @Nonnull Selector.BlockConsumer var3) {
         TransformComponent var4 = var1.getComponent(var2, TransformComponent.getComponentType());
         assert var4 != null;
         Vector3d var5 = var4.getPosition();
         float var6 = ModelComponent.getEyeHeight(var2, var1);
         double var7 = HorizontalSelector.this.startDistance + HorizontalSelector.this.endDistance;
         World var9 = var1.getStore().getExternalData().getWorld();
         CachedAccessor var10 = SelectorBlockScan.accessorAt(var9, var5.x, var5.y + var6, var5.z, var7);
         Selector.selectNearbyBlocks(
            var5.x,
            var5.y + var6,
            var5.z,
            var7,
            (var3x, var4x, var5x) -> {
               BlockSection var6 = var10.getComponentSectionAtBlock(var3x, var4x, var5x, SelectorBlockScan.BLOCK_SECTION);
               if (var6 != null) {
                  int var7 = var6.get(var3x, var4x, var5x);
                  if (var7 != 0) {
                     BlockType var8 = BlockType.getAssetMap().getAsset(var7);
                     if (var8 != null) {
                        BlockBoundingBoxes var9 = BlockBoundingBoxes.getAssetMap().getAsset(var8.getHitboxTypeIndex());
                        if (var9 != null) {
                           int var10 = var6.getFiller(var3x, var4x, var5x);
                           int var11 = var3x - FillerBlockUtil.unpackX(var10);
                           int var12 = var4x - FillerBlockUtil.unpackY(var10);
                           int var13 = var5x - FillerBlockUtil.unpackZ(var10);
                           Box[] var14 = var9.get(var6.getRotationIndex(var3x, var4x, var5x)).getDetailBoxes();

                           for (Box var18 : var14) {
                              this.modelMatrix
                                 .identity()
                                 .translate(var11, var12, var13)
                                 .translate(var18.getMin())
                                 .scale(var18.width(), var18.height(), var18.depth());
                              if (this.executor.test(HitDetectionExecutor.CUBE_QUADS, this.modelMatrix)) {
                                 var3.accept(var3x, var4x, var5x, var11, var12, var13);
                                 break;
                              }
                           }
                        }
                     }
                  }
               }
            }
         );
      }
   }
}