SensorPath class

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

Файл: com/hypixel/hytale/server/npc/corecomponents/world/SensorPath.java

extends: SensorBase

Поля (47)

МодификаторыТипИмя
WAITING, FAILED, SUCCESS
break
break
break
break
private final String description
final double range
return
int var10
int var10
double var10
boolean var11
IPath var11
var11
var11
var11
var11
var11
var11
UUID var12
SpatialResource var12
IPath var13
List var13
IPath var14
double var14
var14
PatrolPathMarkerEntity var16
var16
int var17
Ref var18
PatrolPathMarkerEntity var19
TransformComponent var20
double var21
WorldPathData var23
UUID var24
double var5
TransformComponent var6
World var6
NPCEntity var7
NPCEntity var7
double var7
Vector3d var8
PathManager var8
IPathWaypoint var8
PathManager var9
WorldGenId var9
Vector3d var9

Методы (24)

МодификаторыВозвратСигнатура
abstract throw new IllegalStateExceptionthrow new IllegalStateException()
LoadStatus LoadStatus()
PathType PathType(String nullxx)
protected void findClosestWaypointvoid findClosestWaypoint(@Nonnull IPath<?> var1, @Nonnull Vector3d var2, @Nonnull Vector3d var3, @Nonnull ComponentAccessor<EntityStore> var4)
abstract for for(; var17 < var13.size()
abstract for for(int var12 = 0; var12 < var1.length()
public String getpublic String get()
if if(var14 == null)
if if(var12 != null)
if if(var13 == null)
if if(this.pathType == SensorPath.PathType.WorldPath)
if if(var11 == null)
if if(this.path == null)
if if(var24 != null && !var5)
if if(var21 < var14)
if if(var16 == null)
if if(var7 <= this.distanceSquared)
if if(var8 != null)
if if(var10 < this.distanceSquared)
if if(this.distanceSquared == Double.MAX_VALUE)
protected boolean isInRangeboolean isInRange(double var1)
protected boolean pathMatchesboolean pathMatches(@Nonnull IPath<?> var1)
abstract super super(var1)
switch switch(this.pathType)

Исходный код

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

class="kw">import com.hypixel.hytale.assetstore.AssetRegistry;
class="kw">import com.hypixel.hytale.builtin.path.PathPlugin;
class="kw">import com.hypixel.hytale.builtin.path.WorldPathData;
class="kw">import com.hypixel.hytale.builtin.path.entities.PatrolPathMarkerEntity;
class="kw">import com.hypixel.hytale.builtin.path.path.IPrefabPath;
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.component.ResourceType;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.component.spatial.SpatialResource;
class="kw">import com.hypixel.hytale.math.vector.Vector3dUtil;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.WorldGenId;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.path.IPath;
class="kw">import com.hypixel.hytale.server.core.universe.world.path.IPathWaypoint;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.NPCPlugin;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.SensorBase;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.world.builders.BuilderSensorPath;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.entities.PathManager;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.PathProvider;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.PositionProvider;
class="kw">import java.util.HashSet;
class="kw">import java.util.List;
class="kw">import java.util.Set;
class="kw">import java.util.UUID;
class="kw">import java.util.function.Supplier;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class SensorPath class="kw">extends SensorBase {
   class="kw">protected class="kw">final double range;
   class="kw">protected class="kw">final SensorPath.PathType pathType;
   class="kw">protected class="kw">final Vector3d closestWaypoint = new Vector3d(Vector3dUtil.MIN);
   class="kw">protected class="kw">final HashSet<UUID> disallowedPaths = new HashSet<>();
   class="kw">protected class="kw">final PathProvider pathProvider = new PathProvider();
   class="kw">protected class="kw">final PositionProvider positionProvider = new PositionProvider(null, this.pathProvider);
   class="kw">protected class="kw">final ResourceType<EntityStore, SpatialResource<Ref<EntityStore>, EntityStore>> prefabPathSpatialResource;
   @Nullable
   class="kw">protected class="kw">final ComponentType<EntityStore, PatrolPathMarkerEntity> patrolPathMarkerEntityComponentType;
   class="kw">protected class="kw">final ComponentType<EntityStore, WorldGenId> worldGenIdComponentType;
   @Nullable
   class="kw">protected String path;
   class="kw">protected int pathIndex;
   class="kw">protected int pathChangeRevision;
   class="kw">protected double distanceSquared = Double.MAX_VALUE;
   @Nonnull
   class="kw">protected SensorPath.LoadStatus loadStatus = SensorPath.LoadStatus.WAITING;

   class="kw">public SensorPath(@Nonnull BuilderSensorPath var1, @Nonnull BuilderSupport var2) {
      super(var1);
      this.path = var1.getPath(var2);
      if (this.path != null && !this.path.isEmpty()) {
         this.pathIndex = AssetRegistry.getOrCreateTagIndex(this.path);
      }

      this.range = var1.getRange(var2);
      this.pathType = var1.getPathType(var2);
      this.prefabPathSpatialResource = PathPlugin.get().getPrefabPathSpatialResource();
      this.patrolPathMarkerEntityComponentType = PatrolPathMarkerEntity.getComponentType();
      this.worldGenIdComponentType = WorldGenId.getComponentType();
   }

   @Override
   class="kw">public boolean matches(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, double var3, @Nonnull Store<EntityStore> var5) {
      if (super.matches(var1, var2, var3, var5) && this.loadStatus != SensorPath.LoadStatus.FAILED) {
         TransformComponent var6 = var5.getComponent(var1, TransformComponent.getComponentType());
         assert var6 != null;
         NPCEntity var7 = var5.getComponent(var1, NPCEntity.getComponentType());
         assert var7 != null;
         Vector3d var8 = var6.getPosition();
         PathManager var9 = var7.getPathManager();
         int var10 = NPCPlugin.get().getPathChangeRevision();
         boolean var11 = var2.getWorldSupport().consumeNewPathRequested();
         if (var9.isFollowingPath() && var10 == this.pathChangeRevision && !var11) {
            IPath var14 = var9.getPath(var1, var5);
            if (var14 == null) {
               this.pathProvider.clear();
               this.positionProvider.clear();
               class="kw">return false;
            } else {
               this.findClosestWaypoint(var14, var8, this.closestWaypoint, var5);
               if (this.pathMatches(var14) && this.isInRange(this.distanceSquared)) {
                  this.pathProvider.setPath((IPath<? class="kw">extends IPathWaypoint>)var14);
                  this.positionProvider.setTarget(this.closestWaypoint);
                  class="kw">return true;
               } else {
                  this.pathProvider.clear();
                  this.positionProvider.clear();
                  class="kw">return false;
               }
            }
         } else {
            this.pathChangeRevision = var10;
            if (var11 && var9.isFollowingPath()) {
               UUID var12 = var9.getCurrentPathHint();
               if (var12 != null) {
                  this.disallowedPaths.add(var12);
               }
            }

            IPath var13 = this.findPath(var1, var8, var5, this.disallowedPaths, var11);
            if (var13 == null) {
               this.pathProvider.clear();
               this.positionProvider.clear();
               class="kw">return false;
            }

            this.closestWaypoint.set(Vector3dUtil.MIN);
            this.findClosestWaypoint(var13, var8, this.closestWaypoint, var5);
            if (!this.isInRange(this.distanceSquared)) {
               this.pathProvider.clear();
               this.positionProvider.clear();
               class="kw">return false;
            }

            if (this.pathType == SensorPath.PathType.WorldPath) {
               var9.setTransientPath(var13);
            } else {
               var9.setPrefabPath(var13.getId(), (IPrefabPath)var13);
               var5.putComponent(var1, this.worldGenIdComponentType, new WorldGenId(((IPrefabPath)var13).getWorldGenId()));
            }

            this.disallowedPaths.clear();
            this.pathProvider.setPath((IPath<? class="kw">extends IPathWaypoint>)var13);
            this.positionProvider.setTarget(this.closestWaypoint);
            class="kw">return true;
         }
      } else {
         this.pathProvider.clear();
         this.positionProvider.clear();
         class="kw">return false;
      }
   }

   @Override
   class="kw">public InfoProvider getSensorInfo() {
      class="kw">return this.positionProvider;
   }

   class="kw">protected boolean pathMatches(@Nonnull IPath<?> var1) {
      class="kw">return this.path == null || this.path.isEmpty() || this.path.equals(var1.getName());
   }

   class="kw">protected boolean isInRange(double var1) {
      class="kw">return this.range <= 0.0 || this.range * this.range > var1;
   }

   @Nullable
   class="kw">protected IPath<?> findPath(@Nonnull Ref<EntityStore> var1, @Nonnull Vector3d var2, @Nonnull Store<EntityStore> var3, @Nonnull Set<UUID> var4, boolean var5) {
      World var6 = var3.getExternalData().getWorld();
      NPCEntity var7 = var3.getComponent(var1, NPCEntity.getComponentType());
      assert var7 != null;
      PathManager var8 = var7.getPathManager();
      WorldGenId var9 = var3.getComponent(var1, this.worldGenIdComponentType);
      int var10 = var9 != null ? var9.getWorldGenId() : 0;
      IPath var11;
      class="kw">switch (this.pathType) {
         case WorldPath:
            var11 = var6.getWorldPathConfig().getPath(this.path);
            if (var11 == null) {
               NPCPlugin.get().getLogger().at(Level.WARNING).log("Path sensor: Path %s does not exist", this.path);
               this.loadStatus = SensorPath.LoadStatus.FAILED;
               class="kw">return null;
            }
            break;
         case CurrentPrefabPath:
            WorldPathData var23 = var3.getResource(WorldPathData.getResourceType());
            if (this.path == null) {
               var11 = var23.getNearestPrefabPath(var10, var2, var4, var3);
            } else {
               UUID var24 = var8.getCurrentPathHint();
               if (var24 != null && !var5) {
                  var11 = var23.getPrefabPath(var10, var24, false);
               } else {
                  var11 = var23.getNearestPrefabPath(var10, this.pathIndex, var2, var4, var3);
               }
            }

            if (var11 == null || !((IPrefabPath)var11).isFullyLoaded()) {
               this.loadStatus = SensorPath.LoadStatus.WAITING;
               class="kw">return null;
            }

            this.path = var11.getName();
            break;
         case AnyPrefabPath:
            SpatialResource var12 = var3.getResource(this.prefabPathSpatialResource);
            List var13 = SpatialResource.getThreadLocalReferenceList();
            var12.getSpatialStructure().ordered(var2, this.range, var13);
            if (var13.isEmpty()) {
               this.loadStatus = SensorPath.LoadStatus.WAITING;
               class="kw">return null;
            }

            double var14 = Double.MAX_VALUE;
            PatrolPathMarkerEntity var16 = null;
            int var17 = 0;

            for (; var17 < var13.size(); var17++) {
               Ref var18 = var13.get(var17);
               PatrolPathMarkerEntity var19 = var3.getComponent(var18, this.patrolPathMarkerEntityComponentType);
               assert var19 != null;
               if (!var4.contains(var19.getParentPath().getId())) {
                  TransformComponent var20 = var3.getComponent(var18, TransformComponent.getComponentType());
                  assert var20 != null;
                  double var21 = var2.distanceSquared(var20.getPosition());
                  if (var21 < var14) {
                     var14 = var21;
                     var16 = var19;
                  }
               }
            }

            if (var16 == null) {
               this.loadStatus = SensorPath.LoadStatus.WAITING;
               class="kw">return null;
            }

            var11 = var16.getParentPath();
            if (var11 == null || !((IPrefabPath)var11).isFullyLoaded()) {
               this.loadStatus = SensorPath.LoadStatus.WAITING;
               class="kw">return null;
            }
            break;
         case TransientPath:
            var11 = (IPath<? class="kw">extends IPathWaypoint>)var8.getPath(var1, var3);
            this.path = null;
            break;
         class="kw">default:
            throw new IllegalStateException();
      }

      this.loadStatus = SensorPath.LoadStatus.SUCCESS;
      class="kw">return var11;
   }

   class="kw">protected void findClosestWaypoint(@Nonnull IPath<?> var1, @Nonnull Vector3d var2, @Nonnull Vector3d var3, @Nonnull ComponentAccessor<EntityStore> var4) {
      double var5 = this.distanceSquared;
      if (!var3.equals(Vector3dUtil.MIN)) {
         double var7 = var2.distanceSquared(var3);
         if (var7 <= this.distanceSquared) {
            this.distanceSquared = var7;
            class="kw">return;
         }
      }

      this.distanceSquared = Double.MAX_VALUE;

      for (int var12 = 0; var12 < var1.length(); var12++) {
         IPathWaypoint var8 = var1.get(var12);
         if (var8 != null) {
            Vector3d var9 = var8.getWaypointPosition(var4);
            double var10 = var2.distanceSquared(var9);
            if (var10 < this.distanceSquared) {
               this.distanceSquared = var10;
               var3.set(var9);
            }
         }
      }

      if (this.distanceSquared == Double.MAX_VALUE) {
         this.distanceSquared = var5;
      }
   }

   class="kw">protected enum LoadStatus {
      WAITING,
      FAILED,
      SUCCESS;

      LoadStatus() {
      }
   }

   class="kw">public enum PathType class="kw">implements Supplier<String> {
      WorldPath("named world path"),
      CurrentPrefabPath("a path from the prefab the NPC spawned in"),
      AnyPrefabPath("a path from any prefab"),
      TransientPath("a class="kw">transient path (testing purposes only)");

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

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

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