MarkedEntitySupport class

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

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

implements: Component<EntityStore>

Поля (19)

МодификаторыТипИмя
MarkedEntitySupport var1
MarkedEntitySupport var2
Object2IntMap var2
String var2
String var2
Iterator var2
int var2
Ref var2
int var2
int var3
Entry var3
String var4
int var4
NPCEntity var4
int var5
UUIDComponent var5
Ref var5
Ref var5
Ref var6

Методы (32)

МодификаторыВозвратСигнатура
private void captureRebindvoid captureRebind(int var1, @Nonnull Ref<EntityStore> var2, @Nonnull ComponentAccessor<EntityStore> var3)
public void clearMarkedEntityvoid clearMarkedEntity(int var1)
public void flockSetTargetvoid flockSetTarget(@Nonnull Ref<EntityStore> var1, @Nonnull String var2, @Nullable Ref<EntityStore> var3, @Nonnull Store<EntityStore> var4)
public Ref<EntityStore>[] getEntityTargetsRef<EntityStore>[] getEntityTargets()
public int getMarkedEntitySlotCountint getMarkedEntitySlotCount()
public String getSlotNameString getSlotName(int var1)
public Vector3d getStoredPositionVector3d getStoredPosition(int var1)
public boolean hasMarkedEntityboolean hasMarkedEntity(@Nonnull Ref<EntityStore> var1, int var2)
public boolean hasMarkedEntityInSlotboolean hasMarkedEntityInSlot(String var1)
public boolean hasMarkedEntityInSlotboolean hasMarkedEntityInSlot(int var1)
if if(var2 != null)
if if(var3 >= 0)
if if(var5 >= 0)
if if(var3)
if if(this.slotToNameMap != null)
if if(var4 != null)
if if(var5 != null)
if if(var2 != null)
if if(var4 < 0)
if if(var5 != null)
if if(var4 != null)
private void initEmptyvoid initEmpty()
public boolean isRebindSlotboolean isRebindSlot(int var1)
public void postRoleBuildervoid postRoleBuilder(@Nonnull BuilderSupport var1)
private void removeRebindvoid removeRebind(int var1)
public void resolveRebindsvoid resolveRebinds(@Nonnull ComponentAccessor<EntityStore> var1)
public void setMarkedEntityvoid setMarkedEntity(String var1, Ref<EntityStore> var2)
public void setMarkedEntityvoid setMarkedEntity(int var1, @Nullable Ref<EntityStore> var2)
public void setMarkedEntityvoid setMarkedEntity(String var1, Ref<EntityStore> var2, boolean var3, @Nonnull ComponentAccessor<EntityStore> var4)
public void setMarkedEntityvoid setMarkedEntity(int var1, @Nullable Ref<EntityStore> var2, boolean var3, @Nonnull ComponentAccessor<EntityStore> var4)
public void setTargetSlotToIgnoreForAvoidancevoid setTargetSlotToIgnoreForAvoidance(int var1)
public void unloadedvoid unloaded()

Исходный код

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

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.codecs.map.MapCodec;
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.server.core.entity.UUIDComponent;
class="kw">import com.hypixel.hytale.server.core.entity.group.EntityGroup;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.flock.FlockPlugin;
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.entities.NPCEntity;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntMap;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
class="kw">import java.util.Arrays;
class="kw">import java.util.HashMap;
class="kw">import java.util.Iterator;
class="kw">import java.util.Map;
class="kw">import java.util.UUID;
class="kw">import java.util.Map.Entry;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class MarkedEntitySupport class="kw">implements Component<EntityStore> {
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<MarkedEntitySupport> CODEC = BuilderCodec.builder(MarkedEntitySupport.class, MarkedEntitySupport::new)
      .append(
         new KeyedCodec<>("RebindTargets", new MapCodec<>(Codec.UUID_BINARY, HashMap::new, false)),
         (var0, var1) -> var0.rebindUuids = var1,
         var0 -> var0.rebindUuids.isEmpty() ? null : var0.rebindUuids
      )
      .add()
      .build();
   class="kw">public class="kw">static class="kw">final String DEFAULT_TARGET_SLOT = "LockedTarget";
   @Nullable
   class="kw">protected class="kw">static class="kw">final ComponentType<EntityStore, NPCEntity> NPC_COMPONENT_TYPE = NPCEntity.getComponentType();
   @Nonnull
   class="kw">private class="kw">static class="kw">final Object2IntMap<String> EMPTY_TARGET_SLOT_MAP = new Object2IntOpenHashMap(0);
   class="kw">protected Object2IntMap<String> targetSlotMappings;
   @Nullable
   class="kw">protected Int2ObjectMap<String> slotToNameMap;
   class="kw">protected Ref<EntityStore>[] entityTargets;
   @Nullable
   class="kw">protected Vector3d[] storedPositions;
   @Nonnull
   class="kw">protected Map<String, UUID> rebindUuids = new HashMap<>();
   class="kw">protected int defaultTargetSlot;
   class="kw">protected int targetSlotToIgnoreForAvoidance = Integer.MIN_VALUE;

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

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

