BodyMotionTeleport class

Пакет: com.hypixel.hytale.server.npc.corecomponents.movement

Файл: com/hypixel/hytale/server/npc/corecomponents/movement/BodyMotionTeleport.java

extends: BodyMotionBase

Поля (26)

МодификаторыТипИмя
final int MAX_TRIES
break
break
private final String description
TransformComponent var10
Vector3d var11
double var12
double var14
MotionController var16
BoundingBox var17
Ref var18
TransformComponent var19
double[] var2
Rotation3f var20
double var22
Rotation3f var24
float var25
var25
var25
float var26
var26
var26
double var27
Rotation3f var28
double var29
double var8

Методы (11)

МодификаторыВозвратСигнатура
Orientation Orientation(String nullxx)
abstract UseTarget UseTarget("Use the target's orientation")
public String getpublic String get()
if if(var8 > 1.0)
if if(var12 <= var14 + 1.0E-5)
if if(var27 * var27 + var22 * var22 < 1.0E-5)
if if(var18 == null)
if if(this.cooldown > 0.0)
abstract super super(var1)
switch switch(this.orientation)
protected boolean tickCooldownboolean tickCooldown(double var1)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.corecomponents.movement;

class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.math.random.RandomExtra;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.BoundingBox;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.teleport.Teleport;
class="kw">import com.hypixel.hytale.server.core.modules.physics.util.PhysicsMath;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.BodyMotionBase;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.movement.builders.BuilderBodyMotionTeleport;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import com.hypixel.hytale.server.npc.movement.Steering;
class="kw">import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
class="kw">import java.util.function.Supplier;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class BodyMotionTeleport class="kw">extends BodyMotionBase {
   class="kw">public class="kw">static class="kw">final int MAX_TRIES = 10;
   class="kw">public class="kw">static class="kw">final int MIN_MOVE_CHANGE = 1;
   class="kw">public class="kw">static class="kw">final double TELEPORT_COOLDOWN = 0.5;
   class="kw">protected class="kw">static class="kw">final ComponentType<EntityStore, TransformComponent> TRANSFORM_COMPONENT_TYPE = TransformComponent.getComponentType();
   class="kw">protected class="kw">static class="kw">final ComponentType<EntityStore, BoundingBox> BOUNDING_BOX_COMPONENT_TYPE = BoundingBox.getComponentType();
   class="kw">protected class="kw">final double minOffset;
   class="kw">protected class="kw">final double maxOffset;
   class="kw">protected class="kw">final double maxYOffset;
   class="kw">protected class="kw">final float angle;
   class="kw">protected class="kw">final BodyMotionTeleport.Orientation orientation;
   class="kw">protected class="kw">final Vector3d target = new Vector3d();
   class="kw">protected class="kw">final Vector3d offsetVector = new Vector3d();
   class="kw">protected class="kw">final Vector3d lastTriedTarget = new Vector3d();
   class="kw">protected int tries;
   class="kw">protected double cooldown;

   class="kw">public BodyMotionTeleport(@Nonnull BuilderBodyMotionTeleport var1) {
      super(var1);
      double[] var2 = var1.getOffsetRadius();
      this.minOffset = var2[0];
      this.maxOffset = var2[1];
      this.maxYOffset = var1.getMaxYOffset();
      this.angle = var1.getSectorRadians() / 2.0F;
      this.orientation = var1.getOrientation();
   }

   @Override
   class="kw">public void activate(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      this.tries = 10;
   }

