WorldSupport class

Пакет: com.hypixel.hytale.server.npc.role.support

Файл: com/hypixel/hytale/server/npc/role/support/WorldSupport.java

implements: Component<EntityStore>

Поля (34)

МодификаторыТипИмя
final double ATTITUDE_CACHE_CLEAR_FREQUENCY
boolean var1
int[] var1
WorldSupport var2
ObjectIterator var2
IntList var2
ObjectIterator var2
ItemAttitudeMap var2
AttitudeMemoryEntry var2
IndexedLookupTableAssetMap var2
AttitudeMemoryEntry var3
Int2ObjectOpenHashMap var3
Entry var3
TransformComponent var3
WeatherResource var3
Attitude var4
var4
Ref var4
int var4
int var4
var4
var4
var4
String var4
NPCEntity var5
World var5
NPCEntity var5
int var5
int var6
Store var6
PositionCache var6
ChunkSection var7
Ref var8
BlockChunk var9

Методы (49)

МодификаторыВозвратСигнатура
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("Unknown npc group! " + var4)
public boolean consumeNewPathRequestedboolean consumeNewPathRequested()
static int[] createTagSetIndexArrayint[] createTagSetIndexArray(@Nullable String[] var0)
for for(Vector3d var4 : this.searchRayCachedPositions)
for for(int var7 : var2)
for for(int var3 = 0; var3 < var0.length; var3++)
for for(int var2 = 0; var2 < this.searchRayCachedPositions.length; var2++)
abstract for for(int var4 = 0; var4 < var2.size()
public int getAttitudeGroupint getAttitudeGroup()
public String getBlockToPlaceString getBlockToPlace()
public BlockTarget getCachedBlockTargetBlockTarget getCachedBlockTarget(int var1)
public Vector3d getCachedSearchRayPositionVector3d getCachedSearchRayPosition(int var1)
public int getCurrentWeatherIndexint getCurrentWeatherIndex(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2)
public Attitude getDefaultNPCAttitudeAttitude getDefaultNPCAttitude()
public Attitude getDefaultPlayerAttitudeAttitude getDefaultPlayerAttitude()
public int getEnvironmentIdint getEnvironmentId(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2)
public int getItemAttitudeGroupint getItemAttitudeGroup()
public boolean hasRequestedNewPathboolean hasRequestedNewPath()
static boolean hasTagInGroupboolean hasTagInGroup(int var0, int var1)
if if(this.searchRayCachedPositions != null)
if if(this.blockSensorCachedTargets != null)
if if(var4 != null)
if if(this.attitudeView == null)
if if(this.attitudeCache != null)
if if(this.attitudeOverrideMemory == null)
if if(this.attitudeCache == null)
if if(this.environmentIdChangeCount != this.changeCount)
if if(this.weatherChangeCount != this.changeCount)
if if(this.cachedWeatherIndex != 0)
if if(var4 == Integer.MIN_VALUE)
if if(var2 == null)
if if(var5 != null)
if if(var0 == null)
if if(var5 == Integer.MIN_VALUE)
if if(this.searchRayCachedPositions != null)
if if(this.attitudeOverrideMemory != null)
static boolean isGroupMemberboolean isGroupMember(int var0, @Nonnull Ref<EntityStore> var1, @Nullable int[] var2, @Nonnull ComponentAccessor<EntityStore> var3)
static boolean isGroupMemberboolean isGroupMember(int var0, @Nullable Ref<EntityStore> var1, int var2, @Nonnull ComponentAccessor<EntityStore> var3)
public void overrideAttitudevoid overrideAttitude(Ref<EntityStore> var1, Attitude var2, double var3)
public void postRoleBuiltvoid postRoleBuilt(@Nonnull BuilderSupport var1)
public void requestNewPathvoid requestNewPath()
public void requireAttitudeCachevoid requireAttitudeCache()
public void resetAllBlockSensorsvoid resetAllBlockSensors(@Nonnull Ref<EntityStore> var1)
public void resetAllCachedSearchRayPositionsvoid resetAllCachedSearchRayPositions()
public void resetBlockSensorFoundBlockvoid resetBlockSensorFoundBlock(@Nonnull Ref<EntityStore> var1, int var2)
public void resetCachedSearchRayPositionvoid resetCachedSearchRayPosition(int var1)
public void setBlockToPlacevoid setBlockToPlace(String var1)
public void tickvoid tick(float var1)
public void unloadedvoid unloaded(@Nonnull Ref<EntityStore> var1)

Исходный код

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

class="kw">import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap;
class="kw">import com.hypixel.hytale.builtin.tagset.TagSetPlugin;
class="kw">import com.hypixel.hytale.builtin.tagset.config.NPCGroup;
class="kw">import com.hypixel.hytale.builtin.weather.resources.WeatherResource;
class="kw">import com.hypixel.hytale.component.Component;
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.math.vector.Vector3dUtil;
class="kw">import com.hypixel.hytale.server.core.asset.type.attitude.Attitude;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.BlockChunk;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.ChunkSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
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.BuilderManager;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.SupportConfigBuilder;
class="kw">import com.hypixel.hytale.server.npc.blackboard.Blackboard;
class="kw">import com.hypixel.hytale.server.npc.blackboard.view.attitude.AttitudeView;
class="kw">import com.hypixel.hytale.server.npc.blackboard.view.attitude.ItemAttitudeMap;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.BlockTarget;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.util.AttitudeMemoryEntry;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
class="kw">import it.unimi.dsi.fastutil.ints.IntList;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectIterator;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class WorldSupport class="kw">implements Component<EntityStore> {
   class="kw">public class="kw">static class="kw">final double ATTITUDE_CACHE_CLEAR_FREQUENCY = 0.1;
   class="kw">protected Int2ObjectMap<BlockTarget> blockSensorCachedTargets;
   @Nullable
   class="kw">protected Vector3d[] searchRayCachedPositions;
   class="kw">protected String blockToPlace;
   class="kw">protected class="kw">final Attitude defaultPlayerAttitude;
   class="kw">protected class="kw">final Attitude defaultNPCAttitude;
   class="kw">protected class="kw">final int attitudeGroup;
   class="kw">protected class="kw">final int itemAttitudeGroup;
   class="kw">protected AttitudeView attitudeView;
   class="kw">protected Int2ObjectMap<Attitude> attitudeCache;
   class="kw">protected Int2ObjectMap<AttitudeMemoryEntry> attitudeOverrideMemory;
   class="kw">protected double nextAttitudeCacheClear = 0.1;
   class="kw">protected boolean newPathRequested;
   class="kw">protected int changeCount;
   class="kw">protected int environmentIdChangeCount;
   class="kw">protected int cachedEnvironmentId = Integer.MIN_VALUE;
   class="kw">protected int weatherChangeCount;
   class="kw">protected int cachedWeatherIndex;

   @Nonnull
   class="kw">public class="kw">static ComponentType<EntityStore, WorldSupport> getComponentType() {
      class="kw">return NPCPlugin.get().getWorldSupportComponentType();
   }

   @Nonnull
   class="kw">public class="kw">static WorldSupport get(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1) {
      WorldSupport var2 = var1.getComponent(var0, getComponentType());
      assert var2 != null : "Missing WorldSupport on entity " + var0;
      class="kw">return var2;
   }

   class="kw">public WorldSupport(@Nonnull SupportConfigBuilder<?> var1, @Nonnull BuilderSupport var2) {
      this.defaultPlayerAttitude = var1.getDefaultPlayerAttitude(var2);
      this.defaultNPCAttitude = var1.getDefaultNPCAttitude(var2);
      this.attitudeGroup = var1.getAttitudeGroup(var2);
      this.itemAttitudeGroup = var1.getItemAttitudeGroup(var2);
   }

   class="kw">public void tick(float var1) {
      if (this.attitudeOverrideMemory != null && !this.attitudeOverrideMemory.isEmpty()) {
         ObjectIterator var2 = this.attitudeOverrideMemory.values().iterator();

         while (var2.hasNext()) {
            AttitudeMemoryEntry var3 = (AttitudeMemoryEntry)var2.next();
            var3.tick(var1);
            if (var3.isExpired()) {
               var2.remove();
            }
         }
      }

      if (this.attitudeCache != null && (this.nextAttitudeCacheClear -= var1) <= 0.0) {
         this.attitudeCache.clear();
         this.nextAttitudeCacheClear = 0.1;
      }

      this.changeCount++;
   }

   class="kw">public void postRoleBuilt(@Nonnull BuilderSupport var1) {
      if (var1.requiresBlockTypeBlackboard()) {
         IntList var2 = var1.getBlockTypeBlackboardBlockSets();
         Int2ObjectOpenHashMap var3 = new Int2ObjectOpenHashMap(var2.size());

         for (int var4 = 0; var4 < var2.size(); var4++) {
            var3.put(var2.getInt(var4), new BlockTarget());
         }

         var3.trim();
         this.blockSensorCachedTargets = Int2ObjectMaps.unmodifiable(var3);
      }

      if (var1.requiresAttitudeOverrideMemory()) {
         this.attitudeOverrideMemory = new Int2ObjectOpenHashMap();
      }

      this.searchRayCachedPositions = var1.allocateSearchRayPositionSlots();
      if (this.searchRayCachedPositions != null) {
         this.resetAllCachedSearchRayPositions();
      }
   }

   class="kw">public BlockTarget getCachedBlockTarget(int var1) {
      class="kw">return (BlockTarget)this.blockSensorCachedTargets.get(var1);
   }

   class="kw">public void resetBlockSensorFoundBlock(@Nonnull Ref<EntityStore> var1, int var2) {
      ((BlockTarget)this.blockSensorCachedTargets.get(var2)).reset(var1);
   }

   class="kw">public void resetAllBlockSensors(@Nonnull Ref<EntityStore> var1) {
      if (this.blockSensorCachedTargets != null) {
         ObjectIterator var2 = Int2ObjectMaps.fastIterator(this.blockSensorCachedTargets);

         while (var2.hasNext()) {
            Entry var3 = (Entry<BlockTarget>)var2.next();
            ((BlockTarget)var3.getValue()).reset(var1);
         }
      }
   }

   class="kw">public Vector3d getCachedSearchRayPosition(int var1) {
      class="kw">return this.searchRayCachedPositions[var1];
   }

   class="kw">public void resetCachedSearchRayPosition(int var1) {
      this.searchRayCachedPositions[var1].set(Vector3dUtil.MIN);
   }

   class="kw">public void resetAllCachedSearchRayPositions() {
      for (Vector3d var4 : this.searchRayCachedPositions) {
         var4.set(Vector3dUtil.MIN);
      }
   }

   class="kw">public void setBlockToPlace(String var1) {
      this.blockToPlace = var1;
   }

   class="kw">public String getBlockToPlace() {
      class="kw">return this.blockToPlace;
   }

   class="kw">public Attitude getDefaultPlayerAttitude() {
      class="kw">return this.defaultPlayerAttitude;
   }

   class="kw">public Attitude getDefaultNPCAttitude() {
      class="kw">return this.defaultNPCAttitude;
   }

   class="kw">public int getAttitudeGroup() {
      class="kw">return this.attitudeGroup;
   }

   class="kw">public int getItemAttitudeGroup() {
      class="kw">return this.itemAttitudeGroup;
   }

   @Nonnull
   class="kw">public Attitude getAttitude(@Nonnull Ref<EntityStore> var1, @Nonnull Ref<EntityStore> var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      Attitude var4 = (Attitude)this.attitudeCache.getOrDefault(var2.getIndex(), null);
      if (var4 != null) {
         class="kw">return var4;
      }

      if (this.attitudeView == null) {
         this.attitudeView = var3.getResource(Blackboard.getResourceType()).getView(AttitudeView.class, var1, var3);
      } else {
         this.attitudeView = this.attitudeView.getUpdatedView(var1, var3);
      }

      NPCEntity var5 = var3.getComponent(var1, NPCEntity.getComponentType());
      int var6 = var5 != null ? var5.getRoleIndex() : -1;
      var4 = this.attitudeView.getAttitude(var1, var6, var2, var3);
      this.attitudeCache.put(var2.getIndex(), var4);
      class="kw">return var4;
   }

   @Nullable
   class="kw">public Attitude getItemAttitude(@Nullable ItemStack var1) {
      ItemAttitudeMap var2 = NPCPlugin.get().getItemAttitudeMap();
      class="kw">return var2.getAttitude(this.itemAttitudeGroup, var1);
   }

   class="kw">public void overrideAttitude(Ref<EntityStore> var1, Attitude var2, double var3) {
      this.attitudeOverrideMemory.put(var1.getIndex(), new AttitudeMemoryEntry(var2, var3));
      if (this.attitudeCache != null) {
         this.attitudeCache.remove(var1.getIndex());
      }
   }

   @Nullable
   class="kw">public Attitude getOverriddenAttitude(Ref<EntityStore> var1) {
      if (this.attitudeOverrideMemory == null) {
         class="kw">return null;
      }

      AttitudeMemoryEntry var2 = (AttitudeMemoryEntry)this.attitudeOverrideMemory.get(var1.getIndex());
      class="kw">return var2 == null ? null : var2.getAttitudeOverride();
   }

   class="kw">public void requireAttitudeCache() {
      if (this.attitudeCache == null) {
         this.attitudeCache = new Int2ObjectOpenHashMap();
      }
   }

   class="kw">public void requestNewPath() {
      this.newPathRequested = true;
   }

   class="kw">public boolean hasRequestedNewPath() {
      class="kw">return this.newPathRequested;
   }

   class="kw">public boolean consumeNewPathRequested() {
      boolean var1 = this.newPathRequested;
      this.newPathRequested = false;
      class="kw">return var1;
   }

   class="kw">public int getEnvironmentId(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
      if (this.environmentIdChangeCount != this.changeCount) {
         this.environmentIdChangeCount = this.changeCount;
         TransformComponent var3 = var2.getComponent(var1, TransformComponent.getComponentType());
         assert var3 != null;
         Ref var4 = var3.getSectionRef();
         if (var4 == null || !var4.isValid()) {
            class="kw">return Integer.MIN_VALUE;
         }

         World var5 = var2.getExternalData().getWorld();
         Store var6 = var5.getChunkStore().getStore();
         ChunkSection var7 = var6.getComponent(var4, ChunkSection.getComponentType());
         assert var7 != null;
         Ref var8 = var7.getChunkColumnReference();
         if (var8 == null || !var8.isValid()) {
            class="kw">return Integer.MIN_VALUE;
         }

         BlockChunk var9 = var6.getComponent(var8, BlockChunk.getComponentType());
         assert var9 != null;
         this.cachedEnvironmentId = var9.getEnvironment(var3.getPosition());
      }

      class="kw">return this.cachedEnvironmentId;
   }

   class="kw">public int getCurrentWeatherIndex(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
      if (this.weatherChangeCount != this.changeCount) {
         this.weatherChangeCount = this.changeCount;
         WeatherResource var3 = var2.getResource(WeatherResource.getResourceType());
         this.cachedWeatherIndex = var3.getForcedWeatherIndex();
         if (this.cachedWeatherIndex != 0) {
            class="kw">return this.cachedWeatherIndex;
         }

         int var4 = this.getEnvironmentId(var1, var2);
         if (var4 == Integer.MIN_VALUE) {
            class="kw">return this.cachedWeatherIndex = 0;
         }

         this.cachedWeatherIndex = var3.getWeatherIndexForEnvironment(var4);
      }

      class="kw">return this.cachedWeatherIndex;
   }

   class="kw">public class="kw">static boolean hasTagInGroup(int var0, int var1) {
      class="kw">return TagSetPlugin.get(NPCGroup.class).tagInSet(var0, var1);
   }

   class="kw">public class="kw">static boolean isGroupMember(int var0, @Nonnull Ref<EntityStore> var1, @Nullable int[] var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      if (var2 == null) {
         class="kw">return false;
      }

      for (int var7 : var2) {
         if (isGroupMember(var0, var1, var7, var3)) {
            class="kw">return true;
         }
      }

      class="kw">return false;
   }

   class="kw">public class="kw">static boolean isGroupMember(int var0, @Nullable Ref<EntityStore> var1, int var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      if (var1 != null && var1.isValid()) {
         NPCEntity var5 = var3.getComponent(var1, NPCEntity.getComponentType());
         int var4;
         if (var5 != null) {
            var4 = var5.getRoleIndex();
         } else if (var3.getArchetype(var1).contains(Player.getComponentType())) {
            var4 = BuilderManager.getPlayerGroupID();
         } else {
            PositionCache var6 = var3.getComponent(var1, PositionCache.getComponentType());
            if (var6 == null || var6.getRoleIndex() < 0) {
               class="kw">return false;
            }

            var4 = var6.getRoleIndex();
         }

         class="kw">return var4 == var0 && hasTagInGroup(var2, BuilderManager.getSelfGroupID()) ? true : hasTagInGroup(var2, var4);
      } else {
         class="kw">return false;
      }
   }

   class="kw">public class="kw">static int[] createTagSetIndexArray(@Nullable String[] var0) {
      if (var0 == null) {
         class="kw">return null;
      }

      int[] var1 = new int[var0.length];
      IndexedLookupTableAssetMap var2 = NPCGroup.getAssetMap();

      for (int var3 = 0; var3 < var0.length; var3++) {
         String var4 = var0[var3];
         int var5 = var2.getIndex(var4);
         if (var5 == Integer.MIN_VALUE) {
            throw new IllegalArgumentException("Unknown npc group! " + var4);
         }

         var1[var3] = var5;
      }

      class="kw">return var1;
   }

   class="kw">public void unloaded(@Nonnull Ref<EntityStore> var1) {
      this.resetAllBlockSensors(var1);
      if (this.searchRayCachedPositions != null) {
         for (int var2 = 0; var2 < this.searchRayCachedPositions.length; var2++) {
            this.resetCachedSearchRayPosition(var2);
         }
      }

      if (this.attitudeOverrideMemory != null) {
         this.attitudeOverrideMemory.clear();
      }
   }

   @Override
   class="kw">public Component<EntityStore> clone() {
      class="kw">return this;
   }
}