DeployableOwnerComponent class

Пакет: com.hypixel.hytale.builtin.deployables.component

Файл: com/hypixel/hytale/builtin/deployables/component/DeployableOwnerComponent.java

implements: Component<EntityStore>

Поля (16)

МодификаторыТипИмя
break
break
World var1
DeployableConfig var10
int var11
Ref var14
DeployableComponent var15
GameplayConfig var2
int var3
int var3
int var4
int var4
int var5
Ref var7
DeployableComponent var8
DeployableConfig var9

Методы (19)

МодификаторыВозвратСигнатура
public void deRegisterDeployablevoid deRegisterDeployable(@Nonnull String var1, @Nonnull Ref<EntityStore> var2)
private void decrementIdvoid decrementId(@Nonnull String var1)
for for(Pair var7 : this.deployables)
for for(Pair var6 : this.deployables)
for for(Pair var13 : this.deployables)
for for(Ref var3 : this.deployablesForDestruction)
private int getCurrentDeployablesByIdint getCurrentDeployablesById(@Nonnull String var1)
static int getMaxDeployablesForIdint getMaxDeployablesForId(@Nonnull DeployableComponent var0)
static int getMaxDeployablesGlobalint getMaxDeployablesGlobal(@Nonnull Store<EntityStore> var0)
private void handleGlobalDeployableLimitvoid handleGlobalDeployableLimit(@Nonnull Store<EntityStore> var1, @Nonnull Ref<EntityStore> var2)
private void handleOverMaxDeployableDestructionvoid handleOverMaxDeployableDestruction(@Nonnull CommandBuffer<EntityStore> var1)
private void handlePerDeployableLimitvoid handlePerDeployableLimit(@Nonnull String var1, @Nonnull DeployableComponent var2)
if if(var4 > var3)
if if(var5 <= 0)
if if(var4 > 1)
if if(--var11 <= 0)
private void incrementIdvoid incrementId(@Nonnull String var1)
public void registerDeployablevoid registerDeployable(@Nonnull Ref<EntityStore> var1, @Nonnull DeployableComponent var2, @Nonnull String var3, @Nonnull Ref<EntityStore> var4, @Nonnull Store<EntityStore> var5)
public void tickvoid tick(@Nonnull CommandBuffer<EntityStore> var1)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.deployables.component;

class="kw">import com.hypixel.hytale.builtin.deployables.DeployablesPlugin;
class="kw">import com.hypixel.hytale.builtin.deployables.config.DeployableConfig;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Component;
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.asset.type.gameplay.GameplayConfig;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.Damage;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.DamageCause;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import it.unimi.dsi.fastutil.Pair;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntMap;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
class="kw">import java.util.List;
class="kw">import javax.annotation.Nonnull;

class="kw">public class DeployableOwnerComponent class="kw">implements Component<EntityStore> {
   @Nonnull
   class="kw">private class="kw">final List<Pair<String, Ref<EntityStore>>> deployables = new ObjectArrayList();
   @Nonnull
   class="kw">private class="kw">final Object2IntMap<String> deployableCountPerId = new Object2IntOpenHashMap();
   @Nonnull
   class="kw">private class="kw">final List<Ref<EntityStore>> deployablesForDestruction = new ReferenceArrayList();
   @Nonnull
   class="kw">private class="kw">final List<Pair<String, Ref<EntityStore>>> tempDestructionList = new ObjectArrayList();

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

   @Nonnull
   class="kw">public class="kw">static ComponentType<EntityStore, DeployableOwnerComponent> getComponentType() {
      class="kw">return DeployablesPlugin.get().getDeployableOwnerComponentType();
   }

   class="kw">private class="kw">static int getMaxDeployablesForId(@Nonnull DeployableComponent var0) {
      class="kw">return var0.getConfig().getMaxLiveCount();
   }

   class="kw">private class="kw">static int getMaxDeployablesGlobal(@Nonnull Store<EntityStore> var0) {
      World var1 = var0.getExternalData().getWorld();
      GameplayConfig var2 = var1.getGameplayConfig();
      class="kw">return var2.getPlayerConfig().getMaxDeployableEntities();
   }

   class="kw">public void tick(@Nonnull CommandBuffer<EntityStore> var1) {
      this.handleOverMaxDeployableDestruction(var1);
   }

