当前位置: 首页>>代码示例>>Java>>正文


Java ItemStack.clone方法代码示例

本文整理汇总了Java中org.bukkit.inventory.ItemStack.clone方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.clone方法的具体用法?Java ItemStack.clone怎么用?Java ItemStack.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.inventory.ItemStack的用法示例。


在下文中一共展示了ItemStack.clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLeftOverItems

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public List<? extends ItemStack> getLeftOverItems(CraftingInventory craftingInventory) {
    ItemStack[] matrix = craftingInventory.getMatrix();
    List<ItemStack> leftOver = new ArrayList<>(matrix.length);
    
    for (int i = 0; i < matrix.length; i++) {
        ItemStack itemStack = matrix[i];
        
        if (InventoryUtils.isEmptyStack(itemStack)) {
            leftOver.add(null);
            continue;
        }
        
        ItemStack clone = itemStack.clone();
        MaterialData craftingResult = InventoryUtils.getSingleIngredientResult(itemStack.getData());
        if (craftingResult.getItemType() != Material.AIR) {
            clone.setData(craftingResult);
            leftOver.add(clone);           
            continue;
        }
    }
    
    craftingInventory.setContents(leftOver.toArray(new ItemStack[matrix.length]));
    return leftOver;
}
 
开发者ID:Jannyboy11,项目名称:CustomRecipes,代码行数:29,代码来源:SimpleCraftingRecipe.java

示例2: putItemInSlot

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
 * tries to add item {@link toPut} to item {@link before} and returns the result
 * item.<br>
 * if the item couldn't be inserted, the result item is equal to {@link before}.
 */
protected ItemStack putItemInSlot(ItemStack toPut, ItemStack before) {
	if (toPut == null) {
		return before;
	}
	if (before == null) {
		ItemStack returnCopy = toPut.clone();
		toPut.setAmount(0);
		return returnCopy;
	}
	ItemStack beforeItemStack = before.clone();
	if (beforeItemStack.isSimilar(toPut)) {
		int beforeAmount = beforeItemStack.getAmount();
		beforeItemStack.setAmount(Math.min(before.getMaxStackSize(), beforeAmount + toPut.getAmount()));
		toPut.setAmount(Math.max(0, toPut.getAmount() - (before.getMaxStackSize() - beforeAmount)));
	}
	return beforeItemStack;
}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:23,代码来源:BlockContainer.java

示例3: onSmelt

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public void onSmelt(FurnaceSmeltEvent e)
{
    if(BlockStorage.check(e.getBlock()) != null && (BlockStorage.check(e.getBlock()) instanceof EnhancedFurnace))
    {
        EnhancedFurnace furnace = (EnhancedFurnace)BlockStorage.check(e.getBlock());
        Furnace f = (Furnace)e.getBlock().getState();
        int amount = f.getInventory().getSmelting().getType().toString().endsWith("_ORE") ? furnace.getOutput() : 1;
        ItemStack output = RecipeCalculator.getSmeltedOutput(f.getInventory().getSmelting().getType());
        ItemStack result = f.getInventory().getResult();
        if(result != null)
            result = result.clone();
        f.getInventory().setResult(null);
        if(result != null)
            f.getInventory().setResult(new CustomItem(result, result.getAmount() + amount <= result.getMaxStackSize() ? result.getAmount() + amount : result.getMaxStackSize()));
        else
            f.getInventory().setResult(new CustomItem(output, output.getAmount() + amount <= output.getType().getMaxStackSize() ? output.getAmount() + amount : output.getType().getMaxStackSize()));
    }
}
 
开发者ID:StarWishsama,项目名称:Slimefun4-Chinese-Version,代码行数:19,代码来源:FurnaceListener.java

