ActionDropItem class

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

Файл: com/hypixel/hytale/server/npc/corecomponents/items/ActionDropItem.java

extends: ActionWithDelay

Поля (16)

МодификаторыТипИмя
final String item
ItemModule var10
Rotation3f var10
float var11
ItemStack var14
double[] var3
double[] var4
float var5
ModelComponent var7
Vector3d var7
var7
var7
float var8
TransformComponent var8
float var9
HeadRotation var9

Методы (7)

МодификаторыВозвратСигнатура
if if(this.dropSectorStart > var5)
if if(this.item != null)
if if(var14 != null)
if if(var9 != null)
protected void newDirectionvoid newDirection(@Nonnull Ref<EntityStore> var1, double var2, double var4, @Nonnull ComponentAccessor<EntityStore> var6)
protected double pickDistancedouble pickDistance()
abstract super super(var1, var2)

Исходный код

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

class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.math.random.RandomExtra;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.math.vector.Vector3dUtil;
class="kw">import com.hypixel.hytale.server.core.entity.ItemUtils;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.item.ItemModule;
class="kw">import com.hypixel.hytale.server.core.modules.physics.util.PhysicsMath;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.ActionWithDelay;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.items.builders.BuilderActionDropItem;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
class="kw">import com.hypixel.hytale.server.npc.util.AimingHelper;
class="kw">import com.hypixel.hytale.server.npc.util.InventoryHelper;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class ActionDropItem class="kw">extends ActionWithDelay {
   class="kw">protected class="kw">final String item;
   class="kw">protected class="kw">final String dropList;
   class="kw">protected class="kw">final float dropSectorStart;
   class="kw">protected class="kw">final float dropSectorEnd;
   class="kw">protected class="kw">final double minDistance;
   class="kw">protected class="kw">final double maxDistance;
   class="kw">protected class="kw">final boolean highPitch;
   class="kw">protected class="kw">final float[] pitch = new float[2];
   class="kw">protected class="kw">final Vector3d dropDirection = new Vector3d();
   class="kw">protected float throwSpeed;

   class="kw">public ActionDropItem(@Nonnull BuilderActionDropItem var1, @Nonnull BuilderSupport var2) {
      super(var1, var2);
      this.item = var1.getItem(var2);
      this.dropList = var1.getDropList(var2);
      double[] var3 = var1.getDistance();
      this.minDistance = var3[0];
      this.maxDistance = var3[1];
      this.throwSpeed = var1.getThrowSpeed();
      double[] var4 = var1.getDropSectorRadians();
      this.dropSectorStart = (float) (Math.PI / 180.0) * (float)var4[0];
      float var5 = (float) (Math.PI / 180.0) * (float)var4[1];
      if (this.dropSectorStart > var5) {
         var5 += (float) (Math.PI * 2);
      }

      this.dropSectorEnd = var5;
      this.highPitch = var1.isHighPitch();
   }

   @Override
   class="kw">public boolean canExecute(
      @Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nullable InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6
   ) {
      class="kw">return super.canExecute(var1, var2, var3, var4, var6) && !this.isDelaying();
   }

   @Override
   class="kw">public boolean execute(
      @Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nullable InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6
   ) {
      super.execute(var1, var2, var3, var4, var6);
      this.prepareDelay();
      this.startDelay(var2.getEntitySupport());
      ModelComponent var7 = var6.getComponent(var1, ModelComponent.getComponentType());
      float var8 = var7 != null ? var7.getModel().getEyeHeight(var1, var6) : 0.0F;
      float var9 = -var8;
      if (this.item != null) {
         this.newDirection(var1, this.pickDistance(), var9, var6);
         ItemStack var14 = InventoryHelper.createItem(this.item);
         if (var14 != null) {
            ItemUtils.throwItem(var1, var6, var14, this.dropDirection, this.throwSpeed);
         }

         class="kw">return true;
      } else {
         ItemModule var10 = ItemModule.get();
         if (var10.isEnabled()) {
            for (ItemStack var13 : var10.getRandomItemDrops(this.dropList)) {
               this.newDirection(var1, this.pickDistance(), var9, var6);
               ItemUtils.throwItem(var1, var6, var13, this.dropDirection, this.throwSpeed);
            }
         }

         class="kw">return true;
      }
   }

   class="kw">protected double pickDistance() {
      class="kw">return RandomExtra.randomRange(this.minDistance, this.maxDistance);
   }

   class="kw">protected void newDirection(@Nonnull Ref<EntityStore> var1, double var2, double var4, @Nonnull ComponentAccessor<EntityStore> var6) {
      TransformComponent var8 = var6.getComponent(var1, TransformComponent.getComponentType());
      assert var8 != null;
      HeadRotation var9 = var6.getComponent(var1, HeadRotation.getComponentType());
      Vector3d var7;
      if (var9 != null) {
         var7 = var9.getDirection();
      } else {
         Rotation3f var10 = var8.getRotation();
         var7 = Vector3dUtil.setYawPitch(var10.yaw(), var10.pitch(), new Vector3d());
      }

      this.dropDirection.set(var7);
      this.dropDirection.rotateY(RandomExtra.randomRange(this.dropSectorStart, this.dropSectorEnd));
      if (!AimingHelper.computePitch(var2, var4, this.throwSpeed, 32.0, this.pitch)) {
         throw new IllegalStateException(
            String.format("Error in computing pitch with distance %s, height %s, and speed %s that was not caught in validation", var2, var4, this.throwSpeed)
         );
      }

      float var11 = PhysicsMath.headingFromDirection(this.dropDirection.x, this.dropDirection.z);
      PhysicsMath.vectorFromAngles(var11, this.highPitch ? this.pitch[1] : this.pitch[0], this.dropDirection).normalize();
   }
}