   class="kw">public void registerDeployable(
      @Nonnull Ref<EntityStore> var1, @Nonnull DeployableComponent var2, @Nonnull String var3, @Nonnull Ref<EntityStore> var4, @Nonnull Store<EntityStore> var5
   ) {
      this.deployables.add(Pair.of(var3, var4));
      this.incrementId(var3);
      this.handlePerDeployableLimit(var3, var2);
      this.handleGlobalDeployableLimit(var5, var1);
   }

   class="kw">public void deRegisterDeployable(@Nonnull String var1, @Nonnull Ref<EntityStore> var2) {
      this.deployables.remove(Pair.of(var1, var2));
      this.decrementId(var1);
   }

   class="kw">private void incrementId(@Nonnull String var1) {
      if (!this.deployableCountPerId.containsKey(var1)) {
         this.deployableCountPerId.put(var1, 1);
      } else {
         this.deployableCountPerId.put(var1, this.deployableCountPerId.getInt(var1) + 1);
      }
   }

   class="kw">private void decrementId(@Nonnull String var1) {
      if (!this.deployableCountPerId.containsKey(var1)) {
         this.deployableCountPerId.put(var1, 0);
      } else {
         this.deployableCountPerId.put(var1, this.deployableCountPerId.getInt(var1) - 1);
      }
   }

   class="kw">private int getCurrentDeployablesById(@Nonnull String var1) {
      class="kw">return this.deployableCountPerId.getOrDefault(var1, 0);
   }

   class="kw">private void handlePerDeployableLimit(@Nonnull String var1, @Nonnull DeployableComponent var2) {
      int var3 = getMaxDeployablesForId(var2);
      int var4 = this.getCurrentDeployablesById(var1);
      if (var4 > var3) {
         int var5 = var4 - var3;
         this.tempDestructionList.clear();

         for (Pair var7 : this.deployables) {
            if (((String)var7.key()).equals(var1)) {
               this.deployablesForDestruction.add((Ref<EntityStore>)var7.value());
               this.tempDestructionList.add(var7);
               var5--;
            }

            if (var5 <= 0) {
               break;
            }
         }

         this.deployables.removeAll(this.tempDestructionList);
         this.tempDestructionList.clear();
      }
   }

   class="kw">private void handleGlobalDeployableLimit(@Nonnull Store<EntityStore> var1, @Nonnull Ref<EntityStore> var2) {
      int var3 = 1;
      int var4 = 0;
      this.tempDestructionList.clear();

      for (Pair var6 : this.deployables) {
         Ref var7 = (Ref<EntityStore>)var6.value();
         if (var7.isValid() && var7.getStore() == var1) {
            DeployableComponent var8 = var1.getComponent(var7, DeployableComponent.getComponentType());
            assert var8 != null;
            DeployableConfig var9 = var8.getConfig();
            if (var9.getCountTowardsGlobalLimit()) {
               var4++;
            }
         } else {
            this.tempDestructionList.add(var6);
         }
      }

      if (!this.tempDestructionList.isEmpty()) {
         this.deployables.removeAll(this.tempDestructionList);
         this.tempDestructionList.clear();
      }

      if (var4 > 1) {
         int var11 = var4 - 1;

         for (Pair var13 : this.deployables) {
            Ref var14 = (Ref<EntityStore>)var13.value();
            DeployableComponent var15 = var1.getComponent(var14, DeployableComponent.getComponentType());
            assert var15 != null;
            DeployableConfig var10 = var15.getConfig();
            if (var10.getCountTowardsGlobalLimit()) {
               this.deployablesForDestruction.add(var14);
               this.tempDestructionList.add(var13);
               if (--var11 <= 0) {
                  break;
               }
            }
         }

         this.deployables.removeAll(this.tempDestructionList);
         this.tempDestructionList.clear();
      }
   }

   class="kw">private void handleOverMaxDeployableDestruction(@Nonnull CommandBuffer<EntityStore> var1) {
      if (!this.deployablesForDestruction.isEmpty()) {
         for (Ref var3 : this.deployablesForDestruction) {
            DeathComponent.tryAddComponent(var1, var3, new Damage(Damage.NULL_SOURCE, DamageCause.COMMAND, 0.0F));
         }

         this.deployablesForDestruction.clear();
      }
   }

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