本文整理汇总了Java中org.bukkit.inventory.ItemStack.getMaxStackSize方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.getMaxStackSize方法的具体用法?Java ItemStack.getMaxStackSize怎么用?Java ItemStack.getMaxStackSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.ItemStack
的用法示例。
在下文中一共展示了ItemStack.getMaxStackSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDrops
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public List<ItemStack> getDrops(int multiplier) {
if (template == null || template.size() == 0) {
return new ArrayList<ItemStack>();
}
ArrayList<ItemStack> drops = new ArrayList<ItemStack>(template.size());
for (ItemStack i : template) {
int newSize = i.getAmount() * multiplier;
if (newSize <= 0) {
continue;
}
ItemStack clone = null;
while (newSize > i.getMaxStackSize()) {
clone = i.clone();
clone.setAmount(i.getMaxStackSize());
newSize -= i.getMaxStackSize();
drops.add(clone);
}
clone = i.clone();
clone.setAmount(newSize);
drops.add(clone);
}
return drops;
}
示例2: 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;
}
示例3: giveModularized
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private static void giveModularized(Player p, int amount, ItemStack base, String name) {
if (amount <= 0)
return;
ItemStack item = base.clone();
item.setAmount(amount);
HashMap<Integer, ItemStack> remaining = p.getInventory().addItem(item);
if (!remaining.isEmpty()) {
int extra = 0;
for (Entry<Integer, ItemStack> e : remaining.entrySet()) {
int remainingAmount = e.getValue().getAmount();
extra += remainingAmount;
while (remainingAmount > 0) {
ItemStack temp = base.clone();
if (remainingAmount > temp.getMaxStackSize())
temp.setAmount(temp.getMaxStackSize());
else
temp.setAmount(remainingAmount);
remainingAmount -= temp.getAmount();
p.getWorld().dropItem(p.getEyeLocation(), temp);
}
}
p.sendMessage(ChatColor.RED + "You ran out of inventory space for " + name + " you received.");
p.sendMessage(ChatColor.RED.toString() + extra + " extra " + name + " were dropped around you.");
}
}
示例4: 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;
}
示例5: howManyItemsFit
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
protected int howManyItemsFit(ItemStack toPut, ItemStack before) {
if (toPut == null) {
return 0;
}
if (before == null) {
return toPut.getMaxStackSize();
}
if (before.isSimilar(toPut)) {
if (before.getAmount() < before.getMaxStackSize()) {
return before.getMaxStackSize() - before.getAmount();
} else {
return 0;
}
} else {
return 0;
}
}
示例6: hasEnoughSpace
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean hasEnoughSpace(Inventory inventory, ItemStack item, int amount) {
for (int i = 0; i < inventory.getSize(); i++) {
if (i >= 36 && i <= 39 && inventory instanceof PlayerInventory) {
continue;
}
if (inventory.getItem(i) != null && item.isSimilar(inventory.getItem(i)) &&
inventory.getItem(i).getAmount() < item.getMaxStackSize()) {
amount -= item.getMaxStackSize() - inventory.getItem(i).getAmount();
} else if (inventory.getItem(i) == null || inventory.getItem(i).getType() == Material.AIR) {
amount = 0;
}
if (amount < 1) {
return true;
}
}
return false;
}
示例7: checkItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private static void checkItem(TOAUser p, ItemStack item) {
Inventory i = getInventory(p);
for (int x = 0; x < getInvSize(p); x++) {
if (i.getItem(x) != null) {
if ((i.getItem(x).getType() == item.getType()) && (i.getItem(x).getDurability() == item.getDurability()) &&
(i.getItem(x).getAmount() + item.getAmount() <= item.getMaxStackSize())) {
i.setItem(x, new ItemStack(item.getType(), item.getAmount() + i.getItem(x).getAmount(), item.getDurability()));
saveInv(p, i);
break;
}
} else if (i.getItem(x) == null) {
i.setItem(x, item);
saveInv(p, i);
break;
}
}
advisePlayer(p);
}
示例8: firstPartial
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public int firstPartial(int materialId) {
ItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) {
ItemStack item = inventory[i];
if (item != null && item.getTypeId() == materialId && item.getAmount() < item.getMaxStackSize()) {
return i;
}
}
return -1;
}
示例9: safeEventListener
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void safeEventListener(ItemSafeEvent safe) {
ItemStack item = safe.getItem();
if (item == null) return;
StandardGun gun = plugin.getGuns().findGun(item);
if (gun != null && gun.validGun(item)) {
safe.setValid();
return;
}
Magazine mag = plugin.getAmmo().findMagazine(item);
// TODO: validmag check
if (mag != null && item.getAmount() == 1) {
safe.setValid();
return;
}
Bullet bullet = plugin.getAmmo().findBullet(item);
if (bullet != null) {
if (item.getAmount() <= item.getMaxStackSize() && item.getAmount() > 0) {
safe.setValid();
}
}
}
示例10: isSpaceAvailable
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
static boolean isSpaceAvailable(Player player, ItemStack item)
{
//Exclude armor slots - ids 100, 101, 102, 103 - Normal Inventory is slots 0-35
for (int i = 0; i <= 35; i++ )
{
ItemStack slotItem = player.getInventory().getItem(i);
if (slotItem == null || (slotItem.getType() == item.getType()
&& item.getAmount() + slotItem.getAmount() <= slotItem.getMaxStackSize()))
{
return true;
}
}
return false;
}
示例11: hasSpace
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static int hasSpace(Inventory inv, ItemStack item) {
int space = 0;
for (int i = 0; i < inv.getSize(); i++) {
ItemStack element = inv.getItem(i);
if (element == null || element.getType() == Material.AIR) {
space += item.getMaxStackSize();
} else if (element.isSimilar(item)) {
space += item.getMaxStackSize() - element.getAmount();
}
}
return space;
}
示例12: giveItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static Map<Integer, ItemStack> giveItem(Inventory inv, ItemStack item, int amount) {
Map<Integer, ItemStack> map = new HashMap<>();
if (item != null) {
int maxStack = item.getMaxStackSize();
for (int i = 0; i < amount / maxStack; i++) {
map.putAll(inv.addItem(new ItemBuilder(item).amount(64).build()));
}
int remain = amount % maxStack;
if (remain > 0) {
map.putAll(inv.addItem(new ItemBuilder(item).amount(remain).build()));
}
}
return map;
}
示例13: isInventoryFull
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean isInventoryFull(Player player, ItemStack itemToAdd) {
for (int i = 0; i < 36; i++) {
if(player.getInventory().getItem(i) == null) {
return false;
}
ItemStack item = player.getInventory().getItem(i);
if(item.getType().equals(itemToAdd.getType()) && item.getAmount() + itemToAdd.getAmount() <= itemToAdd.getMaxStackSize()) {
return false;
}
}
return true;
}
示例14: matches
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean matches(ItemStack itemStack1, ItemStack itemStack2) {
if (itemStack1 == null || itemStack2 == null) {
return false;
}
if (!itemStack1.getType().equals(itemStack2.getType())) {
return false;
}
if (itemStack1.getAmount() != itemStack2.getAmount()) {
return false;
}
if (itemStack1.getDurability() != itemStack2.getDurability()) {
return false;
}
if (itemStack1.getMaxStackSize() != itemStack2.getMaxStackSize()) {
return false;
}
if (itemStack1.hasItemMeta() != itemStack2.hasItemMeta()) {
return false;
}
if (itemStack1.hasItemMeta() && itemStack2.hasItemMeta() && !itemStack1.getItemMeta().equals(itemStack2.getItemMeta())) {
return false;
}
return true;
}
示例15: hasInventorySpace
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean hasInventorySpace(Player p, ItemStack item) {
int free = 0;
for (int k = 0; k < 36; k++) {
ItemStack i = p.getInventory().getItem(k);
if (i == null) {
free += item.getMaxStackSize();
} else if (i.isSimilar(item)) {
free += item.getMaxStackSize() - i.getAmount();
}
}
return free >= item.getAmount();
}