SpectatorSystems class

Пакет: com.hypixel.hytale.server.core.modules.entity.spectator

Файл: com/hypixel/hytale/server/core/modules/entity/spectator/SpectatorSystems.java

Поля (46)

МодификаторыТипИмя
private static final float CAMERA_WALL_MARGIN
final double FOLLOW_RESYNC_DISTANCE_SQ
private static final float MIN_CAMERA_PIVOT_HEIGHT
private static final float MIN_EXIT_STANDOFF
private static final float THIRD_PERSON_CAMERA_DISTANCE
private final Set<Dependency<EntityStore>> dependencies
private final ComponentType<EntityStore, EntityTrackerSystems.EntityViewer> entityViewerComponentType
private final Query<EntityStore> query
private final Query<EntityStore> query
private final ComponentType<EntityStore, Spectating> spectatingComponentType
private final ComponentType<EntityStore, Spectating> spectatingComponentType
private final ComponentType<EntityStore, Spectating> spectatingComponentType
TransformComponent var10
TransformComponent var11
Vector3i var11
Vector3d var12
PlayerRef var2
PlayerRef var2
PlayerRef var3
GameModeType var3
TransformComponent var3
NetworkId var4
ClientCameraView var4
HeadRotation var4
PlayerRef var5
TransformComponent var5
CameraManager var5
Rotation3f var5
Spectating var6
EntityTrackerSystems.EntityViewer var6
Ref var6
CameraManager var6
ServerCameraSettings var6
float var6
Ref var7
Iterator var7
Ref var7
float var7
Vector3d var7
Ref var8
Ref var8
Rotation3f var8
Vector3d var8
PlayerRef var9
double var9
var9

Методы (40)

МодификаторыВозвратСигнатура
public FollowTargetpublic FollowTarget()
public HideFromNonSpectatorspublic HideFromNonSpectators()
public OnSpectatingChangepublic OnSpectatingChange()
private static void applyFollowCameraprivate static void applyFollowCamera(@Nonnull Ref<EntityStore> var0, @Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2)
abstract applyFollowCamera applyFollowCamera(var1, var7, var5)
private static void applyFreeCameraprivate static void applyFreeCamera(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1)
abstract applyFreeCamera applyFreeCamera(var1, var5)
public ComponentType<EntityStore, Spectating> componentTypepublic ComponentType<EntityStore, Spectating> componentType()
private static void detachprivate static void detach(@Nonnull Ref<EntityStore> var0, @Nonnull CommandBuffer<EntityStore> var1)
abstract detach detach(var8, var5)
public Set<Dependency<EntityStore>> getDependenciespublic Set<Dependency<EntityStore>> getDependencies()
public SystemGroup<EntityStore> getGrouppublic SystemGroup<EntityStore> getGroup()
public Query<EntityStore> getQuerypublic Query<EntityStore> getQuery()
public Query<EntityStore> getQuerypublic Query<EntityStore> getQuery()
public Query<EntityStore> getQuerypublic Query<EntityStore> getQuery()
if if(var7 != null)
if if(var10 == null)
if if(var2 != null)
if if(var7 != null)
if if(var5 != null && var6 != null)
if if(var3 != null && var4 != null)
if if(var5 != null)
if if(var7 < 1.0F)
if if(var5 != null)
if if(var2 != null)
if if(var4 != null)
if if(var5 != null)
if if(var3 != null)
if if(var11 != null)
public boolean isParallelpublic boolean isParallel(int var1, int var2)
public boolean isParallelpublic boolean isParallel(int var1, int var2)
static boolean isTargetHiddenboolean isTargetHidden(@Nullable PlayerRef var0, @Nonnull UUID var1)
private static void moveToCameraExitPositionprivate static void moveToCameraExitPosition(@Nonnull Ref<EntityStore> var0, @Nullable Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2)
abstract moveToCameraExitPosition moveToCameraExitPosition(var1, var6, var5)
public void onComponentAddedpublic void onComponentAdded(@Nonnull Ref<EntityStore> var1, @Nonnull Spectating var2, @Nonnull Store<EntityStore> var3, @Nonnull CommandBuffer<EntityStore> var4)
public void onComponentRemovedpublic void onComponentRemoved(@Nonnull Ref<EntityStore> var1, @Nonnull Spectating var2, @Nonnull Store<EntityStore> var3, @Nonnull CommandBuffer<EntityStore> var4)
public void onComponentSetpublic void onComponentSet(@Nonnull Ref<EntityStore> var1, Spectating var2, @Nonnull Spectating var3, @Nonnull Store<EntityStore> var4, @Nonnull CommandBuffer<EntityStore> var5)
public void tickpublic void tick(float var1, int var2, @Nonnull ArchetypeChunk<EntityStore> var3, @Nonnull Store<EntityStore> var4, @Nonnull CommandBuffer<EntityStore> var5)
public void tickpublic void tick(float var1, int var2, @Nonnull Store<EntityStore> var3)
public void tickpublic void tick(float var1, int var2, @Nonnull ArchetypeChunk<EntityStore> var3, @Nonnull Store<EntityStore> var4, @Nonnull CommandBuffer<EntityStore> var5)

