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

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

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

ItemStack.getType介绍

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

代码示例

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

/**
 * Convenience method. Returns the material of the item represented by
 * this event
 *
 * @return Material the material of the item used
 */
public Material getMaterial() {
  if (!hasItem()) {
    return Material.AIR;
  }
  return item.getType();
}

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

/**
   * Check whether this target includes the specified item.
   *
   * @param item The item to check
   * @return True if the target includes the item
   */
  public boolean includes(ItemStack item) {
    return includes(item.getType());
  }
}

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

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
  if (tool != null && tool.getType() == Material.SHEARS) {
    return Arrays.asList(new ItemStack(Material.VINE));
  }
  return BlockDropless.EMPTY_STACK;
}

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

public static Potion fromItemStack(ItemStack item) {
  Validate.notNull(item, "item cannot be null");
  if (item.getType() != Material.POTION)
    throw new IllegalArgumentException("item is not a potion");
  return fromDamage(item.getDurability());
}

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

@Override
@Utility
public String toString() {
  StringBuilder toString = new StringBuilder("ItemStack{").append(getType().name()).append(" x ").append(getAmount());
  if (hasItemMeta()) {
    toString.append(", ").append(getItemMeta());
  }
  return toString.append('}').toString();
}

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

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
  if (tool != null && ToolType.SPADE.matches(tool.getType())) {
    return Arrays.asList(new ItemStack(Material.SNOW_BALL, 4));
  } else {
    return BlockDropless.EMPTY_STACK;
  }
}

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

/**
 * Convenience method to inform the user whether this was a block
 * placement event.
 *
 * @return boolean true if the item in hand was a block
 */
public boolean isBlockInHand() {
  if (!hasItem()) {
    return false;
  }
  return item.getType().isBlock();
}

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

/**
 * Get the maximum stacksize for the material hold in this ItemStack.
 * (Returns -1 if it has no idea)
 *
 * @return The maximum you can stack this material to.
 */
@Utility
public int getMaxStackSize() {
  Material material = getType();
  if (material != null) {
    return material.getMaxStackSize();
  }
  return -1;
}

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

private boolean matchesWildcard(ItemStack expected, ItemStack actual) {
  return actual != null && expected.getType() == actual.getType() && (
      isWildcard(expected.getDurability()) || expected.getDurability() == actual
          .getDurability());
}

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

/**
 * Applies the effects of this potion to the given {@link ItemStack}. The
 * ItemStack must be a potion.
 *
 * @param to The itemstack to apply to
 */
public void apply(ItemStack to) {
  Validate.notNull(to, "itemstack cannot be null");
  Validate.isTrue(to.getType() == Material.POTION, "given itemstack is not a potion");
  to.setDurability(toDamageValue());
}

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

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
  if (tool != null && ToolType.SPADE.matches(tool.getType())) {
    return Arrays.asList(new ItemStack(Material.SNOW_BALL, block.getData() + 1));
  } else {
    return BlockDropless.EMPTY_STACK;
  }
}

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

/**
 * Gets the MaterialData for this stack of items
 *
 * @return MaterialData for this item
 */
public MaterialData getData() {
  Material mat = getType();
  if (data == null && mat != null && mat.getData() != null) {
    data = mat.getNewData((byte) this.getDurability());
  }
  return data;
}

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

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
  if (block.getType() == Material.WOOD_STEP
      || tool != null && ToolType.PICKAXE.matches(tool.getType())) {
    return getMinedDrops(block);
  }
  return BlockDropless.EMPTY_STACK;
}

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

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
  MaterialMatcher neededTool = getNeededMiningTool(block);
  if (neededTool != null
    && (tool == null || !neededTool.matches(tool.getType()))) {
    return BlockDropless.EMPTY_STACK;
  }
  return getMinedDrops(block);
}

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

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
  if (block.getType() == Material.WOOD_DOUBLE_STEP
      || tool != null && ToolType.PICKAXE.matches(tool.getType())) {
    return getMinedDrops(block);
  }
  return BlockDropless.EMPTY_STACK;
}

代码示例来源:origin: EngineHub/WorldEdit

/**
 * Create a WorldEdit BaseItemStack from a Bukkit ItemStack
 *
 * @param itemStack The Bukkit ItemStack
 * @return The WorldEdit BaseItemStack
 */
public static BaseItemStack adapt(ItemStack itemStack) {
  checkNotNull(itemStack);
  return new BaseItemStack(ItemTypes.get(itemStack.getType().getKey().toString()), itemStack.getAmount());
}

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

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
  if (isWoodenStair(block.getType())
    || tool != null && ToolType.PICKAXE.matches(tool.getType())) {
    return getMinedDrops(block);
  }
  return BlockDropless.EMPTY_STACK;
}

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

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
  Collection<ItemStack> drops = getContentDrops(block);
  MaterialMatcher neededTool = getNeededMiningTool(block);
  if (neededTool == null
      || !InventoryUtil.isEmpty(tool) && neededTool
      .matches(InventoryUtil.itemOrEmpty(tool).getType())) {
    drops.addAll(getBlockDrops(block));
  }
  return drops;
}

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

protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
  BlockFace facing = BlockDispenser.getFacing(block);
  Vector dispensePosition = BlockDispenser.getDispensePosition(block);
  ItemStack items = new ItemStack(stack.getType(), 1);
  stack.setAmount(stack.getAmount() - 1);
  doDispense(block, items, 6, facing, dispensePosition);
  return stack.getAmount() > 0 ? stack : null;
}

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

@Override
public void rightClickAir(GlowPlayer player, ItemStack holding) {
  if (InventoryUtil.isEmpty(player.getEquipment().getChestplate())
    || player.getEquipment().getChestplate().getType() != Material.ELYTRA || !player
    .isGliding()) {
    return;
  }
  spawnFirework(player, holding, player.getLocation(), player.getUniqueId(), player);
}

相关文章