本文整理了Java中org.bukkit.inventory.ItemStack.setDurability()
方法的一些代码示例,展示了ItemStack.setDurability()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.setDurability()
方法的具体详情如下:
包路径:org.bukkit.inventory.ItemStack
类名称:ItemStack
方法名:setDurability
[英]Sets the durability of this item
[中]设置此项目的耐久性
代码示例来源: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
/**
* Get a list of all recipes for a given item. The stack size is ignored in comparisons.
* If the durability is -1, it will match any data value.
*
* @param result The item whose recipes you want
* @return The list of recipes
*/
public List<Recipe> getRecipesFor(ItemStack result) {
// handling for old-style wildcards
if (result.getDurability() == -1) {
result = result.clone();
result.setDurability(Short.MAX_VALUE);
}
List<Recipe> recipes = new LinkedList<>();
for (Recipe recipe : this) {
if (matchesWildcard(result, recipe.getResult())) {
recipes.add(recipe);
}
}
return recipes;
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
GlowBanner state = (GlowBanner) block.getState();
ItemStack drop = new ItemStack(Material.BANNER, 1);
BannerMeta meta = (BannerMeta) drop.getItemMeta();
meta.setPatterns(state.getPatterns());
drop.setItemMeta(meta);
drop.setDurability(state.getBaseColor().getDyeData());
return Arrays.asList(drop);
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
GlowSkull skull = (GlowSkull) block.getState();
ItemStack drop = new ItemStack(Material.SKULL_ITEM, 1);
if (skull.hasOwner()) {
SkullMeta meta = (SkullMeta) drop.getItemMeta();
meta.setOwner(skull.getOwner());
drop.setItemMeta(meta);
}
drop.setDurability((short) skull.getSkullType().ordinal());
return Arrays.asList(drop);
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Inflicts damage to an item. Unbreaking enchantment is applied if present.
*
* @param player the player holding the item, or null if held by a dispenser
* @param holding the item
*
* @return the updated item stack
*/
public static ItemStack damageItem(GlowPlayer player, ItemStack holding) {
if (player != null && player.getGameMode() == GameMode.CREATIVE) {
return holding;
}
// Apply unbreaking enchantment.
// TODO: Armor has a different formula for chance to avoid damage
int durability = holding.getEnchantmentLevel(Enchantment.DURABILITY);
if (durability > 0 && ThreadLocalRandom.current().nextDouble() < 1 / (durability + 1)) {
return holding;
}
holding.setDurability((short) (holding.getDurability() + 1));
if (holding.getDurability() == holding.getType().getMaxDurability() + 1) {
if (player != null) {
EventFactory.getInstance()
.callEvent(new PlayerItemBreakEvent(player, holding));
}
return createEmptyStack();
}
return holding;
}
代码示例来源:origin: GlowstoneMC/Glowstone
hand.setDurability((short) (hand.getDurability() + 1));
player.getInventory().setItem(message.getHandSlot(), hand);
} else {
代码示例来源:origin: GlowstoneMC/Glowstone
&& player.getGameMode() != GameMode.CREATIVE) {
itemInHand.setDurability((short) (itemInHand.getDurability() + durabilityLoss));
代码示例来源:origin: GlowstoneMC/Glowstone
&& holding.getDurability() > holding.getType().getMaxDurability()) {
holding.setAmount(holding.getAmount() - 1);
holding.setDurability((short) 0);
代码示例来源:origin: jiongjionger/NeverLag
public IconMaker setDurability(short d) {
this.item.setDurability(d);
return this;
}
代码示例来源:origin: Bkm016/TabooLib
public ItemBuilder damage(int damage) {
itemStack.setDurability((short) damage);
return this;
}
代码示例来源:origin: Slikey/EffectLib
protected void displayItem(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, Material material, byte materialData, double range, List<Player> targetPlayers) {
if (material == null || material == Material.AIR) {
return;
}
ItemStack item = new ItemStack(material);
item.setDurability(materialData);
display(particle, center, offsetX, offsetY, offsetZ, speed, amount, item, range, targetPlayers);
}
代码示例来源:origin: elBukkit/MagicPlugin
public static void setMapId(ItemStack mapItem, int id) {
if (isCurrentVersion()) {
setMetaInt(mapItem, "map", id);
} else {
mapItem.setDurability((short)id);
}
}
}
代码示例来源:origin: artex-development/Lukkit
@Override
public LuaValue call(LuaValue value) {
item.setDurability(value.checknumber().toshort());
return NIL;
}
});
代码示例来源:origin: SpigotMC/Spigot-API
/**
* 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: elBukkit/MagicPlugin
protected void updateDurability() {
int maxDurability = item.getType().getMaxDurability();
if (maxDurability > 0 && effectiveManaMax > 0) {
int durability = (short)(getMana() * maxDurability / effectiveManaMax);
durability = maxDurability - durability;
if (durability >= maxDurability) {
durability = maxDurability - 1;
} else if (durability < 0) {
durability = 0;
}
item.setDurability((short)durability);
}
}
代码示例来源:origin: jiongjionger/NeverLag
public IconMaker setOwner(String username) {
if (this.item != null && this.item.getType() == Material.SKULL_ITEM) {
this.item.setDurability((short) 3); // 3: Player
SkullMeta sm = (SkullMeta) item.getItemMeta();
sm.setOwner(username);
item.setItemMeta(sm);
}
return this;
}
}
代码示例来源:origin: garbagemule/MobArena
@EventHandler
public void onBreak(BlockBreakEvent event) {
Player p = event.getPlayer();
if (!p.equals(player)) return;
ItemStack tool = p.getInventory().getItemInMainHand();
if (!isTool(tool)) return;
event.setCancelled(true);
tool.setDurability((short) 0);
}
代码示例来源:origin: Bkm016/TabooLib
public static ItemStack addDurability(ItemStack i, int d) {
i.setDurability((short) (i.getDurability() + d));
int min = i.getDurability();
int max = i.getType().getMaxDurability();
if (min >= max) {
i.setType(Material.AIR);
}
return i;
}
代码示例来源:origin: EngineHub/WorldGuard
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
WorldConfiguration wcfg = getWorldConfig(player);
if (!wcfg.itemDurability) {
ItemStack held = player.getItemInHand();
if (held.getType() != Material.AIR) {
held.setDurability((short) 0);
player.setItemInHand(held);
}
}
}
代码示例来源: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)));
}
内容来源于网络,如有侵权,请联系作者删除!