Исходный код

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

class="kw">import com.hypixel.hytale.component.ArchetypeChunk;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
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.Store;
class="kw">import com.hypixel.hytale.component.SystemGroup;
class="kw">import com.hypixel.hytale.component.dependency.Dependency;
class="kw">import com.hypixel.hytale.component.dependency.Order;
class="kw">import com.hypixel.hytale.component.dependency.SystemDependency;
class="kw">import com.hypixel.hytale.component.query.Query;
class="kw">import com.hypixel.hytale.component.system.RefChangeSystem;
class="kw">import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.math.vector.Transform;
class="kw">import com.hypixel.hytale.protocol.ApplyLookType;
class="kw">import com.hypixel.hytale.protocol.AttachedToType;
class="kw">import com.hypixel.hytale.protocol.ClientCameraView;
class="kw">import com.hypixel.hytale.protocol.Direction;
class="kw">import com.hypixel.hytale.protocol.Position;
class="kw">import com.hypixel.hytale.protocol.PositionDistanceOffsetType;
class="kw">import com.hypixel.hytale.protocol.RotationType;
class="kw">import com.hypixel.hytale.protocol.ServerCameraSettings;
class="kw">import com.hypixel.hytale.protocol.packets.camera.SetServerCamera;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.gamemode.GameModeType;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.CameraManager;
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.Spectating;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.gamemode.GameModeTypes;
class="kw">import com.hypixel.hytale.server.core.modules.entity.player.CreativeEraserSystems;
class="kw">import com.hypixel.hytale.server.core.modules.entity.teleport.Teleport;
class="kw">import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems;
class="kw">import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.core.util.TargetUtil;
class="kw">import java.util.Collections;
class="kw">import java.util.Iterator;
class="kw">import java.util.Objects;
class="kw">import java.util.Set;
class="kw">import java.util.UUID;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">import org.joml.Vector3i;

class="kw">public class SpectatorSystems {
   class="kw">private class="kw">static class="kw">final double FOLLOW_RESYNC_DISTANCE_SQ = 1024.0;

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

   class="kw">static boolean isTargetHidden(@Nullable PlayerRef var0, @Nonnull UUID var1) {
      class="kw">return var0 != null && var0.getHiddenPlayersManager().isPlayerHidden(var1);
   }

   class="kw">public class="kw">static class FollowTarget class="kw">extends EntityTickingSystem<EntityStore> {
      class="kw">private class="kw">final ComponentType<EntityStore, Spectating> spectatingComponentType = Spectating.getComponentType();
      @Nonnull
      class="kw">private class="kw">final Query<EntityStore> query = Query.and(this.spectatingComponentType, Player.getComponentType(), TransformComponent.getComponentType());

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

      @Nonnull
      @Override
      class="kw">public Query<EntityStore> getQuery() {
         class="kw">return this.query;
      }

      @Override
      class="kw">public boolean isParallel(int var1, int var2) {
         class="kw">return false;
      }

      @Override
      class="kw">public void tick(
         float var1, int var2, @Nonnull ArchetypeChunk<EntityStore> var3, @Nonnull Store<EntityStore> var4, @Nonnull CommandBuffer<EntityStore> var5
      ) {
         Spectating var6 = var3.getComponent(var2, this.spectatingComponentType);
         assert var6 != null;
         Ref var7 = var6.getTargetRef();
         if (var7 != null) {
            Ref var8 = var3.getReferenceTo(var2);
            if (var7.isValid()
               && var7.getStore() == var4
               && !var5.getArchetype(var7).contains(DeathComponent.getComponentType())
               && !var5.getArchetype(var7).contains(this.spectatingComponentType)) {
               PlayerRef var9 = var5.getComponent(var7, PlayerRef.getComponentType());
               if (var9 != null && SpectatorSystems.isTargetHidden(var5.getComponent(var8, PlayerRef.getComponentType()), var9.getUuid())) {
                  detach(var8, var5);
               } else {
                  TransformComponent var10 = var5.getComponent(var7, TransformComponent.getComponentType());
                  if (var10 == null) {
                     detach(var8, var5);
                  } else {
                     TransformComponent var11 = var3.getComponent(var2, TransformComponent.getComponentType());
                     assert var11 != null;
                     if (var11.getPosition().distanceSquared(var10.getPosition()) > 1024.0) {
                        var5.putComponent(var8, Teleport.getComponentType(), Teleport.createForPlayer(var10.getPosition(), var10.getRotation()));
                     }
                  }
               }
            } else {
               detach(var8, var5);
            }
         }
      }