   class="kw">public MarkedEntitySupport() {
      this.initEmpty();
   }

   class="kw">private void initEmpty() {
      this.targetSlotMappings = EMPTY_TARGET_SLOT_MAP;
      this.slotToNameMap = null;
      this.entityTargets = (Ref<EntityStore>[])Ref.EMPTY_ARRAY;
      this.defaultTargetSlot = Integer.MIN_VALUE;
      this.targetSlotToIgnoreForAvoidance = Integer.MIN_VALUE;
   }

   class="kw">public Ref<EntityStore>[] getEntityTargets() {
      class="kw">return this.entityTargets;
   }

   class="kw">public void postRoleBuilder(@Nonnull BuilderSupport var1) {
      Object2IntMap var2 = var1.getTargetSlotMappings();
      if (var2 != null) {
         this.targetSlotMappings = var2;
         this.slotToNameMap = var1.getTargetSlotToNameMap();
         this.entityTargets = new Ref[this.targetSlotMappings.size()];
         this.defaultTargetSlot = this.targetSlotMappings.getInt("LockedTarget");
      } else {
         this.targetSlotMappings = EMPTY_TARGET_SLOT_MAP;
         this.slotToNameMap = null;
         this.entityTargets = (Ref<EntityStore>[])Ref.EMPTY_ARRAY;
         this.defaultTargetSlot = Integer.MIN_VALUE;
      }

      this.storedPositions = var1.allocatePositionSlots();
      this.targetSlotToIgnoreForAvoidance = this.defaultTargetSlot;
   }

   class="kw">public void clearMarkedEntity(int var1) {
      this.entityTargets[var1] = null;
      this.removeRebind(var1);
   }

   class="kw">public void setMarkedEntity(String var1, Ref<EntityStore> var2) {
      int var3 = this.targetSlotMappings.getInt(var1);
      if (var3 >= 0) {
         this.setMarkedEntity(var3, var2);
      }
   }

   class="kw">public void setMarkedEntity(int var1, @Nullable Ref<EntityStore> var2) {
      if (var2 != null && var2.isValid()) {
         this.entityTargets[var1] = var2;
         this.removeRebind(var1);
      } else {
         this.clearMarkedEntity(var1);
      }
   }

   class="kw">public void setMarkedEntity(String var1, Ref<EntityStore> var2, boolean var3, @Nonnull ComponentAccessor<EntityStore> var4) {
      int var5 = this.targetSlotMappings.getInt(var1);
      if (var5 >= 0) {
         this.setMarkedEntity(var5, var2, var3, var4);
      }
   }

   class="kw">public void setMarkedEntity(int var1, @Nullable Ref<EntityStore> var2, boolean var3, @Nonnull ComponentAccessor<EntityStore> var4) {
      if (var2 != null && var2.isValid()) {
         this.entityTargets[var1] = var2;
         if (var3) {
            this.captureRebind(var1, var2, var4);
         } else {
            this.removeRebind(var1);
         }
      } else {
         this.clearMarkedEntity(var1);
      }
   }

   class="kw">private void captureRebind(int var1, @Nonnull Ref<EntityStore> var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      if (this.slotToNameMap != null) {
         String var4 = (String)this.slotToNameMap.get(var1);
         if (var4 != null) {
            UUIDComponent var5 = var3.getComponent(var2, UUIDComponent.getComponentType());
            if (var5 != null) {
               this.rebindUuids.put(var4, var5.getUuid());
            }
         }
      }
   }

   class="kw">private void removeRebind(int var1) {
      if (!this.rebindUuids.isEmpty() && this.slotToNameMap != null) {
         String var2 = (String)this.slotToNameMap.get(var1);
         if (var2 != null) {
            this.rebindUuids.remove(var2);
         }
      }
   }