   @Override
   class="kw">public boolean computeSteering(
      @Nonnull Ref<EntityStore> var1,
      @Nonnull ExecutionSupport var2,
      @Nullable InfoProvider var3,
      double var4,
      @Nonnull Steering var6,
      @Nonnull ComponentAccessor<EntityStore> var7
   ) {
      if (var3 != null && var3.getPositionProvider().providePosition(this.target)) {
         double var8 = this.target.distanceSquared(this.lastTriedTarget);
         if ((this.tries > 0 || !(var8 < 1.0)) && !this.tickCooldown(var4)) {
            if (var8 > 1.0) {
               this.tries = 10;
            }

            this.lastTriedTarget.set(this.target);
            TransformComponent var10 = var7.getComponent(var1, TRANSFORM_COMPONENT_TYPE);
            assert var10 != null;
            Vector3d var11 = var10.getPosition();
            double var12 = var11.distanceSquared(this.target);
            double var14 = this.maxOffset * this.maxOffset;
            if (var12 <= var14 + 1.0E-5) {
               class="kw">return false;
            }

            this.offsetVector.set(var11).sub(this.target).y = 0.0;
            this.offsetVector.normalize(RandomExtra.randomRange(this.minOffset, this.maxOffset));
            this.offsetVector.rotateY(RandomExtra.randomRange(-this.angle, this.angle));
            this.target.add(this.offsetVector);
            MotionController var16 = var2.getMotionContextSupport().getActiveMotionController();
            BoundingBox var17 = var7.getComponent(var1, BOUNDING_BOX_COMPONENT_TYPE);
            if (var16.translateToAccessiblePosition(
                  this.target, var17 != null ? var17.getBoundingBox() : null, this.target.y - this.maxYOffset, this.target.y + this.maxYOffset, var7
               )
               && var16.isValidPosition(this.target, var7)) {
               class="kw">switch (this.orientation) {
                  case Unchanged: {
                     Rotation3f var28 = var10.getRotation();
                     var7.addComponent(var1, Teleport.getComponentType(), Teleport.createExact(this.target, var28));
                     break;
                  }
                  case TowardsTarget: {
                     double var27 = this.lastTriedTarget.x() - this.target.x();
                     double var29 = this.lastTriedTarget.y() - this.target.y();
                     double var22 = this.lastTriedTarget.z() - this.target.z();
                     Rotation3f var24 = var10.getRotation();
                     float var25;
                     float var26;
                     if (var27 * var27 + var22 * var22 < 1.0E-5) {
                        var25 = var24.yaw();
                        var26 = var24.pitch();
                     } else {
                        var25 = PhysicsMath.normalizeTurnAngle(PhysicsMath.headingFromDirection(var27, var22));
                        var26 = PhysicsMath.pitchFromDirection(var27, var29, var22);
                     }

                     var7.addComponent(var1, Teleport.getComponentType(), Teleport.createExact(this.target, new Rotation3f(var25, var26, var24.roll())));
                     break;
                  }
                  case UseTarget: {
                     Ref var18 = var3.hasPosition() ? var3.getPositionProvider().getTarget() : null;
                     if (var18 == null) {
                        class="kw">return false;
                     }

                     TransformComponent var19 = var7.getComponent(var18, TRANSFORM_COMPONENT_TYPE);
                     assert var19 != null;
                     Rotation3f var20 = var19.getRotation();
                     var7.addComponent(var1, Teleport.getComponentType(), Teleport.createExact(this.target, var20));
                  }
               }

               this.tries = 10;
               this.cooldown = 0.5;
               var6.clear();
               class="kw">return false;
            } else {
               this.tries--;
               class="kw">return true;
            }
         } else {
            class="kw">return false;
         }
      } else {
         class="kw">return false;
      }
   }

   class="kw">protected boolean tickCooldown(double var1) {
      if (this.cooldown > 0.0) {
         this.cooldown -= var1;
         class="kw">return true;
      } else {
         class="kw">return false;
      }
   }

   class="kw">public enum Orientation class="kw">implements Supplier<String> {
      Unchanged("Do not change orientation"),
      TowardsTarget("Face towards the target"),
      UseTarget("Use the target's orientation");

      class="kw">private class="kw">final String description;

      Orientation(String nullxx) {
         this.description = nullxx;
      }

      class="kw">public String get() {
         class="kw">return this.description;
      }
   }
}