org.bukkit.inventory.ItemStack.getTypeId()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中org.bukkit.inventory.ItemStack.getTypeId()方法的一些代码示例,展示了ItemStack.getTypeId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.getTypeId()方法的具体详情如下:
包路径:org.bukkit.inventory.ItemStack
类名称:ItemStack
方法名:getTypeId

ItemStack.getTypeId介绍

[英]Gets the type id of this item
[中]获取此项的类型id

代码示例

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public int first(int materialId) {
  int i = 0;
  for (ItemStack slotItem : this) {
    if (slotItem == null) {
      if (materialId == 0) {
        return i;
      }
    } else if (slotItem.getTypeId() == materialId) {
      return i;
    }
    i++;
  }
  return -1;
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public boolean contains(ItemStack item, int amount) {
  return contains(item.getTypeId(), amount);
}

代码示例来源:origin: GlowstoneMC/Glowstone

private boolean compareItems(ItemStack a, ItemStack b, boolean ignoreMeta) {
  if (ignoreMeta) {
    return a.getTypeId() == b.getTypeId() && a.getDurability() == b.getDurability();
  }
  return a.isSimilar(b);
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public HashMap<Integer, ItemStack> all(int materialId) {
  HashMap<Integer, ItemStack> result = new HashMap<>();
  int i = 0;
  for (ItemStack slotItem : this) {
    if (!InventoryUtil.isEmpty(slotItem) && slotItem.getTypeId() == materialId) {
      result.put(i, InventoryUtil.itemOrEmpty(slotItem));
    }
    i++;
  }
  return result;
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Gets the type of this item
 *
 * @return Type of the items in this stack
 */
@Utility
public Material getType() {
  return getType0(getTypeId());
}

代码示例来源:origin: Bukkit/Bukkit

@Override
@Utility
public final int hashCode() {
  int hash = 1;
  hash = hash * 31 + getTypeId();
  hash = hash * 31 + getAmount();
  hash = hash * 31 + (getDurability() & 0xffff);
  hash = hash * 31 + (hasItemMeta() ? (meta == null ? getItemMeta().hashCode() : meta.hashCode()) : 0);
  return hash;
}

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Write an item stack to the buffer.
 *
 * @param buf The buffer.
 * @param stack The stack to write, or null.
 */
public static void writeSlot(ByteBuf buf, ItemStack stack) {
  if (InventoryUtil.isEmpty(stack)) {
    buf.writeShort(-1);
  } else {
    buf.writeShort(stack.getTypeId());
    buf.writeByte(stack.getAmount());
    buf.writeShort(stack.getDurability());
    if (stack.hasItemMeta()) {
      CompoundTag tag = GlowItemFactory.instance().writeNbt(stack.getItemMeta());
      writeCompound(buf, tag);
    } else {
      writeCompound(buf, null);
    }
  }
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * This method is the same as equals, but does not consider stack size
 * (amount).
 *
 * @param stack the item stack to compare to
 * @return true if the two stacks are equal, ignoring the amount
 */
@Utility
public boolean isSimilar(ItemStack stack) {
  if (stack == null) {
    return false;
  }
  if (stack == this) {
    return true;
  }
  return getTypeId() == stack.getTypeId() && getDurability() == stack.getDurability() && hasItemMeta() == stack.hasItemMeta() && (hasItemMeta() ? Bukkit.getItemFactory().equals(getItemMeta(), stack.getItemMeta()) : true);
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Creates a new item stack derived from the specified stack
 *
 * @param stack the stack to copy
 * @throws IllegalArgumentException if the specified stack is null or
 *     returns an item meta not created by the item factory
 */
public ItemStack(final ItemStack stack) throws IllegalArgumentException {
  Validate.notNull(stack, "Cannot copy null stack");
  this.type = stack.getTypeId();
  this.amount = stack.getAmount();
  this.durability = stack.getDurability();
  this.data = stack.getData();
  if (stack.hasItemMeta()) {
    setItemMeta0(stack.getItemMeta(), getType0());
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
@Deprecated
public int clear(int id, int data) {
  int numCleared = 0;
  for (int i = 0; i < getSize(); ++i) {
    ItemStack stack = getItem(i);
    if (stack != null && (id == -1 || stack.getTypeId() == id) && (data == -1
        || stack.getData().getData() == data)) {
      setItem(i, InventoryUtil.createEmptyStack());
      if (!InventoryUtil.isEmpty(stack)) {
        // never report AIR as removed - else will report all empty slots cleared
        numCleared += stack.getAmount(); // report # items, not # stacks removed
      }
    }
  }
  return numCleared;
}

代码示例来源:origin: GlowstoneMC/Glowstone

return new int[]{item.getTypeId(), item.getDurability()};

代码示例来源:origin: bergerkiller/BKCommonLib

@SuppressWarnings("deprecation")
public static int getTypeId(ItemStack item) {
  return item.getTypeId();
}

代码示例来源:origin: SpigotMC/Spigot-API

/**
 * Gets the type of this item
 *
 * @return Type of the items in this stack
 */
@Utility
public Material getType() {
  return getType0(getTypeId());
}

代码示例来源:origin: SpigotMC/Spigot-API

@Override
@Utility
public final int hashCode() {
  int hash = 1;
  hash = hash * 31 + getTypeId();
  hash = hash * 31 + getAmount();
  hash = hash * 31 + (getDurability() & 0xffff);
  hash = hash * 31 + (hasItemMeta() ? (meta == null ? getItemMeta().hashCode() : meta.hashCode()) : 0);
  return hash;
}

代码示例来源:origin: MylesIsCool/ViaVersion

public static Item convert(ItemStack itemInHand) {
    if (itemInHand == null) return new Item((short) 0, (byte) 0, (short) 0, null);
    return new Item((short) itemInHand.getTypeId(), (byte) itemInHand.getAmount(), itemInHand.getDurability(), null);
  }
}

代码示例来源:origin: xXKeyleXx/MyPet

public int getBlockID() {
  return getMyPet().getBlock() != null ? getMyPet().getBlock().getTypeId() : 0;
}

代码示例来源:origin: marcelo-mason/PreciousStones

/**
 * @param item
 */
public ItemStackEntry(ItemStack item) {
  this.typeId = item.getTypeId();
  this.data = item.getData().getData();
  this.durability = item.getDurability();
  this.enchantments = item.getEnchantments();
  this.amount = item.getAmount();
}

代码示例来源:origin: bergerkiller/BKCommonLib

/**
 * Transfers the item type, data and enchantments from one item stack to the other
 * 
 * @param from which Item Stack to read the info
 * @param to which Item Stack to transfer the info to
 */
@SuppressWarnings("deprecation")
public static void transferInfo(org.bukkit.inventory.ItemStack from, org.bukkit.inventory.ItemStack to) {
  // Transfer type, durability and any other remaining metadata information
  to.setTypeId(from.getTypeId());
  to.setDurability(from.getDurability());
  setMetaTag(to, LogicUtil.clone(getMetaTag(from)));
}

代码示例来源:origin: marcelo-mason/PreciousStones

public static boolean hasItems(Player player, BlockTypeEntry item, int amount) {
  for (ItemStack i : player.getInventory()) {
    if (i == null) {
      continue;
    }
    if (i.getTypeId() == item.getTypeId()) {
      if (item.getData() == 0 || i.getData().getData() == item.getData()) {
        amount -= i.getAmount();
      }
    }
  }
  return amount <= 0;
}

代码示例来源:origin: MylesIsCool/ViaVersion

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e) {
  HumanEntity human = e.getWhoClicked();
  if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
    final Player player = (Player) human;
    if (e.getCurrentItem() != null) {
      if (ArmorType.isArmor(e.getCurrentItem().getTypeId())) {
        sendDelayedArmorUpdate(player);
        return;
      }
    }
    if (e.getRawSlot() >= 5 && e.getRawSlot() <= 8) {
      sendDelayedArmorUpdate(player);
    }
  }
}

相关文章