InventoryHelper class
Пакет: com.hypixel.hytale.server.npc.util
Файл: com/hypixel/hytale/server/npc/util/InventoryHelper.java
Поля (40)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
short |
DEFAULT_NPC_HOTBAR_SLOTS |
|
Item |
var1 |
|
ItemDropList |
var1 |
|
int |
var1 |
|
InventoryComponent.Hotbar |
var2 |
|
int |
var2 |
|
|
var2 |
|
|
var2 |
|
ItemStack |
var2 |
|
Item |
var2 |
|
String |
var3 |
|
InventoryComponent.Hotbar |
var3 |
|
InventoryComponent.Hotbar |
var3 |
|
ItemContainer |
var3 |
|
CombinedItemContainer |
var3 |
|
CombinedItemContainer |
var3 |
|
ItemStack |
var3 |
|
byte |
var3 |
|
|
var3 |
|
InventoryComponent.Hotbar |
var3 |
|
InventoryComponent.Hotbar |
var3 |
|
InventoryComponent.Utility |
var3 |
|
InventoryComponent.Utility |
var3 |
|
ItemArmor |
var3 |
|
ItemContainer |
var4 |
|
ItemContainer |
var4 |
|
ItemStack |
var4 |
|
InventoryComponent.Hotbar |
var4 |
|
byte |
var4 |
|
InventoryComponent.Hotbar |
var4 |
|
InventoryComponent.Utility |
var4 |
|
byte |
var4 |
|
short |
var4 |
|
ItemStack |
var5 |
|
ItemStack |
var5 |
|
ItemContainer |
var5 |
|
ItemContainer |
var5 |
|
InventoryComponent.Hotbar |
var5 |
|
ItemStack |
var6 |
|
ItemStack |
var6 |
Методы (55)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
static |
boolean |
checkHotbarSlotboolean checkHotbarSlot(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) |
static |
boolean |
checkOffHandSlotboolean checkOffHandSlot(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) |
static |
boolean |
clearItemInHandboolean clearItemInHand(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) |
static |
boolean |
containsItemboolean containsItem(@Nonnull Ref<EntityStore> var0, @Nonnull String var1, @Nonnull ComponentAccessor<EntityStore> var2) |
static |
boolean |
containsItemboolean containsItem(@Nonnull Ref<EntityStore> var0, @Nonnull List<String> var1, @Nonnull ComponentAccessor<EntityStore> var2) |
static |
int |
countFreeSlotsint countFreeSlots(@Nonnull ItemContainer var0) |
static |
int |
countItemsint countItems(@Nonnull ItemContainer var0, @Nonnull List<String> var1) |
static |
byte |
findHotbarEmptySlotbyte findHotbarEmptySlot(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1) |
static |
byte |
findHotbarSlotWithItembyte findHotbarSlotWithItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull String var2) |
static |
short |
findHotbarSlotWithItemshort findHotbarSlotWithItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull List<String> var2) |
static |
short |
findInventorySlotWithItemshort findInventorySlotWithItem(@Nonnull Ref<EntityStore> var0, @Nonnull String var1, @Nonnull ComponentAccessor<EntityStore> var2) |
static |
short |
findInventorySlotWithItemshort findInventorySlotWithItem(@Nonnull Ref<EntityStore> var0, @Nonnull List<String> var1, @Nonnull ComponentAccessor<EntityStore> var2) |
abstract |
|
for for(int var2 = 0; var2 < var0.size() |
abstract |
|
for for(byte var5 = 0; var5 < var4.getCapacity() |
abstract |
|
for for(short var5 = 0; var5 < var4.getCapacity() |
abstract |
|
for for(byte var4 = 0; var4 < var3.getCapacity() |
abstract |
|
for for(short var4 = 0; var4 < var3.getCapacity() |
abstract |
|
for for(short var3 = 0; var3 < var0.getCapacity() |
abstract |
|
for for(short var2 = 0; var2 < var0.getCapacity() |
static |
boolean |
holdsItemboolean holdsItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull String var2) |
static |
boolean |
hotbarContainsItemboolean hotbarContainsItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull String var2) |
static |
boolean |
hotbarContainsItemboolean hotbarContainsItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull List<String> var2) |
|
|
if if(var3 == null) |
|
|
if if(var3 == null) |
|
|
if if(var2 == null) |
|
|
if if(var3 >= 0) |
|
|
if if(var4 != null) |
|
|
if if(var3 != null) |
|
|
if if(var4 != -1) |
|
|
if if(var3 == null) |
|
|
if if(var3 == null) |
|
|
if if(var3 != null) |
|
|
if if(var4 >= 0) |
|
|
if if(var2 == -1) |
|
|
if if(var2 == -1) |
|
|
if if(var5 != null) |
|
|
if if(var1 == null) |
|
|
if if(var2 == null) |
|
|
if if(var3 == null) |
static |
boolean |
itemDropListKeyExistsboolean itemDropListKeyExists(@Nullable String var0) |
static |
boolean |
itemKeyExistsboolean itemKeyExists(@Nullable String var0) |
static |
boolean |
itemKeyIsBlockTypeboolean itemKeyIsBlockType(@Nullable String var0) |
static |
boolean |
matchesItemboolean matchesItem(@Nullable String var0, @Nonnull ItemStack var1) |
static |
boolean |
matchesItemboolean matchesItem(@Nullable List<String> var0, @Nonnull ItemStack var1) |
static |
boolean |
matchesPatternsboolean matchesPatterns(@Nonnull List<String> var0, @Nullable String var1) |
static |
void |
removeItemInHandvoid removeItemInHand(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, int var2) |
static |
boolean |
setHotbarItemboolean setHotbarItem(@Nonnull Ref<EntityStore> var0, @Nullable String var1, byte var2, @Nonnull ComponentAccessor<EntityStore> var3) |
static |
void |
setHotbarSlotvoid setHotbarSlot(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) |
static |
boolean |
setOffHandItemboolean setOffHandItem(@Nonnull Ref<EntityStore> var0, @Nullable String var1, byte var2, @Nonnull ComponentAccessor<EntityStore> var3) |
static |
void |
setOffHandSlotvoid setOffHandSlot(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) |
static |
boolean |
useArmorboolean useArmor(@Nonnull ItemContainer var0, @Nullable String var1) |
static |
boolean |
useArmorboolean useArmor(@Nonnull ItemContainer var0, @Nullable ItemStack var1) |
abstract |
return |
useArmorreturn useArmor(var0, var2) |
static |
boolean |
useItemboolean useItem(@Nonnull Ref<EntityStore> var0, @Nullable String var1, byte var2, @Nonnull ComponentAccessor<EntityStore> var3) |
static |
boolean |
useItemboolean useItem(@Nonnull Ref<EntityStore> var0, @Nullable String var1, @Nonnull ComponentAccessor<EntityStore> var2) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.util;
class="kw">import com.hypixel.hytale.common.util.StringUtil;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.Item;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.ItemArmor;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.ItemDropList;
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.inventory.container.ItemContainer;
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 java.util.List;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class InventoryHelper {
class="kw">public class="kw">static class="kw">final short DEFAULT_NPC_HOTBAR_SLOTS = 3;
class="kw">public class="kw">static class="kw">final short MAX_NPC_HOTBAR_SLOTS = 8;
class="kw">public class="kw">static class="kw">final short DEFAULT_NPC_INVENTORY_SLOTS = 0;
class="kw">public class="kw">static class="kw">final short DEFAULT_NPC_UTILITY_SLOTS = 0;
class="kw">public class="kw">static class="kw">final short MAX_NPC_UTILITY_SLOTS = 4;
class="kw">public class="kw">static class="kw">final short DEFAULT_NPC_TOOL_SLOTS = 0;
class="kw">public class="kw">static class="kw">final short MAX_NPC_INVENTORY_SLOTS = 36;
class="kw">private InventoryHelper() {
}
class="kw">public class="kw">static boolean matchesItem(@Nullable String var0, @Nonnull ItemStack var1) {
class="kw">return var0 != null && !var0.isEmpty() && !ItemStack.isEmpty(var1) ? StringUtil.isGlobMatching(var0, var1.getItem().getId()) : false;
}
class="kw">public class="kw">static boolean matchesItem(@Nullable List<String> var0, @Nonnull ItemStack var1) {
class="kw">return var0 != null && !var0.isEmpty() && !ItemStack.isEmpty(var1) ? matchesPatterns(var0, var1.getItem().getId()) : false;
}
class="kw">protected class="kw">static boolean matchesPatterns(@Nonnull List<String> var0, @Nullable String var1) {
if (var1 != null && !var1.isEmpty()) {
for (int var2 = 0; var2 < var0.size(); var2++) {
String var3 = var0.get(var2);
if (var3 != null && !var3.isEmpty() && StringUtil.isGlobMatching(var3, var1)) {
class="kw">return true;
}
}
class="kw">return false;
} else {
class="kw">return false;
}
}
class="kw">public class="kw">static boolean itemKeyExists(@Nullable String var0) {
class="kw">return var0 != null && !var0.isEmpty() ? ItemModule.exists(var0) : false;
}
class="kw">public class="kw">static boolean itemKeyIsBlockType(@Nullable String var0) {
if (var0 != null && !var0.isEmpty()) {
Item var1 = Item.getAssetMap().getAsset(var0);
class="kw">return var1 != null && var1.hasBlockType();
} else {
class="kw">return false;
}
}
class="kw">public class="kw">static boolean itemDropListKeyExists(@Nullable String var0) {
if (var0 != null && !var0.isEmpty()) {
ItemDropList var1 = ItemDropList.getAssetMap().getAsset(var0);
class="kw">return var1 != null;
} else {
class="kw">return false;
}
}
class="kw">public class="kw">static byte findHotbarSlotWithItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull String var2) {
InventoryComponent.Hotbar var3 = var1.getComponent(var0, InventoryComponent.Hotbar.getComponentType());
if (var3 == null) {
class="kw">return -1;
}
ItemContainer var4 = var3.getInventory();
for (byte var5 = 0; var5 < var4.getCapacity(); var5++) {
ItemStack var6 = var4.getItemStack(var5);
if (var6 != null && matchesItem(var2, var6)) {
class="kw">return var5;
}
}
class="kw">return -1;
}
class="kw">public class="kw">static short findHotbarSlotWithItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull List<String> var2) {
InventoryComponent.Hotbar var3 = var1.getComponent(var0, InventoryComponent.Hotbar.getComponentType());
if (var3 == null) {
class="kw">return -1;
}
ItemContainer var4 = var3.getInventory();
for (short var5 = 0; var5 < var4.getCapacity(); var5++) {
ItemStack var6 = var4.getItemStack(var5);
if (var6 != null && matchesItem(var2, var6)) {
class="kw">return var5;
}
}
class="kw">return -1;
}
class="kw">public class="kw">static byte findHotbarEmptySlot(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1) {
InventoryComponent.Hotbar var2 = var1.getComponent(var0, InventoryComponent.Hotbar.getComponentType());
if (var2 == null) {
class="kw">return -1;
}
ItemContainer var3 = var2.getInventory();
for (byte var4 = 0; var4 < var3.getCapacity(); var4++) {
if (ItemStack.isEmpty(var3.getItemStack(var4))) {
class="kw">return var4;
}
}
class="kw">return -1;
}
class="kw">public class="kw">static short findInventorySlotWithItem(@Nonnull Ref<EntityStore> var0, @Nonnull String var1, @Nonnull ComponentAccessor<EntityStore> var2) {
CombinedItemContainer var3 = InventoryComponent.getCombined(var2, var0, InventoryComponent.HOTBAR_FIRST);
for (short var4 = 0; var4 < var3.getCapacity(); var4++) {
ItemStack var5 = var3.getItemStack(var4);
if (var5 != null && matchesItem(var1, var5)) {
class="kw">return var4;
}
}
class="kw">return -1;
}
class="kw">public class="kw">static short findInventorySlotWithItem(@Nonnull Ref<EntityStore> var0, @Nonnull List<String> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
CombinedItemContainer var3 = InventoryComponent.getCombined(var2, var0, InventoryComponent.HOTBAR_FIRST);
for (short var4 = 0; var4 < var3.getCapacity(); var4++) {
ItemStack var5 = var3.getItemStack(var4);
if (var5 != null && matchesItem(var1, var5)) {
class="kw">return var4;
}
}
class="kw">return -1;
}
class="kw">public class="kw">static int countItems(@Nonnull ItemContainer var0, @Nonnull List<String> var1) {
int var2 = 0;
for (short var3 = 0; var3 < var0.getCapacity(); var3++) {
ItemStack var4 = var0.getItemStack(var3);
if (var4 != null && matchesItem(var1, var4)) {
var2 += var4.getQuantity();
}
}
class="kw">return var2;
}
class="kw">public class="kw">static int countFreeSlots(@Nonnull ItemContainer var0) {
int var1 = 0;
for (short var2 = 0; var2 < var0.getCapacity(); var2++) {
ItemStack var3 = var0.getItemStack(var2);
if (var3 == null || var3.isEmpty()) {
var1++;
}
}
class="kw">return var1;
}
class="kw">public class="kw">static boolean hotbarContainsItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull String var2) {
class="kw">return findHotbarSlotWithItem(var0, var1, var2) != -1;
}
class="kw">public class="kw">static boolean hotbarContainsItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull List<String> var2) {
class="kw">return findHotbarSlotWithItem(var0, var1, var2) != -1;
}
class="kw">public class="kw">static boolean holdsItem(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, @Nonnull String var2) {
class="kw">return matchesItem(var2, InventoryComponent.getItemInHand(var1, var0));
}
class="kw">public class="kw">static boolean containsItem(@Nonnull Ref<EntityStore> var0, @Nonnull String var1, @Nonnull ComponentAccessor<EntityStore> var2) {
class="kw">return findInventorySlotWithItem(var0, var1, var2) != -1;
}
class="kw">public class="kw">static boolean containsItem(@Nonnull Ref<EntityStore> var0, @Nonnull List<String> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
class="kw">return findInventorySlotWithItem(var0, var1, var2) != -1;
}
class="kw">public class="kw">static boolean clearItemInHand(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) {
if (ItemStack.isEmpty(InventoryComponent.getItemInHand(var2, var0))) {
class="kw">return true;
}
byte var3 = findHotbarEmptySlot(var0, var2);
if (var3 >= 0) {
InventoryUtils.setActiveSlot(var0, -1, var3, var2);
class="kw">return true;
}
var3 = var1 != -1 ? var1 : 0;
InventoryComponent.Hotbar var4 = var2.getComponent(var0, InventoryComponent.Hotbar.getComponentType());
if (var4 != null) {
var4.getInventory().removeItemStackFromSlot(var3);
}
InventoryUtils.setActiveSlot(var0, -1, var3, var2);
class="kw">return true;
}
class="kw">public class="kw">static void removeItemInHand(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1, int var2) {
if (!ItemStack.isEmpty(InventoryComponent.getItemInHand(var1, var0))) {
InventoryComponent.Hotbar var3 = var1.getComponent(var0, InventoryComponent.Hotbar.getComponentType());
if (var3 != null) {
byte var4 = var3.getActiveSlot();
if (var4 != -1) {
var3.getInventory().removeItemStackFromSlot(var4, var2);
}
}
}
}
class="kw">public class="kw">static boolean checkHotbarSlot(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) {
InventoryComponent.Hotbar var3 = var2.getComponent(var0, InventoryComponent.Hotbar.getComponentType());
if (var3 == null) {
class="kw">return false;
}
if (var1 < var3.getInventory().getCapacity() && var1 >= 0) {
class="kw">return true;
}
NPCPlugin.get().getLogger().at(Level.WARNING).log("Invalid hotbar slot %s. Max is %s", var1, var3.getInventory().getCapacity() - 1);
class="kw">return false;
}
class="kw">public class="kw">static boolean checkOffHandSlot(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) {
InventoryComponent.Utility var3 = var2.getComponent(var0, InventoryComponent.Utility.getComponentType());
if (var3 == null) {
class="kw">return false;
}
if (var1 < var3.getInventory().getCapacity() && var1 >= -1) {
class="kw">return true;
}
NPCPlugin.get().getLogger().at(Level.WARNING).log("Invalid utility slot %s. Max is %s, Min is %s", var1, var3.getInventory().getCapacity() - 1, -1);
class="kw">return false;
}
class="kw">public class="kw">static void setHotbarSlot(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) {
if (InventoryUtils.getActiveSlot(var0, -1, var2) != var1) {
if (checkHotbarSlot(var0, var1, var2)) {
InventoryUtils.setActiveSlot(var0, -1, var1, var2);
}
}
}
class="kw">public class="kw">static void setOffHandSlot(@Nonnull Ref<EntityStore> var0, byte var1, @Nonnull ComponentAccessor<EntityStore> var2) {
if (InventoryUtils.getActiveSlot(var0, -5, var2) != var1) {
if (checkOffHandSlot(var0, var1, var2)) {
InventoryComponent.Utility var3 = var2.getComponent(var0, InventoryComponent.Utility.getComponentType());
if (var3 != null) {
var3.setActiveSlot(var1, var0, var2);
}
}
}
}
class="kw">public class="kw">static boolean setHotbarItem(@Nonnull Ref<EntityStore> var0, @Nullable String var1, byte var2, @Nonnull ComponentAccessor<EntityStore> var3) {
if (var1 != null && !var1.isEmpty() && itemKeyExists(var1)) {
InventoryComponent.Hotbar var4 = var3.getComponent(var0, InventoryComponent.Hotbar.getComponentType());
if (var4 != null && checkHotbarSlot(var0, var2, var3)) {
ItemContainer var5 = var4.getInventory();
if (matchesItem(var1, var5.getItemStack(var2))) {
class="kw">return true;
}
var5.setItemStackForSlot(var2, createItem(var1));
class="kw">return true;
} else {
class="kw">return false;
}
} else {
class="kw">return false;
}
}
class="kw">public class="kw">static boolean setOffHandItem(@Nonnull Ref<EntityStore> var0, @Nullable String var1, byte var2, @Nonnull ComponentAccessor<EntityStore> var3) {
if (var1 != null && !var1.isEmpty() && itemKeyExists(var1)) {
InventoryComponent.Utility var4 = var3.getComponent(var0, InventoryComponent.Utility.getComponentType());
if (var4 != null && checkOffHandSlot(var0, var2, var3)) {
ItemContainer var5 = var4.getInventory();
if (matchesItem(var1, var5.getItemStack(var2))) {
class="kw">return true;
}
var5.setItemStackForSlot(var2, createItem(var1));
class="kw">return true;
} else {
class="kw">return false;
}
} else {
class="kw">return false;
}
}
class="kw">public class="kw">static boolean useItem(@Nonnull Ref<EntityStore> var0, @Nullable String var1, byte var2, @Nonnull ComponentAccessor<EntityStore> var3) {
if (var1 == null || var1.isEmpty() || !itemKeyExists(var1)) {
class="kw">return false;
}
if (holdsItem(var0, var3, var1)) {
class="kw">return true;
}
byte var4 = findHotbarSlotWithItem(var0, var3, var1);
if (var4 >= 0) {
InventoryUtils.setActiveSlot(var0, -1, var4, var3);
class="kw">return true;
}
if (var2 == -1) {
var2 = findHotbarEmptySlot(var0, var3);
}
if (var2 == -1) {
var2 = 0;
}
InventoryComponent.Hotbar var5 = var3.getComponent(var0, InventoryComponent.Hotbar.getComponentType());
if (var5 != null) {
var5.getInventory().setItemStackForSlot(var2, createItem(var1));
var5.setActiveSlot(var2, var0, var3);
}
class="kw">return true;
}
@Nullable
class="kw">public class="kw">static ItemStack createItem(@Nullable String var0) {
class="kw">return !itemKeyExists(var0) ? null : new ItemStack(var0, 1);
}
class="kw">public class="kw">static boolean useItem(@Nonnull Ref<EntityStore> var0, @Nullable String var1, @Nonnull ComponentAccessor<EntityStore> var2) {
class="kw">return var1 != null && !var1.isEmpty() ? useItem(var0, var1, (byte)-1, var2) : clearItemInHand(var0, (byte)-1, var2);
}
class="kw">public class="kw">static boolean useArmor(@Nonnull ItemContainer var0, @Nullable String var1) {
ItemStack var2 = createItem(var1);
class="kw">return useArmor(var0, var2);
}
class="kw">public class="kw">static boolean useArmor(@Nonnull ItemContainer var0, @Nullable ItemStack var1) {
if (var1 == null) {
class="kw">return false;
}
Item var2 = var1.getItem();
if (var2 == null) {
class="kw">return false;
}
ItemArmor var3 = var2.getArmor();
if (var3 == null) {
class="kw">return false;
}
short var4 = (short)var3.getArmorSlot().ordinal();
class="kw">return var4 >= 0 && var4 <= var0.getCapacity() ? var0.setItemStackForSlot(var4, var1).succeeded() : false;
}
}