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


Java ItemStack.isSimilar方法代码示例

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


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

示例1: tryToSaveSlot

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public boolean tryToSaveSlot(int slot) {
    Inventory inv = player.getInventory();
    ItemStack item = inv.getItem(slot);
    if (item == null)
        return true;
    ListIterator<ItemStack> i = inv.iterator();
    while (i.hasNext()) {
        int ind = i.nextIndex();
        ItemStack itm = i.next();
        if (ind == slot || (ind < 9 && hotbarsBySlot[ind] != null))
            continue;
        if(itm == null) {
            i.set(item);
            return true;
        } else if (itm.isSimilar(item)) {
            int free = itm.getAmount() - itm.getMaxStackSize();
            if(item.getAmount() > free) {
                itm.setAmount(itm.getMaxStackSize());
            } else {
                itm.setAmount(itm.getAmount() + free);
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:27,代码来源:HotbarView.java

示例2: isSimilar

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public boolean isSimilar(ItemStack stack) {
    if (stack == null) {
        return false;
    }
    if (stack == this) {
        return true;
    }
    if (!(stack instanceof CraftItemStack)) {
        return stack.getClass() == ItemStack.class && stack.isSimilar(this);
    }

    CraftItemStack that = (CraftItemStack) stack;
    if (handle == that.handle) {
        return true;
    }
    if (handle == null || that.handle == null) {
        return false;
    }
    if (!(that.getTypeId() == getTypeId() && getDurability() == that.getDurability())) {
        return false;
    }
    return hasItemMeta() ? that.hasItemMeta() && handle.stackTagCompound.equals(that.handle.stackTagCompound) : !that.hasItemMeta();
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:25,代码来源:CraftItemStack.java

示例3: takeOneItem

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean takeOneItem(Player p, ItemStack item) {
    for (int k = 0; k < p.getInventory().getSize(); k++) {
        ItemStack i = p.getInventory().getItem(k);
        if (i != null && i.isSimilar(item)) {
            if (i.getAmount() > 1) {
                i.setAmount(i.getAmount() - 1);
                p.getInventory().setItem(k, i);
                p.updateInventory();
            } else {
                i.setType(Material.AIR);
                i.setAmount(0);
                p.getInventory().setItem(k, null);
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:19,代码来源:ItemManager.java

示例4: takeItem

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean takeItem(Inventory inv, ItemStack item, int takeAmount) {
    Set<Integer> removeSlots = new HashSet<>(takeAmount);
    for (int i = 0; i < inv.getSize(); i++) {
        ItemStack elemItem = inv.getItem(i);
        if (elemItem == null || elemItem.getType() == Material.AIR
                || !elemItem.isSimilar(item))
            continue;

        int amount = elemItem.getAmount();
        if (takeAmount > amount) {
            takeAmount -= amount;
            removeSlots.add(i);
        } else {
            if (takeAmount < amount) {
                elemItem.setAmount(amount - takeAmount);
            } else {
                removeSlots.add(i);
            }
            removeSlots.forEach(inv::clear);
            return true;
        }
    }
    return false;
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:25,代码来源:Inventories.java

示例5: onPlayerInteractEntity

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
  public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
      Player p = event.getPlayer();
      Entity e = event.getRightClicked();
int slot = p.getInventory().getHeldItemSlot();
if(slot >= 0 && slot < 9){
	ItemStack itemInHand = p.getInventory().getContents()[slot];
	if(itemInHand != null && itemInHand.getType() != Material.AIR && itemInHand.isSimilar(SelectorLayout.getSelectorItem())){
		new SelectorMenu(p, 0).open(p);
		event.setCancelled(true);
		return;
	}
      }

      if (ReflectionUtil.getEntityHandle(e) instanceof IEntityPet) {
          IPet pet = ((IEntityPet) ReflectionUtil.getEntityHandle(e)).getPet();
          event.setCancelled(true);
          PetInteractEvent iEvent = new PetInteractEvent(pet, p, PetInteractEvent.Action.RIGHT_CLICK, false);
          EchoPet.getPlugin().getServer().getPluginManager().callEvent(iEvent);
          if (!iEvent.isCancelled()) {
              pet.getEntityPet().onInteract(p);
              return;
          }
      }
  }
 
开发者ID:Borlea,项目名称:EchoPet,代码行数:26,代码来源:PetOwnerListener.java

示例6: howMuchSpaceForItemAsync

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public int howMuchSpaceForItemAsync(WrappedDirection insertDirection, ItemStack insertion) {
	if (!cachedChunk.isLoaded()) {
		return 0;
	}
	if (isInvLocked(cachedInvHolder)) {
		return 0;
	}
	int freeSpace = 0;
	for (int i = 0; i < cachedInv.getSize(); i++) {
		ItemStack is = cachedInv.getItem(i);
		if (is == null || is.getType() == Material.AIR) {
			freeSpace += insertion.getMaxStackSize();
		} else if (is.isSimilar(insertion) && is.getAmount() < is.getMaxStackSize()) {
			freeSpace += is.getMaxStackSize() - is.getAmount();
		}
	}
	return freeSpace;
}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:20,代码来源:SimpleInventoryContainer.java

示例7: hasInputItems

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public boolean hasInputItems( ItemStack itemStack, int amount ) {
    int count = 0;
    int i = 0;
    for ( ItemStack craftingSlot : craftingSlots ) {
        if ( i != 0 ) {
            if ( craftingSlot != null && craftingSlot.getType() != Material.AIR ) {
                if ( craftingSlot.isSimilar( itemStack ) ) {
                    count++;
                }
            }
        }
        i++;
    }
    return count == amount;
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:17,代码来源:FlexPlayerInventory.java

示例8: containsAtLeast

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public boolean containsAtLeast(ItemStack item, int amount) {
    if (item == null) {
        return false;
    }
    if (amount <= 0) {
        return true;
    }
    for (ItemStack i : getContents()) {
        if (item.isSimilar(i) && (amount -= i.getAmount()) <= 0) {
            return true;
        }
    }
    return false;
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:15,代码来源:CraftInventory.java

示例9: first

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private int first(ItemStack item, boolean withAmount) {
    if (item == null) {
        return -1;
    }
    ItemStack[] inventory = getContents();
    for (int i = 0; i < inventory.length; i++) {
        if (inventory[i] == null) continue;

        if (withAmount ? item.equals(inventory[i]) : item.isSimilar(inventory[i])) {
            return i;
        }
    }
    return -1;
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:15,代码来源:CraftInventory.java

示例10: firstPartial

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private int firstPartial(ItemStack item) {
    if (item == null) {
        return -1;
    }
    ItemStack[] inventory = getContents();
    ItemStack filteredItem = CraftItemStack.asCraftCopy(item);
    for (int i = 0; i < inventory.length; i++) {
        ItemStack cItem = inventory[i];
        if (cItem != null && cItem.getAmount() < cItem.getMaxStackSize() && cItem.isSimilar(filteredItem)) {
            return i;
        }
    }
    return -1;
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:15,代码来源:CraftInventory.java

示例11: hasItem

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean hasItem(Player p, ItemStack item) {
    for (int k = 0; k < p.getInventory().getSize(); k++) {
        ItemStack i = p.getInventory().getItem(k);
        if (i != null && i.isSimilar(item)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:10,代码来源:ItemManager.java

示例12: getSkillBySelector

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public Skill getSkillBySelector(ItemStack item) {
    Skill result = null;
    for (Skill s : skills) {
        ItemStack skill = s.getSelector();
        if (skill.isSimilar(item)) {
            result = s;
        }
    }
    return result;
}
 
开发者ID:Soldier233,项目名称:ArchersBattle,代码行数:11,代码来源:SkillManager.java

示例13: getPriorQuantity

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
 * Return the quantity of items stackable with the given item that
 * the player was in posession of prior to the transfer event. This
 * includes any items being carried on the cursor.
 */
public int getPriorQuantity(ItemStack type) {
    int quantity = 0;
    for(ItemStack stack : this.player.getInventory().contents()) {
        if(stack != null && stack.isSimilar(type)) {
            quantity += stack.getAmount();
        }
    }
    if(this.cursorItems != null && this.cursorItems.isSimilar(type)) {
        quantity += this.cursorItems.getAmount();
    }
    return quantity;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:18,代码来源:PlayerItemTransferEvent.java

示例14: processClickEvent

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void processClickEvent(InventoryClickEvent event) {
    if (event.getAction() == InventoryAction.COLLECT_TO_CURSOR) {
        ItemStack cursorItem = event.getCursor();
        Inventory topInv = event.getView().getTopInventory();
        for (int i = 0; i < topInv.getSize(); i++) {
            ItemStack item = topInv.getItem(i);
            if (item != null && item.isSimilar(cursorItem)) {
                event.setCancelled(true);
                break;
            }
        }
    }
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:14,代码来源:ClickHandler.java

示例15: extractItem

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack extractItem(WrappedDirection extractDirection, int extractAmount, List<ItemData> filterItems,
		FilteringMode filteringMode) {
	if (!cachedChunk.isLoaded()) {
		return null;
	}
	if (isInvLocked(cachedInvHolder)) {
		return null;
	}
	ItemStack takenIs = null;
	for (int i = 0; i < cachedInv.getSize(); i++) {
		if (cachedInv.getItem(i) != null) {
			int amountBefore = takenIs != null ? takenIs.getAmount() : 0;
			if (takenIs == null) {
				if (new ItemData(cachedInv.getItem(i)).checkFilter(filterItems, filteringMode)) {
					takenIs = cachedInv.getItem(i).clone();
					takenIs.setAmount(Math.min(extractAmount, takenIs.getAmount()));
				} else {
					continue;
				}
			} else if (takenIs.isSimilar(cachedInv.getItem(i))) {
				takenIs.setAmount(Math.min(extractAmount, amountBefore + cachedInv.getItem(i).getAmount()));
			}
			ItemStack invItem = cachedInv.getItem(i);
			cachedInv.setItem(i, InventoryUtils.changeAmount(invItem, -(takenIs.getAmount() - amountBefore)));
		}
	}
	if (takenIs != null) {
		block.getState().update();
	}
	return takenIs;
}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:33,代码来源:SimpleInventoryContainer.java


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