      class="kw">private class="kw">static void detach(@Nonnull Ref<EntityStore> var0, @Nonnull CommandBuffer<EntityStore> var1) {
         var1.putComponent(var0, Spectating.getComponentType(), new Spectating());
         PlayerRef var2 = var1.getComponent(var0, PlayerRef.getComponentType());
         if (var2 != null) {
            var2.sendMessage(Message.translation("server.commands.spectate.targetLost"));
         }
      }
   }

   class="kw">public class="kw">static class HideFromNonSpectators class="kw">extends EntityTickingSystem<EntityStore> {
      class="kw">private class="kw">final ComponentType<EntityStore, EntityTrackerSystems.EntityViewer> entityViewerComponentType = EntityTrackerSystems.EntityViewer.getComponentType();
      class="kw">private class="kw">final ComponentType<EntityStore, Spectating> spectatingComponentType = Spectating.getComponentType();
      @Nonnull
      class="kw">private class="kw">final Query<EntityStore> query = Query.and(this.entityViewerComponentType, Player.getComponentType(), Query.not(this.spectatingComponentType));
      @Nonnull
      class="kw">private class="kw">final Set<Dependency<EntityStore>> dependencies = Collections.singleton(
         new SystemDependency<>(Order.AFTER, EntityTrackerSystems.CollectVisible.class)
      );

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

      @Nullable
      @Override
      class="kw">public SystemGroup<EntityStore> getGroup() {
         class="kw">return EntityTrackerSystems.FIND_VISIBLE_ENTITIES_GROUP;
      }

      @Nonnull
      @Override
      class="kw">public Set<Dependency<EntityStore>> getDependencies() {
         class="kw">return this.dependencies;
      }

      @Nonnull
      @Override
      class="kw">public Query<EntityStore> getQuery() {
         class="kw">return this.query;
      }

      @Override
      class="kw">public boolean isParallel(int var1, int var2) {
         class="kw">return EntityTickingSystem.maybeUseParallel(var1, var2);
      }

      @Override
      class="kw">public void tick(float var1, int var2, @Nonnull Store<EntityStore> var3) {
         if (var3.getEntityCountFor(this.spectatingComponentType) != 0) {
            super.tick(var1, var2, var3);
         }
      }

      @Override
      class="kw">public void tick(
         float var1, int var2, @Nonnull ArchetypeChunk<EntityStore> var3, @Nonnull Store<EntityStore> var4, @Nonnull CommandBuffer<EntityStore> var5
      ) {
         EntityTrackerSystems.EntityViewer var6 = var3.getComponent(var2, this.entityViewerComponentType);
         assert var6 != null;
         Iterator var7 = var6.visible.iterator();

         while (var7.hasNext()) {
            Ref var8 = var7.next();
            if (!var8.isValid()) {
               var7.remove();
            } else if (var5.getArchetype(var8).contains(this.spectatingComponentType)) {
               var6.hiddenCount++;
               var7.remove();
            }
         }
      }
   }

   class="kw">public class="kw">static class OnSpectatingChange class="kw">extends RefChangeSystem<EntityStore, Spectating> {
      class="kw">private class="kw">static class="kw">final float THIRD_PERSON_CAMERA_DISTANCE = 4.0F;
      class="kw">private class="kw">static class="kw">final float MIN_CAMERA_PIVOT_HEIGHT = 1.0F;
      class="kw">private class="kw">static class="kw">final float MIN_EXIT_STANDOFF = 0.5F;
      class="kw">private class="kw">static class="kw">final float CAMERA_WALL_MARGIN = 1.0F;
      class="kw">private class="kw">final ComponentType<EntityStore, Spectating> spectatingComponentType = Spectating.getComponentType();

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

      @Nonnull
      @Override
      class="kw">public Query<EntityStore> getQuery() {
         class="kw">return Player.getComponentType();
      }

      @Nonnull
      @Override
      class="kw">public ComponentType<EntityStore, Spectating> componentType() {
         class="kw">return this.spectatingComponentType;
      }

      class="kw">public void onComponentAdded(
         @Nonnull Ref<EntityStore> var1, @Nonnull Spectating var2, @Nonnull Store<EntityStore> var3, @Nonnull CommandBuffer<EntityStore> var4
      ) {
         if (var2.getTargetRef() != null) {
            applyFollowCamera(var1, var2.getTargetRef(), var4);
         }
      }

      class="kw">public void onComponentSet(
         @Nonnull Ref<EntityStore> var1, Spectating var2, @Nonnull Spectating var3, @Nonnull Store<EntityStore> var4, @Nonnull CommandBuffer<EntityStore> var5
      ) {
         Ref var6 = var2 != null ? var2.getTargetRef() : null;
         Ref var7 = var3.getTargetRef();
         if (!Objects.equals(var6, var7)) {
            if (var7 != null) {
               applyFollowCamera(var1, var7, var5);
            } else {
               moveToCameraExitPosition(var1, var6, var5);
               applyFreeCamera(var1, var5);
            }
         }
      }

