PolygonPathCommand class

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

Файл: com/hypixel/hytale/server/npc/commands/NPCPathCommand.java

extends: NPCWorldCommandBase

Поля (10)

МодификаторыТипИмя
private final OptionalArg<Double> lengthArg
private final RequiredArg<Integer> sidesArg
HeadRotation var12
Vector3d var13
Rotation3f var14
TransformComponent var15
ArrayDeque var6
Integer var7
float var8
double var9

Методы (3)

МодификаторыВозвратСигнатура
protected void executeprotected void execute(@Nonnull CommandContext var1, @Nonnull NPCEntity var2, @Nonnull World var3, @Nonnull Store<EntityStore> var4, @Nonnull Ref<EntityStore> var5)
for for(int var11 = 0; var11 < var7; var11++)
abstract super super("polygon", "server.commands.npc.path.polygon.desc")

Исходный код

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

class="kw">import com.hypixel.hytale.builtin.path.path.TransientPath;
class="kw">import com.hypixel.hytale.builtin.path.waypoint.RelativeWaypointDefinition;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.command.system.CommandContext;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
class="kw">import com.hypixel.hytale.server.core.command.system.basecommands.AbstractCommandCollection;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
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.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import java.util.ArrayDeque;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class NPCPathCommand class="kw">extends AbstractCommandCollection {
   class="kw">public NPCPathCommand() {
      super("path", "server.commands.npc.path.desc");
      this.addSubCommand(new NPCPathCommand.SetPathCommand());
      this.addSubCommand(new NPCPathCommand.PolygonPathCommand());
   }

   class="kw">public class="kw">static class PolygonPathCommand class="kw">extends NPCWorldCommandBase {
      @Nonnull
      class="kw">private class="kw">final RequiredArg<Integer> sidesArg = this.withRequiredArg("sides", "server.commands.npc.path.polygon.sides.desc", ArgTypes.INTEGER)
         .addValidator(Validators.greaterThan(0));
      @Nonnull
      class="kw">private class="kw">final OptionalArg<Double> lengthArg = this.withOptionalArg("length", "server.commands.npc.path.length.desc", ArgTypes.DOUBLE)
         .addValidator(Validators.greaterThan(0.0));

      class="kw">public PolygonPathCommand() {
         super("polygon", "server.commands.npc.path.polygon.desc");
      }

      @Override
      class="kw">protected void execute(
         @Nonnull CommandContext var1, @Nonnull NPCEntity var2, @Nonnull World var3, @Nonnull Store<EntityStore> var4, @Nonnull Ref<EntityStore> var5
      ) {
         ArrayDeque var6 = new ArrayDeque<>();
         Integer var7 = this.sidesArg.get(var1);
         float var8 = (float) (Math.PI * 2) / var7.intValue();
         double var9 = this.lengthArg.provided(var1) ? this.lengthArg.get(var1) : 5.0;

         for (int var11 = 0; var11 < var7; var11++) {
            var6.add(new RelativeWaypointDefinition(var8, var9));
         }

         TransformComponent var15 = var4.getComponent(var5, TransformComponent.getComponentType());
         assert var15 != null;
         HeadRotation var12 = var4.getComponent(var5, HeadRotation.getComponentType());
         assert var12 != null;
         Vector3d var13 = var15.getPosition();
         Rotation3f var14 = var12.getRotation();
         var2.getPathManager().setTransientPath(TransientPath.buildPath(var13, var14, var6, 1.0));
      }
   }

   class="kw">public class="kw">static class SetPathCommand class="kw">extends NPCWorldCommandBase {
      @Nonnull
      class="kw">private class="kw">final RequiredArg<String> instructionsArg = this.withRequiredArg("instructions", "server.commands.npc.path.instructions.desc", ArgTypes.STRING);

      class="kw">public SetPathCommand() {
         super("", "server.commands.npc.path.desc");
      }

      @Override
      class="kw">protected void execute(
         @Nonnull CommandContext var1, @Nonnull NPCEntity var2, @Nonnull World var3, @Nonnull Store<EntityStore> var4, @Nonnull Ref<EntityStore> var5
      ) {
         TransformComponent var6 = var4.getComponent(var5, TransformComponent.getComponentType());
         assert var6 != null;
         HeadRotation var7 = var4.getComponent(var5, HeadRotation.getComponentType());
         assert var7 != null;
         String var8 = this.instructionsArg.get(var1);
         ArrayDeque var9 = this.parseInstructions(var1, var8);
         if (var9 != null) {
            var2.getPathManager().setTransientPath(TransientPath.buildPath(var6.getPosition(), var7.getRotation(), var9, 1.0));
         }
      }

      @Nullable
      class="kw">private ArrayDeque<RelativeWaypointDefinition> parseInstructions(@Nonnull CommandContext var1, @Nonnull String var2) {
         ArrayDeque var3 = new ArrayDeque<>();
         String[] var4 = var2.split(",", 0);
         int var5 = 0;

         try {
            while (var5 < var4.length) {
               float var6 = Float.parseFloat(var4[var5++]) * (float) (Math.PI / 180.0);
               double var7 = Double.parseDouble(var4[var5++]);
               var3.add(new RelativeWaypointDefinition(var6, var7));
            }

            class="kw">return var3;
         } catch (NumberFormatException var9) {
            var1.sendMessage(Message.raw("Invalid number format: " + var9.getMessage()));
            class="kw">return null;
         } catch (IndexOutOfBoundsException var10) {
            var1.sendMessage(Message.raw("Instructions must be defined in pairs! Missing distance value."));
            class="kw">return null;
         }
      }
   }
}