NearbyCountCondition class

Пакет: com.hypixel.hytale.server.npc.decisionmaker.core.conditions

Файл: com/hypixel/hytale/server/npc/decisionmaker/core/conditions/NearbyCountCondition.java

extends: ScaledCurveCondition

Поля (4)

МодификаторыТипИмя
final BuilderCodec<NearbyCountCondition> CODEC
PositionCache var2
NPCEntity var6
PositionCache var7

Методы (5)

МодификаторыВозвратСигнатура
static boolean filterNPCboolean filterNPC(@Nonnull Role var0, Ref<EntityStore> var1, @Nonnull NearbyCountCondition var2, @Nonnull ComponentAccessor<EntityStore> var3)
public String getNpcGroupString getNpcGroup()
public int getNpcGroupIndexint getNpcGroupIndex()
public double getRangedouble getRange()
if if(this.includePlayers)

Исходный код

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

class="kw">import com.hypixel.hytale.builtin.tagset.config.NPCGroup;
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.validation.Validators;
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.Ref;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderManager;
class="kw">import com.hypixel.hytale.server.npc.decisionmaker.core.EvaluationContext;
class="kw">import com.hypixel.hytale.server.npc.decisionmaker.core.conditions.base.ScaledCurveCondition;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import com.hypixel.hytale.server.npc.role.Role;
class="kw">import com.hypixel.hytale.server.npc.role.support.PositionCache;
class="kw">import com.hypixel.hytale.server.npc.role.support.WorldSupport;
class="kw">import javax.annotation.Nonnull;

class="kw">public class NearbyCountCondition class="kw">extends ScaledCurveCondition {
   class="kw">public class="kw">static class="kw">final BuilderCodec<NearbyCountCondition> CODEC = BuilderCodec.builder(
         NearbyCountCondition.class, NearbyCountCondition::new, ScaledCurveCondition.ABSTRACT_CODEC
      )
      .documentation("A scaled curve condition that returns a utility value based on the number of NPCs nearby belonging to a specific **NPCGroup**.")
      .<Double>append(new KeyedCodec<>("Range", Codec.DOUBLE), (var0, var1) -> var0.range = var1, var0 -> var0.range)
      .documentation("The range within which to count NPCs.")
      .addValidator(Validators.nonNull())
      .addValidator(Validators.greaterThan(0.0))
      .add()
      .<String>append(new KeyedCodec<>("NPCGroup", Codec.STRING), (var0, var1) -> var0.npcGroup = var1, var0 -> var0.npcGroup)
      .documentation("The NPCGroup to count NPCs from.")
      .addValidator(Validators.nonNull())
      .addValidator(NPCGroup.VALIDATOR_CACHE.getValidator())
      .add()
      .afterDecode(var0 -> var0.npcGroupIndex = NPCGroup.getAssetMap().getIndex(var0.npcGroup))
      .build();
   class="kw">protected double range;
   class="kw">protected String npcGroup;
   class="kw">protected int npcGroupIndex;
   class="kw">protected boolean includePlayers;

   class="kw">protected NearbyCountCondition() {
   }

   class="kw">public double getRange() {
      class="kw">return this.range;
   }

   class="kw">public String getNpcGroup() {
      class="kw">return this.npcGroup;
   }

   class="kw">public int getNpcGroupIndex() {
      class="kw">return this.npcGroupIndex;
   }

   @Override
   class="kw">public void setupNPC(@Nonnull ExecutionSupport var1) {
      PositionCache var2 = var1.getPositionCache();
      var2.requireEntityDistanceSorted(this.range);
      this.includePlayers = WorldSupport.hasTagInGroup(this.npcGroupIndex, BuilderManager.getPlayerGroupID());
      if (this.includePlayers) {
         var2.requirePlayerDistanceSorted(this.range);
      }
   }

   @Override
   class="kw">protected double getInput(
      int var1, @Nonnull ArchetypeChunk<EntityStore> var2, Ref<EntityStore> var3, CommandBuffer<EntityStore> var4, EvaluationContext var5
   ) {
      NPCEntity var6 = var2.getComponent(var1, NPCEntity.getComponentType());
      assert var6 != null;
      PositionCache var7 = var2.getComponent(var1, PositionCache.getComponentType());
      assert var7 != null;
      class="kw">return var7.countEntitiesInRange(0.0, this.range, this.includePlayers, NearbyCountCondition::filterNPC, var6.getRole(), this, var4);
   }

   class="kw">protected class="kw">static boolean filterNPC(
      @Nonnull Role var0, Ref<EntityStore> var1, @Nonnull NearbyCountCondition var2, @Nonnull ComponentAccessor<EntityStore> var3
   ) {
      class="kw">return WorldSupport.isGroupMember(var0.getRoleIndex(), var1, var2.npcGroupIndex, var3);
   }

   @Nonnull
   @Override
   class="kw">public String toString() {
      class="kw">return "NearbyCountCondition{range=" + this.range + ", npcGroup=" + this.npcGroup + ", npcGroupIndex=" + this.npcGroupIndex + "} " + super.toString();
   }
}