Operation enum

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

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

implements: Supplier<String>

Поля (1)

МодификаторыТипИмя
private final String description

Методы (2)

МодификаторыВозвратСигнатура
abstract EquipOffHand EquipOffHand("Equips the item from a specific off-hand slot")
public String getpublic String get()

Исходный код

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

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.item.config.Item;
class="kw">import com.hypixel.hytale.server.core.inventory.InventoryComponent;
class="kw">import com.hypixel.hytale.server.core.inventory.InventoryUtils;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
class="kw">import com.hypixel.hytale.server.core.modules.item.ItemModule;
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.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.ActionBase;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.items.builders.BuilderActionInventory;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.IPositionProvider;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
class="kw">import com.hypixel.hytale.server.npc.util.InventoryHelper;
class="kw">import java.util.EnumSet;
class="kw">import java.util.function.Supplier;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class ActionInventory class="kw">extends ActionBase {
   @Nonnull
   class="kw">private class="kw">static class="kw">final EnumSet<ActionInventory.Operation> ITEM_FREE_OPERATIONS = EnumSet.of(
      ActionInventory.Operation.ClearHeldItem,
      ActionInventory.Operation.RemoveHeldItem,
      ActionInventory.Operation.EquipHotbar,
      ActionInventory.Operation.EquipOffHand
   );
   class="kw">protected class="kw">final ActionInventory.Operation operation;
   class="kw">protected class="kw">final String item;
   class="kw">protected class="kw">final int count;
   class="kw">protected class="kw">final boolean useTarget;
   class="kw">protected class="kw">final byte slot;

   class="kw">public ActionInventory(@Nonnull BuilderActionInventory var1, @Nonnull BuilderSupport var2) {
      super(var1);
      this.operation = var1.getOperation(var2);
      this.count = var1.getCount(var2);
      this.item = var1.getItem(var2);
      this.useTarget = var1.getUseTarget(var2);
      this.slot = (byte)var1.getSlot(var2);
   }

   @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)
         ? false
         : (!this.useTarget || var3 != null && var3.hasPosition())
            && (ITEM_FREE_OPERATIONS.contains(this.operation) || this.item != null && !this.item.isEmpty());
   }

   @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);
      IPositionProvider var7 = var3 != null ? var3.getPositionProvider() : null;
      Ref var8 = this.useTarget ? (var7 != null ? var7.getTarget() : null) : var1;
      if (var8 == null) {
         class="kw">return false;
      }

      if (this.operation == ActionInventory.Operation.ClearHeldItem) {
         InventoryHelper.clearItemInHand(var8, (byte)-1, var6);
         class="kw">return true;
      }

      if (this.operation == ActionInventory.Operation.RemoveHeldItem) {
         InventoryHelper.removeItemInHand(var8, var6, this.count);
         class="kw">return true;
      }

      if (this.operation != ActionInventory.Operation.EquipHotbar || this.item != null && !this.item.isEmpty()) {
         if (this.operation != ActionInventory.Operation.EquipOffHand || this.item != null && !this.item.isEmpty()) {
            String var9 = this.item;
            if (var9 != null && !"Empty".equals(var9) && !"Unknown".equals(var9) && ItemModule.exists(var9)) {
               CombinedItemContainer var10 = InventoryComponent.getCombined(var6, var8, InventoryComponent.HOTBAR_FIRST);
               ItemStack var11 = new ItemStack(var9, this.count);
               class="kw">switch (this.operation) {
                  case Add:
                     if (this.count > 0) {
                        var10.addItemStack(var11);
                     }
                     break;
                  case Remove:
                     if (this.count > 0) {
                        var10.removeItemStack(var11);
                     }
                     break;
                  case Equip:
                     Item var17 = var11.getItem();
                     if (var17.getArmor() != null) {
                        InventoryComponent.Armor var13 = var6.getComponent(var8, InventoryComponent.Armor.getComponentType());
                        if (var13 != null) {
                           InventoryHelper.useArmor(var13.getInventory(), var11);
                        }
                     } else {
                        InventoryHelper.useItem(var8, var17.getId(), var6);
                     }
                  case ClearHeldItem:
                  case RemoveHeldItem:
                  class="kw">default:
                     break;
                  case SetHotbar:
                     if (InventoryHelper.checkHotbarSlot(var8, this.slot, var6)) {
                        InventoryComponent.Hotbar var16 = var6.getComponent(var8, InventoryComponent.Hotbar.getComponentType());
                        if (var16 != null) {
                           var16.getInventory().setItemStackForSlot(this.slot, var11);
                        }
                     }
                     break;
                  case EquipHotbar:
                     if (InventoryHelper.checkHotbarSlot(var8, this.slot, var6)) {
                        InventoryComponent.Hotbar var15 = var6.getComponent(var8, InventoryComponent.Hotbar.getComponentType());
                        if (var15 != null) {
                           var15.getInventory().setItemStackForSlot(this.slot, var11);
                           if (var15.getActiveSlot() != this.slot) {
                              var15.setActiveSlot(this.slot, var8, var6);
                           }
                        }
                     }
                     break;
                  case SetOffHand:
                     if (InventoryHelper.checkOffHandSlot(var8, this.slot, var6)) {
                        InventoryComponent.Utility var14 = var6.getComponent(var8, InventoryComponent.Utility.getComponentType());
                        if (var14 != null) {
                           var14.getInventory().setItemStackForSlot(this.slot, var11);
                        }
                     }
                     break;
                  case EquipOffHand:
                     if (InventoryHelper.checkOffHandSlot(var8, this.slot, var6)) {
                        InventoryComponent.Utility var12 = var6.getComponent(var8, InventoryComponent.Utility.getComponentType());
                        if (var12 != null) {
                           var12.getInventory().setItemStackForSlot(this.slot, var11);
                        }
                     }

                     InventoryHelper.setOffHandSlot(var8, this.slot, var6);
               }

               class="kw">return true;
            } else {
               NPCPlugin.get().getLogger().at(Level.WARNING).log("Unknown item %s in Inventory action", this.item);
               class="kw">return true;
            }
         } else {
            InventoryHelper.setOffHandSlot(var8, this.slot, var6);
            class="kw">return true;
         }
      } else {
         if (InventoryUtils.getActiveSlot(var8, -1, var6) == this.slot) {
            class="kw">return true;
         }

         if (InventoryHelper.checkHotbarSlot(var8, this.slot, var6)) {
            InventoryUtils.setActiveSlot(var8, -1, this.slot, var6);
         }

         class="kw">return true;
      }
   }

   class="kw">public enum Operation class="kw">implements Supplier<String> {
      Add("Add items to inventory"),
      Remove("Remove items from inventory"),
      Equip("Equip item as weapon or armour"),
      ClearHeldItem("Clear the held item"),
      RemoveHeldItem("Destroy the held item"),
      SetHotbar("Sets the hotbar item in a specific slot"),
      EquipHotbar("Equips the item from a specific hotbar slot"),
      SetOffHand("Sets the off-hand item in a specific slot"),
      EquipOffHand("Equips the item from a specific off-hand slot");

      class="kw">private class="kw">final String description;

      Operation(String nullxx) {
         this.description = nullxx;
      }

      class="kw">public String get() {
         class="kw">return this.description;
      }
   }
}