SensorEntityBase.java
package com.hypixel.hytale.server.npc.corecomponents.entity;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.protocol.GameMode;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent;
import com.hypixel.hytale.server.core.modules.entity.player.PlayerSettings;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.asset.builder.ComponentContext;
import com.hypixel.hytale.server.npc.corecomponents.ISensorEntityCollector;
import com.hypixel.hytale.server.npc.corecomponents.ISensorEntityPrioritiser;
import com.hypixel.hytale.server.npc.corecomponents.SensorWithEntityFilters;
import com.hypixel.hytale.server.npc.corecomponents.entity.builders.BuilderSensorEntityBase;
import com.hypixel.hytale.server.npc.entities.NPCEntity;
import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
import com.hypixel.hytale.server.npc.role.Role;
import com.hypixel.hytale.server.npc.sensorinfo.EntityPositionProvider;
com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
com.hypixel.hytale.server.npc.util.IEntityByPriorityFilter;
javax.annotation.Nonnull;
javax.annotation.Nullable;
{
HytaleLogger.forEnclosingClass();
ComponentType<EntityStore, TransformComponent> TRANSFORM_COMPONENT_TYPE = TransformComponent.getComponentType();
ComponentType<EntityStore, NPCEntity> NPC_COMPONENT_TYPE = NPCEntity.getComponentType();
ComponentType<EntityStore, Player> PLAYER_COMPONENT_TYPE = Player.getComponentType();
ComponentType<EntityStore, DeathComponent> DEATH_COMPONENT_TYPE = DeathComponent.getComponentType();
range;
minRange;
useProjectedDistance;
lockOnTarget;
autoUnlockTarget;
onlyLockedTarget;
lockedTargetSlot;
ignoredTargetSlot;
ISensorEntityPrioritiser prioritiser;
IEntityByPriorityFilter npcPrioritiser;
IEntityByPriorityFilter playerPrioritiser;
ISensorEntityCollector collector;
ownRole;
();
{
(builder, builder.getFilters(builderSupport, prioritiser, ComponentContext.SensorEntity));
.range = builder.getRange(builderSupport);
.minRange = builder.getMinRange(builderSupport);
.lockOnTarget = builder.isLockOnTarget(builderSupport);
.autoUnlockTarget = builder.isAutoUnlockTarget(builderSupport);
.onlyLockedTarget = builder.isOnlyLockedTarget(builderSupport);
.useProjectedDistance = builder.isUseProjectedDistance(builderSupport);
.lockedTargetSlot = builder.getLockedTargetSlot(builderSupport);
.ignoredTargetSlot = builder.getIgnoredTargetSlot(builderSupport);
.prioritiser = prioritiser;
.collector = builder.getCollector(builderSupport);
}
{
(!.matches(ref, role, dt, store)) {
.positionProvider.clear();
;
} {
(TransformComponent)store.getComponent(ref, TRANSFORM_COMPONENT_TYPE);
transformComponent != ;
transformComponent.getPosition();
.ownRole = role.getRoleIndex();
(.ignoredTargetSlot == - || .ignoredTargetSlot != .lockedTargetSlot) {
Ref<EntityStore> targetRef = .filterLockedEntity(ref, position, role, store);
(targetRef != ) {
.collector.init(ref, role, store);
(!.collector.terminateOnFirstMatch()) {
.findPlayerOrEntity(ref, position, role, store);
}
.collector.cleanup();
.positionProvider.setTarget(targetRef, store) != ;
}
}
(.onlyLockedTarget) {
.positionProvider.clear();
;
} {
.collector.init(ref, role, store);
Ref<EntityStore> targetRef = .findPlayerOrEntity(ref, position, role, store);
.collector.cleanup();
(targetRef == ) {
.positionProvider.clear();
;
} {
.positionProvider.setTarget(targetRef, store);
(.lockOnTarget) {
role.getMarkedEntitySupport().setMarkedEntity(.lockedTargetSlot, targetRef);
}
;
}
}
}
}
{
.positionProvider.clear();
}
InfoProvider {
.positionProvider;
}
{
.registerWithSupport(role);
(.isGetPlayers()) {
role.getPositionCache().requirePlayerDistanceSorted(.range);
}
(.isGetNPCs()) {
role.getPositionCache().requireEntityDistanceSorted(.range);
}
.prioritiser.registerWithSupport(role);
.collector.registerWithSupport(role);
}
{
.motionControllerChanged(ref, npcComponent, motionController, componentAccessor);
.prioritiser.motionControllerChanged(ref, npcComponent, motionController, componentAccessor);
.collector.motionControllerChanged(ref, npcComponent, motionController, componentAccessor);
}
{
.loaded(role);
.prioritiser.loaded(role);
.collector.loaded(role);
}
{
.spawned(role);
.prioritiser.spawned(role);
.collector.spawned(role);
}
{
.unloaded(role);
.prioritiser.unloaded(role);
.collector.unloaded(role);
}
{
.removed(role);
.prioritiser.removed(role);
.collector.removed(role);
}
{
.teleported(role, from, to);
.prioritiser.teleported(role, from, to);
.collector.teleported(role, from, to);
}
{
.npcPrioritiser = .isGetNPCs() ? .prioritiser.getNPCPrioritiser() : ;
.playerPrioritiser = .isGetPlayers() ? .prioritiser.getPlayerPrioritiser() : ;
}
;
;
{
;
}
Ref<EntityStore> {
Ref<EntityStore> target = .lockedTargetSlot >= ? role.getMarkedEntitySupport().getMarkedEntityRef(.lockedTargetSlot) : ;
(target == ) {
;
} (.filterEntityWithRange(ref, target, position, role, store)) {
target;
} {
(.autoUnlockTarget) {
role.getMarkedEntitySupport().clearMarkedEntity(.lockedTargetSlot);
}
;
}
}
{
(Player)store.getComponent(targetRef, Player.getComponentType());
(playerComponent != ) {
(!.isGetPlayers()) {
;
}
playerComponent.getGameMode();
(gameMode == GameMode.Creative) {
(PlayerSettings)store.getComponent(targetRef, PlayerSettings.getComponentType());
playerSettingsComponent != && playerSettingsComponent.creativeSettings().allowNPCDetection();
(!allowDetection) {
;
}
}
} {
(!store.getArchetype(targetRef).contains(NPC_COMPONENT_TYPE)) {
;
}
(!.isGetNPCs()) {
;
}
}
(TransformComponent)store.getComponent(targetRef, TRANSFORM_COMPONENT_TYPE);
targetTransformComponent != ;
targetTransformComponent.getPosition();
role.getActiveMotionController().getSquaredDistance(position, pos, .useProjectedDistance);
!(squaredDistance < .minRange * .minRange) && !(squaredDistance > .range * .range) ? .filterEntity(ref, targetRef, role, store) : ;
}
{
(store.getArchetype(targetRef).contains(DEATH_COMPONENT_TYPE)) {
;
} {
(NPCEntity)store.getComponent(targetRef, NPC_COMPONENT_TYPE);
.isExcludingOwnType() && npcComponent != && .ownRole == npcComponent.getRoleIndex() ? : .matchesFilters(ref, targetRef, role, store);
}
}
{
.filterPrioritisedEntity(ref, targetRef, role, store, .playerPrioritiser);
}
{
.filterPrioritisedEntity(ref, targetRef, role, store, .npcPrioritiser);
}
{
(!.filterEntity(ref, targetRef, role, store)) {
.collector.collectNonMatching(targetRef, store);
;
} {
playerPrioritiser.test(ref, targetRef, store);
(match) {
.collector.collectMatching(ref, targetRef, store);
} {
.collector.collectNonMatching(targetRef, store);
}
.collector.terminateOnFirstMatch() && match;
}
}
Ref<EntityStore> {
Ref<EntityStore> player = ;
Ref<EntityStore> npc = ;
Ref<EntityStore> ignoredEntity = .ignoredTargetSlot >= ? role.getMarkedEntitySupport().getMarkedEntityRef(.ignoredTargetSlot) : ;
(.isGetPlayers()) {
.playerPrioritiser.init(role);
role.getPositionCache().processPlayersInRange(ref, .minRange, .range, .useProjectedDistance, ignoredEntity, role, (sensorEntityBase, targetRef, role1, ref1) -> sensorEntityBase.filterPrioritisedPlayer(ref1, targetRef, role1, ref1.getStore()), , ref, store);
player = .playerPrioritiser.getHighestPriorityTarget();
.playerPrioritiser.cleanup();
}
(.isGetNPCs()) {
.npcPrioritiser.init(role);
role.getPositionCache().processNPCsInRange(ref, .minRange, .range, .useProjectedDistance, ignoredEntity, role, (sensorEntityBase, targetRef, role1, ref1) -> sensorEntityBase.filterPrioritisedNPC(ref1, targetRef, role1, ref1.getStore()), , ref, store);
npc = .npcPrioritiser.getHighestPriorityTarget();
.npcPrioritiser.cleanup();
}
Ref<EntityStore> target;
(npc == ) {
target = player;
} (player == ) {
target = npc;
} {
target = .prioritiser.pickTarget(ref, role, position, player, npc, .useProjectedDistance, store);
}
target;
}
}