   class="kw">public boolean isRebindSlot(int var1) {
      if (!this.rebindUuids.isEmpty() && this.slotToNameMap != null) {
         String var2 = (String)this.slotToNameMap.get(var1);
         class="kw">return var2 != null && this.rebindUuids.containsKey(var2);
      } else {
         class="kw">return false;
      }
   }

   class="kw">public void resolveRebinds(@Nonnull ComponentAccessor<EntityStore> var1) {
      if (!this.rebindUuids.isEmpty() && this.slotToNameMap != null) {
         Iterator var2 = this.rebindUuids.entrySet().iterator();

         while (var2.hasNext()) {
            Entry var3 = var2.next();
            int var4 = this.targetSlotMappings.getInt(var3.getKey());
            if (var4 < 0) {
               var2.remove();
            } else {
               Ref var5 = this.entityTargets[var4];
               if (var5 == null || !var5.isValid()) {
                  Ref var6 = var1.getExternalData().getRefFromUUID(var3.getValue());
                  if (var6 != null && var6.isValid()) {
                     this.entityTargets[var4] = var6;
                  } else {
                     this.entityTargets[var4] = null;
                     var2.remove();
                  }
               }
            }
         }
      }
   }

   @Nullable
   class="kw">public Ref<EntityStore> getMarkedEntityRef(String var1) {
      int var2 = this.targetSlotMappings.getInt(var1);
      class="kw">return var2 >= 0 ? this.getMarkedEntityRef(var2) : null;
   }

   @Nullable
   class="kw">public Ref<EntityStore> getMarkedEntityRef(int var1) {
      Ref var2 = this.entityTargets[var1];
      class="kw">return var2 != null && var2.isValid() ? var2 : null;
   }

   class="kw">public int getMarkedEntitySlotCount() {
      class="kw">return this.entityTargets.length;
   }

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

   class="kw">public boolean hasMarkedEntity(@Nonnull Ref<EntityStore> var1, int var2) {
      class="kw">return var1.equals(this.getMarkedEntityRef(var2));
   }

   class="kw">public boolean hasMarkedEntityInSlot(String var1) {
      int var2 = this.targetSlotMappings.getInt(var1);
      class="kw">return var2 < 0 ? false : this.hasMarkedEntityInSlot(var2);
   }

   class="kw">public boolean hasMarkedEntityInSlot(int var1) {
      class="kw">return this.getMarkedEntityRef(var1) != null;
   }

   class="kw">public void flockSetTarget(@Nonnull Ref<EntityStore> var1, @Nonnull String var2, @Nullable Ref<EntityStore> var3, @Nonnull Store<EntityStore> var4) {
      Ref var5 = FlockPlugin.getFlockReference(var1, var4);
      if (var5 != null) {
         var4.getComponent(var5, EntityGroup.getComponentType()).forEachMember((var0, var1x, var2x, var3x) -> {
            NPCEntity var4 = var0.getStore().getComponent(var0, NPC_COMPONENT_TYPE);
            if (var4 != null) {
               var4.onFlockSetTarget(var3x, var2x);
            }
         }, var1, var3, var2);
      }
   }

   class="kw">public void setTargetSlotToIgnoreForAvoidance(int var1) {
      this.targetSlotToIgnoreForAvoidance = var1 >= 0 ? var1 : this.defaultTargetSlot;
   }

   @Nullable
   class="kw">public Ref<EntityStore> getTargetReferenceToIgnoreForAvoidance() {
      class="kw">return this.targetSlotToIgnoreForAvoidance < 0 ? null : this.getMarkedEntityRef(this.targetSlotToIgnoreForAvoidance);
   }

   class="kw">public String getSlotName(int var1) {
      class="kw">return (String)this.slotToNameMap.get(var1);
   }

   class="kw">public void unloaded() {
      Arrays.fill(this.entityTargets, null);
   }

   @Nonnull
   @Override
   class="kw">public Component<EntityStore> clone() {
      MarkedEntitySupport var1 = new MarkedEntitySupport();
      var1.rebindUuids = new HashMap<>(this.rebindUuids);
      class="kw">return var1;
   }

   class="kw">static {
      EMPTY_TARGET_SLOT_MAP.defaultReturnValue(Integer.MIN_VALUE);
   }
}