本文整理汇总了Java中net.minecraft.item.ItemStack.isStackable方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.isStackable方法的具体用法?Java ItemStack.isStackable怎么用?Java ItemStack.isStackable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemStack
的用法示例。
在下文中一共展示了ItemStack.isStackable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canItemStacksStackRelaxed
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* A relaxed version of canItemStacksStack that stacks itemstacks with different metadata if they don't have subtypes.
* This usually only applies when players pick up items.
*/
public static boolean canItemStacksStackRelaxed(ItemStack a, ItemStack b)
{
if (a == null || b == null || a.getItem() != b.getItem())
return false;
if (!a.isStackable())
return false;
// Metadata value only matters when the item has subtypes
// Vanilla stacks non-subtype items with different metadata together
// e.g. a stick with metadata 0 and a stick with metadata 1 stack
if (a.getHasSubtypes() && a.getMetadata() != b.getMetadata())
return false;
return ItemStack.areItemStackTagsEqual(a, b);
}
示例2: combineSlots
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
static void combineSlots(EntityPlayerMP player, int dst, int add)
{
InventoryPlayer inv = player.inventory;
ItemStack dstStack = inv.getStackInSlot(dst);
ItemStack addStack = inv.getStackInSlot(add);
if (addStack == null)
return; // Combination is a no-op.
if (dstStack == null) // Do a straight move - nothing to combine with.
{
inv.setInventorySlotContents(dst, addStack);
inv.setInventorySlotContents(add, null);
return;
}
// Check we can combine. This logic comes from InventoryPlayer.storeItemStack():
boolean itemsMatch = dstStack.getItem() == addStack.getItem();
boolean dstCanStack = dstStack.isStackable() && dstStack.stackSize < dstStack.getMaxStackSize() && dstStack.stackSize < inv.getInventoryStackLimit();
boolean subTypesMatch = !dstStack.getHasSubtypes() || dstStack.getMetadata() == addStack.getMetadata();
boolean tagsMatch = ItemStack.areItemStackTagsEqual(dstStack, addStack);
if (itemsMatch && dstCanStack && subTypesMatch && tagsMatch)
{
// We can combine, so figure out how much we have room for:
int limit = Math.min(dstStack.getMaxStackSize(), inv.getInventoryStackLimit());
int room = limit - dstStack.stackSize;
if (addStack.stackSize > room)
{
// Not room for all of it, so shift across as much as possible.
addStack.stackSize -= room;
dstStack.stackSize += room;
}
else
{
// Room for the whole lot, so empty out the add slot.
dstStack.stackSize += addStack.stackSize;
inv.setInventorySlotContents(add, null);
}
}
}
示例3: doesRecipeMatch
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static boolean doesRecipeMatch(ItemStack[] recipeItems, InventoryCrafting matrix, World world)
{
int requiredMatches = 9;
int matches = 0;
int currentSlot = 0;
ItemStack currentStack;
while (currentSlot < 9) // Going through all 9 slots
{
currentStack = matrix.getStackInSlot(currentSlot); // Hand me your item, slot
if (currentStack != null && recipeItems[currentSlot] != null)
{
if (currentStack.getItem() != recipeItems[currentSlot].getItem())
{
return false; // Not the right item
}
else if (currentStack.isItemStackDamageable() && currentStack.getItemDamage() != recipeItems[currentSlot].getItemDamage())
{
return false; // Damage doesn't match up
}
else if (currentStack.isStackable() && currentStack.stackSize < recipeItems[currentSlot].stackSize)
{
return false; // Not the right amount
}
else
{
matches += 1; // Seems to check out
}
}
else if (currentStack == null && recipeItems[currentSlot] == null)
{
matches += 1; // Both null, so that works for me too
}
// Next!
currentSlot += 1;
}
//if (!world.isRemote) { System.out.println("[RECIPE] Found " + matches + " matches out of " + requiredMatches + "."); }
if (matches == requiredMatches) { return true; } // Found all we need
else { return false; } // Not enough
}
示例4: canMergeStacks
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean canMergeStacks(ItemStack stack1, ItemStack stack2)
{
return !stack1.func_190926_b() && this.stackEqualExact(stack1, stack2) && stack1.isStackable() && stack1.func_190916_E() < stack1.getMaxStackSize() && stack1.func_190916_E() < this.getInventoryStackLimit();
}
示例5: insertItemStacked
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Inserts the ItemStack into the inventory, filling up already present stacks first.
* This is equivalent to the behaviour of a player picking up an item.
* Note: This function stacks items without subtypes with different metadata together.
*/
public static ItemStack insertItemStacked(IItemHandler inventory, ItemStack stack, boolean simulate)
{
if (inventory == null || stack == null)
return stack;
// not stackable -> just insert into a new slot
if (!stack.isStackable())
{
return insertItem(inventory, stack, simulate);
}
int sizeInventory = inventory.getSlots();
// go through the inventory and try to fill up already existing items
for (int i = 0; i < sizeInventory; i++)
{
ItemStack slot = inventory.getStackInSlot(i);
if (canItemStacksStackRelaxed(slot, stack))
{
stack = inventory.insertItem(i, stack, simulate);
if (stack == null)
{
break;
}
}
}
// insert remainder into empty slots
if (stack != null)
{
// find empty slot
for (int i = 0; i < sizeInventory; i++)
{
if (inventory.getStackInSlot(i) == null)
{
stack = inventory.insertItem(i, stack, simulate);
if (stack == null)
{
break;
}
}
}
}
return stack;
}
示例6: canMergeStacks
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean canMergeStacks(@Nullable ItemStack stack1, ItemStack stack2)
{
return stack1 != null && this.stackEqualExact(stack1, stack2) && stack1.isStackable() && stack1.stackSize < stack1.getMaxStackSize() && stack1.stackSize < this.getInventoryStackLimit();
}
示例7: canMergeItemStacks
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean canMergeItemStacks(@Nonnull ItemStack stack, @Nonnull ItemStack other) {
if (stack.isEmpty() || other.isEmpty() || !stack.isStackable() || !other.isStackable()) {
return false;
}
return stack.isItemEqual(other) && ItemStack.areItemStackTagsEqual(stack, other);
}