      class="kw">public void onComponentRemoved(
         @Nonnull Ref<EntityStore> var1, @Nonnull Spectating var2, @Nonnull Store<EntityStore> var3, @Nonnull CommandBuffer<EntityStore> var4
      ) {
         CreativeEraserSystems.refresh(var1, var4);
         if (var2.getTargetRef() != null) {
            moveToCameraExitPosition(var1, var2.getTargetRef(), var4);
            PlayerRef var5 = var4.getComponent(var1, PlayerRef.getComponentType());
            CameraManager var6 = var4.getComponent(var1, CameraManager.getComponentType());
            if (var5 != null && var6 != null) {
               var6.resetCamera(var5);
            }
         }
      }

      class="kw">private class="kw">static void applyFollowCamera(@Nonnull Ref<EntityStore> var0, @Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
         PlayerRef var3 = var2.getComponent(var0, PlayerRef.getComponentType());
         NetworkId var4 = var2.getComponent(var1, NetworkId.getComponentType());
         if (var3 != null && var4 != null) {
            TransformComponent var5 = var2.getComponent(var1, TransformComponent.getComponentType());
            if (var5 != null) {
               var2.putComponent(var0, Teleport.getComponentType(), Teleport.createForPlayer(var5.getPosition(), var5.getRotation()));
            }

            ServerCameraSettings var6 = new ServerCameraSettings();
            var6.attachedToType = AttachedToType.EntityId;
            var6.attachedToEntityId = var4.getId();
            var6.followAttachedEntity = true;
            var6.eyeOffset = true;
            var6.isFirstPerson = false;
            float var7 = ModelComponent.getEyeHeight(var1, var2);
            if (var7 < 1.0F) {
               var6.positionOffset = new Position(0.0, 1.0F - var7, 0.0);
            }

            var6.positionDistanceOffsetType = PositionDistanceOffsetType.DistanceOffsetRaycast;
            var6.distance = 4.0F;
            var6.rotationType = RotationType.Custom;
            var6.applyLookType = ApplyLookType.Rotation;
            if (var5 != null) {
               Rotation3f var8 = var5.getRotation();
               var6.rotation = new Direction(var8.yaw(), var8.pitch(), var8.roll());
            }

            var3.getPacketHandler().writeNoCache(new SetServerCamera(ClientCameraView.Custom, true, var6));
         }
      }

      class="kw">private class="kw">static void applyFreeCamera(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1) {
         PlayerRef var2 = var1.getComponent(var0, PlayerRef.getComponentType());
         if (var2 != null) {
            GameModeType var3 = GameModeTypes.getCurrentType(var0, var1);
            ClientCameraView var4 = var3 != null ? var3.getLockedCameraView() : null;
            if (var4 != null) {
               var2.getPacketHandler().writeNoCache(new SetServerCamera(var4, true, null));
            } else {
               CameraManager var5 = var1.getComponent(var0, CameraManager.getComponentType());
               if (var5 != null) {
                  var5.resetCamera(var2);
               }
            }
         }
      }

      class="kw">private class="kw">static void moveToCameraExitPosition(
         @Nonnull Ref<EntityStore> var0, @Nullable Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2
      ) {
         if (var1 != null && var1.isValid() && var1.getStore() == var0.getStore()) {
            TransformComponent var3 = var2.getComponent(var1, TransformComponent.getComponentType());
            if (var3 != null) {
               HeadRotation var4 = var2.getComponent(var0, HeadRotation.getComponentType());
               Rotation3f var5 = var4 != null ? var4.getRotation() : var3.getRotation();
               float var6 = Math.max(ModelComponent.getEyeHeight(var1, var2), 1.0F);
               Vector3d var7 = new Vector3d(var3.getPosition()).add(0.0, var6, 0.0);
               Vector3d var8 = Transform.getDirection(var5.pitch(), var5.yaw()).negate();
               double var9 = 4.0;
               Vector3i var11 = TargetUtil.getTargetBlock(
                  var2.getExternalData().getWorld(), (var0x, var1x) -> BlockType.blocksLineOfSight(var0x), var7.x, var7.y, var7.z, var8.x, var8.y, var8.z, 4.0
               );
               if (var11 != null) {
                  var9 = Math.max(0.5, new Vector3d(var11.x + 0.5, var11.y + 0.5, var11.z + 0.5).distance(var7) - 1.0);
               }

               Vector3d var12 = new Vector3d(var8).mul(var9).add(var7);
               var2.putComponent(var0, Teleport.getComponentType(), Teleport.createForPlayer(var12, var5));
            }
         }
      }
   }
}