public static boolean itemsEqualForCrafting(final ItemStack stack1, final ItemStack stack2) { return areEqualNoMeta(stack1, stack2) && (!stack1.getHasSubtypes() || OreDictionaryHelper.isGeneric(stack1) || OreDictionaryHelper.isGeneric(stack2) || getItemDamage(stack2) == getItemDamage(stack1)); }
/** * @param stack1 The {@link ItemStack} being compared. * @param stack2 The {@link ItemStack} to compare to. * @return whether the two items are the same in terms of damage and itemID. */ public static boolean areStacksSameType(ItemStack stack1, ItemStack stack2) { return stack1 != null && stack2 != null && (stack1.getItem() == stack2.getItem() && (!stack2.getHasSubtypes() || stack2.getItemDamage() == stack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack2, stack1)); }
/** * Adds an ItemStack to the first available slot in the provided IInventory, continuing to * distribute the stack as necessary until the stacksize reaches 0, if possible * * @return the number of items remaining in the stack, zero if all were added */ public static int addItemToInventory(ItemStack stack, IInventory inv) { int remaining = stack.stackSize; for (int i = 0; i < inv.getSizeInventory() && remaining > 0; ++i) { ItemStack slotstack = inv.getStackInSlot(i); if (slotstack == null && inv.isItemValidForSlot(i, stack)) { remaining -= inv.getInventoryStackLimit(); stack.stackSize = (remaining > 0 ? inv.getInventoryStackLimit() : stack.stackSize); inv.setInventorySlotContents(i, stack); inv.markDirty(); } else if (slotstack != null && stack.isStackable() && inv.isItemValidForSlot(i, stack)) { if (slotstack.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getItemDamage() == slotstack.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, slotstack)) { int l = slotstack.stackSize + remaining; if (l <= stack.getMaxStackSize() && l <= inv.getInventoryStackLimit()) { remaining = 0; slotstack.stackSize = l; inv.markDirty(); } else if (slotstack.stackSize < stack.getMaxStackSize() && stack.getMaxStackSize() <= inv.getInventoryStackLimit()) { remaining -= stack.getMaxStackSize() - slotstack.stackSize; slotstack.stackSize = stack.getMaxStackSize(); inv.markDirty(); } } } } return remaining; }
/** * checks that there is an item to be smelted in one of the input slots and that there is room for * the result in the output slots If desired, performs the smelt * * @param performSmelt if true, perform the smelt. if false, check whether smelting is possible, * but don't change the inventory * @return false if no items can be smelted, true otherwise */ private boolean smeltItem(boolean performSmelt) { Integer firstSuitableInputSlot = null; Integer firstSuitableOutputSlot = null; ItemStack result = null; // finds the first input slot which is smeltable and whose result fits into an output slot // (stacking if possible) for (int inputSlot = FIRST_INPUT_SLOT; inputSlot < FIRST_INPUT_SLOT + INPUT_SLOTS_COUNT; inputSlot++) { if (itemStacks[inputSlot] != null) { result = getSmeltingResultForItem(itemStacks[inputSlot]); if (result != null) { // find the first suitable output slot- either empty, or with identical item that has // enough space for (int outputSlot = FIRST_OUTPUT_SLOT; outputSlot < FIRST_OUTPUT_SLOT + OUTPUT_SLOTS_COUNT; outputSlot++) { ItemStack outputStack = itemStacks[outputSlot]; if (outputStack == null) { firstSuitableInputSlot = inputSlot; firstSuitableOutputSlot = outputSlot; break; } if (outputStack.getItem() == result.getItem() && (!outputStack.getHasSubtypes() || outputStack.getMetadata() == outputStack.getMetadata()) && ItemStack.areItemStackTagsEqual(outputStack, result)) { int combinedSize = itemStacks[outputSlot].stackSize + result.stackSize; if (combinedSize <= getInventoryStackLimit() && combinedSize <= itemStacks[outputSlot].getMaxStackSize()) { firstSuitableInputSlot = inputSlot; firstSuitableOutputSlot = outputSlot; break; } } } if (firstSuitableInputSlot != null) break; } } } if (firstSuitableInputSlot == null) return false; if (!performSmelt) return true; // alter input and output itemStacks[firstSuitableInputSlot].stackSize--; if (itemStacks[firstSuitableInputSlot].stackSize <= 0) itemStacks[firstSuitableInputSlot] = null; if (itemStacks[firstSuitableOutputSlot] == null) { itemStacks[firstSuitableOutputSlot] = result.copy(); // Use deep .copy() to avoid altering the recipe } else { itemStacks[firstSuitableOutputSlot].stackSize += result.stackSize; } markDirty(); return true; }
public static int countItemNames(ItemStack item) { if (getItemDamage(item) == CraftGuide.DAMAGE_WILDCARD && item.getHasSubtypes()) { ArrayList<ItemStack> temp = new ArrayList<ItemStack>(); item.getItem().getSubItems(item.getItem(), null, temp); return temp.size(); } else { return 1; } }
@Override public boolean matches(IItemStack item) { ItemStack internal = getItemStack(item); return internal != null && stack != null && internal.getItem() == stack.getItem() && (wildcardSize || internal.getCount() >= stack.getCount()) && (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack.getItemDamage() == internal.getItemDamage() || (!stack.getHasSubtypes() && !stack.getItem().isDamageable())); }
public static List<String> itemNames(ItemStack item) { ArrayList<String> list = new ArrayList<String>(); if (getItemDamage(item) == CraftGuide.DAMAGE_WILDCARD && item.getHasSubtypes()) { ArrayList<ItemStack> subItems = new ArrayList<ItemStack>(); item.getItem().getSubItems(item.getItem(), null, subItems); for (ItemStack stack : subItems) { list.add(itemName(stack)); } } else { list.add(itemName(item)); } return list; }
private int FindSlotToStoreItemStack(ItemStack itemstack) { for (int i = 0; i < getSizeInventory(); i++) { ItemStack itemstack1 = GetStackInSlot(i); if (itemstack1 != null && itemstack1.itemID == itemstack.itemID && itemstack1.isStackable() && itemstack1.stackSize < itemstack1.getMaxStackSize() && itemstack1.stackSize < getInventoryStackLimit() && (!itemstack1.getHasSubtypes() || itemstack1.getItemDamage() == itemstack.getItemDamage())) { return i; } } return -1; }
public boolean equalsItemStack(ItemStack is, boolean ignoreSize) { if (is == null) { return false; } if (id != is.itemID) { return false; } if (damage != is.getItemDamage() && damage != -1 && is.getItemDamage() != -1 && is.getHasSubtypes()) { return false; } if (!ignoreSize && size != is.stackSize) { return false; } return true; }
public static String itemName(ItemStack item) { String idText = ""; if (Minecraft.getMinecraft().gameSettings.advancedItemTooltips) { if (item.getHasSubtypes()) { idText = String.format( " (%s #%04d/%d)", Item.itemRegistry.getNameForObject(item.getItem()), Item.getIdFromItem(item.getItem()), getItemDamage(item)); } else { idText = String.format( " (%s #%04d)", Item.itemRegistry.getNameForObject(item.getItem()), Item.getIdFromItem(item.getItem())); } } return item.getDisplayName() + idText; }
private int placeInSpecialInvent(ItemStack itemstack1, int i, boolean doAdd) { if (cargoItems[i] == null) { if (doAdd) cargoItems[i] = itemstack1; return itemstack1.stackSize; } else if (cargoItems[i] != null && cargoItems[i].itemID == itemstack1.itemID && itemstack1.isStackable() && (!itemstack1.getHasSubtypes() || cargoItems[i].getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(cargoItems[i], itemstack1)) { int var9 = cargoItems[i].stackSize + itemstack1.stackSize; if (var9 <= itemstack1.getMaxStackSize()) { if (doAdd) cargoItems[i].stackSize = var9; return var9; } else if (cargoItems[i].stackSize < itemstack1.getMaxStackSize()) { if (doAdd) cargoItems[i].stackSize = cargoItems[i].getMaxStackSize(); return Math.abs( cargoItems[i].getMaxStackSize() - cargoItems[i].stackSize - itemstack1.stackSize); } } return itemstack1.stackSize; }
private static boolean isItemStackConsideredEqual(ItemStack result, ItemStack itemstack1) { return itemstack1 != null && itemstack1.getItem() == result.getItem() && (!result.getHasSubtypes() || result.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(result, itemstack1); }
/** merges provided ItemStack with the first avaliable one in the container/player inventory */ protected boolean mergeItemStack(ItemStack par1ItemStack, int par2, int par3, boolean par4) { boolean var5 = false; int var6 = par2; if (par4) { var6 = par3 - 1; } Slot var7; ItemStack var8; if (par1ItemStack.isStackable()) { while (par1ItemStack.stackSize > 0 && (!par4 && var6 < par3 || par4 && var6 >= par2)) { var7 = (Slot) this.inventorySlots.get(var6); var8 = var7.getStack(); if (var8 != null && var8.itemID == par1ItemStack.itemID && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == var8.getItemDamage()) && ItemStack.areItemStackTagsEqual(par1ItemStack, var8)) { int var9 = var8.stackSize + par1ItemStack.stackSize; if (var9 <= par1ItemStack.getMaxStackSize()) { par1ItemStack.stackSize = 0; var8.stackSize = var9; var7.onSlotChanged(); var5 = true; } else if (var8.stackSize < par1ItemStack.getMaxStackSize()) { par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - var8.stackSize; var8.stackSize = par1ItemStack.getMaxStackSize(); var7.onSlotChanged(); var5 = true; } } if (par4) { --var6; } else { ++var6; } } } if (par1ItemStack.stackSize > 0) { if (par4) { var6 = par3 - 1; } else { var6 = par2; } while (!par4 && var6 < par3 || par4 && var6 >= par2) { var7 = (Slot) this.inventorySlots.get(var6); var8 = var7.getStack(); if (var8 == null) { var7.putStack(par1ItemStack.copy()); var7.onSlotChanged(); par1ItemStack.stackSize = 0; var5 = true; break; } if (par4) { --var6; } else { ++var6; } } } return var5; }
public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) { ItemStack var5 = null; InventoryPlayer var6 = par4EntityPlayer.inventory; Slot var7; ItemStack var8; int var10; ItemStack var11; if ((par3 == 0 || par3 == 1) && (par2 == 0 || par2 == 1)) { if (par1 == -999) { if (var6.getItemStack() != null && par1 == -999) { if (par2 == 0) { par4EntityPlayer.dropPlayerItem(var6.getItemStack()); var6.setItemStack((ItemStack) null); } if (par2 == 1) { // CraftBukkit start - store a reference ItemStack itemstack3 = var6.getItemStack(); par4EntityPlayer.dropPlayerItem(itemstack3.splitStack(1)); if (itemstack3.stackSize == 0) { // CraftBukkit end var6.setItemStack((ItemStack) null); } } } } else if (par3 == 1) { var7 = (Slot) this.inventorySlots.get(par1); if (var7 != null && var7.canTakeStack(par4EntityPlayer)) { var8 = this.transferStackInSlot(par4EntityPlayer, par1); if (var8 != null) { int var12 = var8.itemID; var5 = var8.copy(); if (var7 != null && var7.getStack() != null && var7.getStack().itemID == var12) { this.retrySlotClick(par1, par2, true, par4EntityPlayer); } } } } else { if (par1 < 0) { return null; } var7 = (Slot) this.inventorySlots.get(par1); if (var7 != null) { var8 = var7.getStack(); ItemStack var13 = var6.getItemStack(); if (var8 != null) { var5 = var8.copy(); } if (var8 == null) { if (var13 != null && var7.isItemValid(var13)) { var10 = par2 == 0 ? var13.stackSize : 1; if (var10 > var7.getSlotStackLimit()) { var10 = var7.getSlotStackLimit(); } if (var13.stackSize >= var10) // CraftBukkit var7.putStack(var13.splitStack(var10)); if (var13.stackSize == 0) { var6.setItemStack((ItemStack) null); } } } else if (var7.canTakeStack(par4EntityPlayer)) { if (var13 == null) { var10 = par2 == 0 ? var8.stackSize : (var8.stackSize + 1) / 2; var11 = var7.decrStackSize(var10); var6.setItemStack(var11); if (var8.stackSize == 0) { var7.putStack((ItemStack) null); } var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack()); } else if (var7.isItemValid(var13)) { if (var8.itemID == var13.itemID && var8.getItemDamage() == var13.getItemDamage() && ItemStack.areItemStackTagsEqual(var8, var13)) { var10 = par2 == 0 ? var13.stackSize : 1; if (var10 > var7.getSlotStackLimit() - var8.stackSize) { var10 = var7.getSlotStackLimit() - var8.stackSize; } if (var10 > var13.getMaxStackSize() - var8.stackSize) { var10 = var13.getMaxStackSize() - var8.stackSize; } var13.splitStack(var10); if (var13.stackSize == 0) { var6.setItemStack((ItemStack) null); } var8.stackSize += var10; } else if (var13.stackSize <= var7.getSlotStackLimit()) { var7.putStack(var13); var6.setItemStack(var8); } } else if (var8.itemID == var13.itemID && var13.getMaxStackSize() > 1 && (!var8.getHasSubtypes() || var8.getItemDamage() == var13.getItemDamage()) && ItemStack.areItemStackTagsEqual(var8, var13)) { var10 = var8.stackSize; if (var10 > 0 && var10 + var13.stackSize <= var13.getMaxStackSize()) { var13.stackSize += var10; var8 = var7.decrStackSize(var10); if (var8.stackSize == 0) { var7.putStack((ItemStack) null); } var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack()); } } } var7.onSlotChanged(); } } } else if (par3 == 2 && par2 >= 0 && par2 < 9) { var7 = (Slot) this.inventorySlots.get(par1); if (var7.canTakeStack(par4EntityPlayer)) { var8 = var6.getStackInSlot(par2); boolean var9 = var8 == null || var7.inventory == var6 && var7.isItemValid(var8); var10 = -1; if (!var9) { var10 = var6.getFirstEmptyStack(); var9 |= var10 > -1; } if (var7.getHasStack() && var9) { var11 = var7.getStack(); var6.setInventorySlotContents(par2, var11); if ((var7.inventory != var6 || !var7.isItemValid(var8)) && var8 != null) { if (var10 > -1) { var6.addItemStackToInventory(var8); var7.decrStackSize(var11.stackSize); var7.putStack((ItemStack) null); var7.onPickupFromSlot(par4EntityPlayer, var11); } } else { var7.decrStackSize(var11.stackSize); var7.putStack(var8); var7.onPickupFromSlot(par4EntityPlayer, var11); } } else if (!var7.getHasStack() && var8 != null && var7.isItemValid(var8)) { var6.setInventorySlotContents(par2, (ItemStack) null); var7.putStack(var8); } } } else if (par3 == 3 && par4EntityPlayer.capabilities.isCreativeMode && var6.getItemStack() == null && par1 >= 0) { var7 = (Slot) this.inventorySlots.get(par1); if (var7 != null && var7.getHasStack()) { var8 = var7.getStack().copy(); var8.stackSize = var8.getMaxStackSize(); var6.setItemStack(var8); } } return var5; }
protected boolean mergeItemStack( ItemStack par1ItemStack, int par2, int par3, boolean par4, Slot ss) { boolean flag1 = false; int k = par2; if (par4) { k = par3 - 1; } Slot slot; ItemStack itemstack1; if (par1ItemStack.isStackable()) { while (par1ItemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2)) { slot = (Slot) this.inventorySlots.get(k); itemstack1 = slot.getStack(); if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1)) { int l = itemstack1.stackSize + par1ItemStack.stackSize; if (l <= par1ItemStack.getMaxStackSize()) { // if (ss instanceof SlotBauble) unequipBauble(par1ItemStack); par1ItemStack.stackSize = 0; itemstack1.stackSize = l; slot.onSlotChanged(); flag1 = true; } else if (itemstack1.stackSize < par1ItemStack.getMaxStackSize()) { // if (ss instanceof SlotBauble) unequipBauble(par1ItemStack); par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize; itemstack1.stackSize = par1ItemStack.getMaxStackSize(); slot.onSlotChanged(); flag1 = true; } } if (par4) { --k; } else { ++k; } } } if (par1ItemStack.stackSize > 0) { if (par4) { k = par3 - 1; } else { k = par2; } while (!par4 && k < par3 || par4 && k >= par2) { slot = (Slot) this.inventorySlots.get(k); itemstack1 = slot.getStack(); if (itemstack1 == null) { // if (ss instanceof SlotBauble) unequipBauble(par1ItemStack); slot.putStack(par1ItemStack.copy()); slot.onSlotChanged(); par1ItemStack.stackSize = 0; flag1 = true; break; } if (par4) { --k; } else { ++k; } } } return flag1; }
@Override protected boolean mergeItemStack(ItemStack stack, int start, int end, boolean inverse) { boolean flag1 = false; int k = start; if (inverse) k = end - 1; Slot slot; ItemStack itemstack1; if (stack.isStackable()) { while (stack.stackSize > 0 && (!inverse && k < end || inverse && k >= start)) { slot = (Slot) this.inventorySlots.get(k); if (slot.isItemValid(stack)) { itemstack1 = slot.getStack(); if (itemstack1 != null && itemstack1.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { int l = itemstack1.stackSize + stack.stackSize; if (l <= stack.getMaxStackSize()) { stack.stackSize = 0; itemstack1.stackSize = l; slot.onSlotChanged(); flag1 = true; } else if (itemstack1.stackSize < stack.getMaxStackSize()) { stack.stackSize -= stack.getMaxStackSize() - itemstack1.stackSize; itemstack1.stackSize = stack.getMaxStackSize(); slot.onSlotChanged(); flag1 = true; } } } if (inverse) --k; else ++k; } } if (stack.stackSize > 0) { if (inverse) k = end - 1; else k = start; while (!inverse && k < end || inverse && k >= start) { slot = (Slot) this.inventorySlots.get(k); if (slot.isItemValid(stack)) { itemstack1 = slot.getStack(); if (itemstack1 == null) { slot.putStack(stack.copy()); slot.onSlotChanged(); stack.stackSize = 0; flag1 = true; break; } } if (inverse) --k; else ++k; } } return flag1; }
public static Optional<ItemStack> getItemStack(final String name, final int quantity) { if (name == null || name.isEmpty()) return Optional.absent(); // Check our preferred list first. If we have a hit, use it. ItemStack result = PreferredItemStacks.instance.get(name); if (result != null) { result = result.copy(); result.stackSize = quantity; } else { // Parse out the possible subtype from the end of the string String workingName = name; int subType = -1; if (StringUtils.countMatches(name, ":") == 2) { workingName = StringUtils.substringBeforeLast(name, ":"); final String num = StringUtils.substringAfterLast(name, ":"); if (num != null && !num.isEmpty()) { if ("*".compareTo(num) == 0) subType = OreDictionaryHelper.WILDCARD_VALUE; else { try { subType = Integer.parseInt(num); } catch (Exception e) { // It appears malformed - assume the incoming name // is // the real name and continue. ; } } } } // Check the OreDictionary first for any alias matches. Otherwise // go to the game registry to find a match. final List<ItemStack> ores = OreDictionaryHelper.getOres(workingName); if (!ores.isEmpty()) { result = ores.get(0).copy(); result.stackSize = quantity; } else { final Item i = GameData.getItemRegistry().getObject(workingName); if (i != null) { result = new ItemStack(i, quantity); } } // If we did have a hit on a base item, set the sub-type // as needed. if (result != null && subType != -1) { if (subType == OreDictionaryHelper.WILDCARD_VALUE && !result.getHasSubtypes()) { ModLog.warn("[%s] GENERIC requested but Item does not support sub-types", name); } else { result.setItemDamage(subType); } } } return Optional.fromNullable(result); }
protected boolean mergeItemStack( ItemStack par1ItemStack, int par2, int par3, boolean par4, Slot ss) { boolean flag1 = false; int k = par2; if (par4) { k = par3 - 1; } if (par1ItemStack.isStackable()) { while ((par1ItemStack.stackSize > 0) && (((!par4) && (k < par3)) || ((par4) && (k >= par2)))) { Slot slot = (Slot) this.inventorySlots.get(k); ItemStack itemstack1 = slot.getStack(); if ((itemstack1 != null) && (itemstack1.getItem() == par1ItemStack.getItem()) && ((!par1ItemStack.getHasSubtypes()) || (par1ItemStack.getItemDamage() == itemstack1.getItemDamage())) && (ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1))) { int l = itemstack1.stackSize + par1ItemStack.stackSize; if (l <= par1ItemStack.getMaxStackSize()) { if ((ss instanceof SlotRestricted)) if (((SlotRestricted) ss).isBaubleSlot()) unequipBauble(par1ItemStack); par1ItemStack.stackSize = 0; itemstack1.stackSize = l; slot.onSlotChanged(); flag1 = true; } else if (itemstack1.stackSize < par1ItemStack.getMaxStackSize()) { if ((ss instanceof SlotRestricted)) if (((SlotRestricted) ss).isBaubleSlot()) unequipBauble(par1ItemStack); par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize; itemstack1.stackSize = par1ItemStack.getMaxStackSize(); slot.onSlotChanged(); flag1 = true; } } if (par4) { k--; } else { k++; } } } if (par1ItemStack.stackSize > 0) { if (par4) { k = par3 - 1; } else { k = par2; } while (((!par4) && (k < par3)) || ((par4) && (k >= par2))) { Slot slot = (Slot) this.inventorySlots.get(k); ItemStack itemstack1 = slot.getStack(); if (itemstack1 == null) { if ((ss instanceof SlotRestricted)) if (((SlotRestricted) ss).isBaubleSlot()) unequipBauble(par1ItemStack); slot.putStack(par1ItemStack.copy()); slot.onSlotChanged(); par1ItemStack.stackSize = 0; flag1 = true; break; } if (par4) { k--; } else { k++; } } } return flag1; }
@Override protected boolean mergeItemStack(ItemStack stack, int slotStart, int slotRange, boolean reverse) { boolean successful = false; int slotIndex = slotStart; int maxStack = Math.min(stack.getMaxStackSize(), _ncw.getInventoryStackLimit()); if (reverse) { slotIndex = slotRange - 1; } Slot slot; ItemStack existingStack; if (stack.isStackable()) { while (stack.stackSize > 0 && (!reverse && slotIndex < slotRange || reverse && slotIndex >= slotStart)) { slot = (Slot) this.inventorySlots.get(slotIndex); existingStack = slot.getStack(); if (slot.isItemValid(stack) && existingStack != null && existingStack.getItem().equals(stack.getItem()) && (!stack.getHasSubtypes() || stack.getItemDamage() == existingStack.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, existingStack)) { int existingSize = existingStack.stackSize + stack.stackSize; if (existingSize <= maxStack) { stack.stackSize = 0; existingStack.stackSize = existingSize; slot.onSlotChanged(); successful = true; } else if (existingStack.stackSize < maxStack) { stack.stackSize -= maxStack - existingStack.stackSize; existingStack.stackSize = maxStack; slot.onSlotChanged(); successful = true; } } if (reverse) { --slotIndex; } else { ++slotIndex; } } } if (stack.stackSize > 0) { if (reverse) { slotIndex = slotRange - 1; } else { slotIndex = slotStart; } while (!reverse && slotIndex < slotRange || reverse && slotIndex >= slotStart) { slot = (Slot) this.inventorySlots.get(slotIndex); existingStack = slot.getStack(); if (slot.isItemValid(stack) && existingStack == null) { slot.putStack(stack.copy()); slot.onSlotChanged(); stack.stackSize = 0; successful = true; break; } if (reverse) { --slotIndex; } else { ++slotIndex; } } } return successful; }
@Override protected boolean mergeItemStack(ItemStack stack, int start, int end, boolean backwards) { boolean flag1 = false; int k = (backwards ? end - 1 : start); Slot slot; ItemStack itemstack1; if (stack.isStackable()) { while (stack.stackSize > 0 && (!backwards && k < end || backwards && k >= start)) { slot = (Slot) inventorySlots.get(k); itemstack1 = slot.getStack(); if (!slot.isItemValid(stack)) { continue; } if (itemstack1 != null && itemstack1.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, itemstack1)) { int l = itemstack1.stackSize + stack.stackSize; if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) { stack.stackSize = 0; itemstack1.stackSize = l; tileEntity.markDirty(); flag1 = true; } else if (itemstack1.stackSize < stack.getMaxStackSize() && l < slot.getSlotStackLimit()) { stack.stackSize -= stack.getMaxStackSize() - itemstack1.stackSize; itemstack1.stackSize = stack.getMaxStackSize(); tileEntity.markDirty(); flag1 = true; } } k += (backwards ? -1 : 1); } } if (stack.stackSize > 0) { k = (backwards ? end - 1 : start); while (!backwards && k < end || backwards && k >= start) { slot = (Slot) inventorySlots.get(k); itemstack1 = slot.getStack(); if (!slot.isItemValid(stack)) { continue; } if (itemstack1 == null) { int l = stack.stackSize; if (l <= slot.getSlotStackLimit()) { slot.putStack(stack.copy()); stack.stackSize = 0; tileEntity.markDirty(); flag1 = true; break; } else { putStackInSlot( k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage())); stack.stackSize -= slot.getSlotStackLimit(); tileEntity.markDirty(); flag1 = true; } } k += (backwards ? -1 : 1); } } return flag1; }