示例4: refillOneWoolPerContainer

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Repeatable(interval = @Time(seconds = 30), scope = MatchScope.RUNNING)
public void refillOneWoolPerContainer() {
    if(!Config.Wool.autoRefillWoolChests()) return;

    for(Entry<Inventory, Map<Integer, ItemStack>> chest : this.woolChests.entrySet()) {
        Inventory inv = chest.getKey();
        for(Entry<Integer, ItemStack> slotEntry : chest.getValue().entrySet()) {
            int slot = slotEntry.getKey();
            ItemStack wool = slotEntry.getValue();
            ItemStack stack = inv.getItem(slotEntry.getKey());

            if(stack == null) {
                stack = wool.clone();
                stack.setAmount(1);
                inv.setItem(slot, stack);
                break;
            } else if(stack.isSimilar(wool) && stack.getAmount() < wool.getAmount()) {
                stack.setAmount(stack.getAmount() + 1);
                inv.setItem(slot, stack);
                break;
            }
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:25,代码来源:WoolMatchModule.java

示例5: attach

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static ItemStack attach(ItemStack it, String id) {
	ItemStack i = it.clone();
	ItemMeta m = i.getItemMeta();
	
	List<String> lore = new ArrayList<String>();
	
	lore.addAll(Arrays.asList(new String[] {ChatColor.RESET + "" + ChatColor.DARK_GRAY + id}));
	if (m.getLore() != null && !m.getLore().isEmpty()) {
		lore.add("");
		lore.addAll(m.getLore());
	}
	
	m.setLore(lore);
	i.setItemMeta(m);
	
	return i;
}
 
开发者ID:GigaGamma,项目名称:McLink,代码行数:18,代码来源:ItemId.java

示例6: lockFlagIgnored

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Test
public void lockFlagIgnored() throws Throwable {
    ItemStack ref = new ItemStack(Material.BEDROCK);
    ItemStack query = ref.clone();
    ItemTags.LOCKED.set(query, true);
    assertMatches(ref, query);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:ItemMatcherTest.java

示例7: encrypted

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private ItemStack encrypted(ItemStack itemStack, String textToEncrypt) {
    final ItemMeta itemMeta = itemStack.getItemMeta();
    final List<String> lore = itemMeta.getLore() != null
        ? itemMeta.getLore()
        : new ArrayList<String>();
    lore.add(encrypted(textToEncrypt));
    itemMeta.setLore(lore);

    final ItemStack encryptedItemStack = itemStack.clone();
    encryptedItemStack.setItemMeta(itemMeta);
    return encryptedItemStack;
}
 
开发者ID:Personinblack,项目名称:black,代码行数:13,代码来源:BasicElement.java

示例8: saveGoldenPipeInv

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void saveGoldenPipeInv(Player p, Inventory inv) {
	if (inv != null && goldenPipeInventories.containsValue(inv)) {
		GoldenPipe pipe = null;
		//get pipe with inventory
		for (GoldenPipe gp : goldenPipeInventories.keySet()) {
			if (goldenPipeInventories.get(gp).equals(inv)) {
				pipe = gp;
				break;
			}
		}
		//cache new items in golden pipe
		linefor: for (int line = 0; line < 6; line++) {
			ItemData[] items = pipe.getFilteringItems(WrappedDirection.fromID(line));
			int scrollValue = scrollValues.get(pipe).containsKey(line) ? scrollValues.get(pipe).get(line) : 0;
			for (int i = 2; i < 8; i++) {
				ItemStack is = inv.getItem(line * 9 + i);
				//make sure the glass pane won't be saved
				if (!InventoryUtils.isGlassItemOrBarrier(is)) {
					if (is != null && is.getAmount() > 1) {
						ItemStack drop = is.clone();
						drop.setAmount(is.getAmount() - 1);
						p.getWorld().dropItem(p.getLocation(), drop);
						is.setAmount(1);
					}
					items[scrollValue] = is != null ? new ItemData(is) : null;
				} else {
					//skip this save-sequenz if this line is not available (not a pipe or block as neighbor)
					continue linefor;
				}
				scrollValue++;
			}
		}
	}
}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:35,代码来源:GoldenPipeInv.java

示例9: CraftingOperation

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public CraftingOperation(Block block, ItemStack stack) {
	this.block = block;
	ItemStack toDrop = stack.clone();
	toDrop.setAmount(1);
	stack.setAmount(stack.getAmount()-1);
	Item item = block.getWorld().dropItem(block.getLocation().add(0.5, 1.2, 0.5), toDrop);
	item.setVelocity(new Vector(0,0,0));
	item.teleport(block.getLocation().add(0.5, 1.5, 0.5));
	item.setPickupDelay(Integer.MAX_VALUE);
	item.setGlowing(true);
	item.setGravity(false);
	this.book = item;
	items = new HashMap<Item, BukkitRunnable>();
}
 
开发者ID:mcardy,项目名称:MystiCraft,代码行数:15,代码来源:CraftingOperation.java

示例10: setDisplayName

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static ItemStack setDisplayName(ItemStack itemStack, String name) {
    itemStack = itemStack.clone();
    ItemMeta meta = itemStack.getItemMeta();
    meta.setDisplayName(name);
    itemStack.setItemMeta(meta);
    return itemStack;
}
 
开发者ID:DRE2N,项目名称:FactionsXL,代码行数:8,代码来源:GUIButton.java

示例11: onCommand

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public boolean onCommand(CommandSender cs, String[] args) {

	if (!cs.hasPermission("transportpipes.creative")) {
		return false;
	}

	if (cs instanceof Player) {
		Inventory inv = Bukkit.createInventory(null, 9 * 3, LocConf.load(LocConf.CREATIVE_TITLE));

		int i = 0;
		List<ItemStack> ductItems = DuctItemUtils.getAllDuctItems();
		for (ItemStack is : ductItems) {
			ItemStack clonedIs = is.clone();
			clonedIs.setAmount(16);
			inv.setItem(i, clonedIs);
			i++;
		}
		inv.setItem(i++, DuctItemUtils.getClonedWrenchItem());

		((Player) cs).openInventory(inv);
	} else {
		cs.sendMessage("§cYou're not a player!");
	}

	return true;
}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:28,代码来源:CreativeCommandExecutor.java

示例12: withdrawInventoryAtomic

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
 * Remove items from inventory.
 * Either all removed or none removed.
 *
 * @param inv           the inventory
 * @param itemToBeTaken items to be removed
 * @return If null, then all designated items are removed. If not null, it contains the items missing
 */
public static List<ItemStack> withdrawInventoryAtomic(Inventory inv, List<ItemStack> itemToBeTaken) {
    ItemStack[] itemStacks = inv.getContents();
    ItemStack[] cloneStacks = new ItemStack[itemStacks.length];
    for (int i = 0; i < itemStacks.length; i++) {
        cloneStacks[i] = itemStacks[i] == null ? null : itemStacks[i].clone();
    }

    List<ItemStack> ret = new ArrayList<>();

    for (ItemStack item : itemToBeTaken) {
        int sizeReq = item.getAmount();

        for (int i = 0; i < cloneStacks.length; i++) {
            if (cloneStacks[i] == null) continue;
            if (cloneStacks[i].isSimilar(item)) {
                int sizeSupp = cloneStacks[i].getAmount();
                if (sizeSupp > sizeReq) {
                    cloneStacks[i].setAmount(sizeSupp - sizeReq);
                    sizeReq = 0;
                    break;
                } else {
                    cloneStacks[i] = null;
                    sizeReq -= sizeSupp;
                    if (sizeReq == 0) break;
                }
            }
        }

        if (sizeReq > 0) {
            ItemStack n = item.clone();
            item.setAmount(sizeReq);
            ret.add(n);
        }
    }

    if (ret.size() == 0) {
        inv.setContents(cloneStacks);
        return null;
    } else {
        return ret;
    }
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:51,代码来源:InventoryUtils.java

示例13: matches

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public boolean matches(ItemStack anotherItem) {
    ItemStack base = itemTemplate.clone();
    ItemStack given = anotherItem.clone();
    base.setAmount(1);
    given.setAmount(1);
    if (requireExact) return base.equals(given);
    if (!base.getType().equals(given.getType())) return false;

    if (repairCostMatch == MatchingMode.EXACT &&
            base.getItemMeta() instanceof Repairable && given.getItemMeta() instanceof Repairable &&
            !(((Repairable) given.getItemMeta()).getRepairCost() == ((Repairable) base.getItemMeta()).getRepairCost())) {
        return false;
    }

    int baseDamage = base.getDurability();
    int givenDamage = given.getDurability();
    if (minDamageValue == -2 && givenDamage < baseDamage) return false;
    if (minDamageValue >= 0 && givenDamage < minDamageValue) return false;
    if (maxDamageValue == -2 && givenDamage > baseDamage) return false;
    if (maxDamageValue >= 0 && givenDamage > maxDamageValue) return false;

    String baseDisplay = getDisplayName(base);
    String givenDisplay = getDisplayName(given);
    if (nameMatch == MatchingMode.EXACT && !baseDisplay.equals(givenDisplay)) return false;
    if (nameMatch == MatchingMode.EXACT_TEXT && !ChatColor.stripColor(baseDisplay).equals(ChatColor.stripColor(givenDisplay)))
        return false;
    if (nameMatch == MatchingMode.CONTAINS && !givenDisplay.contains(baseDisplay)) return false;
    if (nameMatch == MatchingMode.CONTAINS_TEXT && !ChatColor.stripColor(givenDisplay).contains(ChatColor.stripColor(baseDisplay)))
        return false;

    Map<Enchantment, Integer> baseEnch = base.getEnchantments();
    Map<Enchantment, Integer> givenEnch = given.getEnchantments();
    if (enchantMatch == MatchingMode.EXACT || enchantMatch == MatchingMode.EXACT_TEXT) {
        if (!baseEnch.equals(givenEnch)) return false;
    } else if (enchantMatch == MatchingMode.CONTAINS || enchantMatch == MatchingMode.CONTAINS_TEXT) {
        for (Map.Entry<Enchantment, Integer> e : baseEnch.entrySet()) {
            if (!givenEnch.containsKey(e.getKey()) || givenEnch.get(e.getKey()) < e.getValue())
                return false;
        }
    }

    String[] baseLore = getLore(base);
    String[] givenLore = getLore(given);
    if (loreMatch == MatchingMode.EXACT && !Arrays.deepEquals(baseLore, givenLore)) return false;
    if (loreMatch == MatchingMode.CONTAINS && !containStrArr(givenLore, baseLore, false)) return false;
    if (loreMatch == MatchingMode.EXACT_TEXT) {
        for (int i = 0; i < baseLore.length; i++) baseLore[i] = ChatColor.stripColor(baseLore[i]);
        for (int i = 0; i < givenLore.length; i++) givenLore[i] = ChatColor.stripColor(givenLore[i]);
        if (!Arrays.deepEquals(baseLore, givenLore)) return false;
    }
    if (loreMatch == MatchingMode.CONTAINS_TEXT && !containStrArr(givenLore, baseLore, true)) return false;

    return true;
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:55,代码来源:BasicItemMatcher.java

示例14: ItemBuilder

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public ItemBuilder(final ItemStack is) {
	this.is = is.clone();
}
 
开发者ID:ijoeleoli,项目名称:ServerCommons,代码行数:4,代码来源:ItemBuilder.java

示例15: onPlayerInteract

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
 * Fill a legacy chest
 *
 * @param event Event
 */
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getClickedBlock().getType().equals(Material.CHEST))
    {
        Chest chest = (Chest) event.getClickedBlock().getState();

        if (chest.hasMetadata("playerInteracted"))
            return;

        Inventory inventory = chest.getInventory();
        inventory.clear();

        int addedItems = 0;
        int slot;

        for (ItemStack item : this.items.keySet())
        {
            if (addedItems > 20)
                break;

            int frequency = 0;

            for(Map.Entry<ItemStack, Integer> entry : this.items.entrySet())
                if(entry.getKey().equals(item))
                    frequency = entry.getValue();

            SecureRandom random = new SecureRandom();

            if (random.nextInt(1000) <= frequency * 10)
            {
                ItemStack stack = item.clone();
                stack.setAmount((random.nextInt(3) + 1) * stack.getAmount());

                slot = random.nextInt(inventory.getSize());

                while (inventory.getItem(slot) != null)
                {
                    slot++;

                    if (slot >= inventory.getSize())
                        slot = 0;
                }

                inventory.setItem(slot, this.addMetaIfNeeded(stack));
                addedItems++;
            }
        }

        chest.setMetadata("playerInteracted", new FixedMetadataValue(this.plugin, true));
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:58,代码来源:RandomChestModule.java


注:本文中的org.bukkit.inventory.ItemStack.clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。