コード例 #1
1
ファイル: RMFurnaceTile.java プロジェクト: Roblomal/ProjectE
  private void pushOutput() {
    ItemStack output = inventory[outputSlot];

    if (output == null) {
      return;
    }

    for (int i = outputStorage[0]; i <= outputStorage[1]; i++) {
      ItemStack stack = inventory[i];

      if (stack == null) {
        inventory[i] = output;
        inventory[outputSlot] = null;
        return;
      } else {
        if (Utils.areItemStacksEqual(output, stack) && stack.stackSize < stack.getMaxStackSize()) {
          int remain = stack.getMaxStackSize() - stack.stackSize;

          if (output.stackSize <= remain) {
            inventory[outputSlot] = null;
            inventory[i].stackSize += output.stackSize;
            return;
          } else {
            this.decrStackSize(outputSlot, remain);
            inventory[i].stackSize += remain;
          }
        }
      }
    }
  }
コード例 #2
0
 public static boolean canInsertStackIntoInventory(
     IInventory inventory, ItemStack stack, int side) {
   if (stack == null || inventory == null) return false;
   if (inventory instanceof ISidedInventory) {
     ISidedInventory sidedInv = (ISidedInventory) inventory;
     int slots[] = sidedInv.getAccessibleSlotsFromSide(side);
     if (slots == null) return false;
     for (int i = 0; i < slots.length && stack != null; i++) {
       if (sidedInv.canInsertItem(slots[i], stack, side)
           && sidedInv.isItemValidForSlot(slots[i], stack)) {
         ItemStack existingStack = inventory.getStackInSlot(slots[i]);
         if (existingStack == null) return true;
         else if (OreDictionary.itemMatches(existingStack, stack, true)
             && ItemStack.areItemStackTagsEqual(stack, existingStack))
           if (existingStack.stackSize + stack.stackSize < inventory.getInventoryStackLimit()
               && existingStack.stackSize + stack.stackSize < existingStack.getMaxStackSize())
             return true;
       }
     }
   } else {
     int invSize = inventory.getSizeInventory();
     for (int i = 0; i < invSize && stack != null; i++)
       if (inventory.isItemValidForSlot(i, stack)) {
         ItemStack existingStack = inventory.getStackInSlot(i);
         if (existingStack == null) return true;
         else if (OreDictionary.itemMatches(existingStack, stack, true)
             && ItemStack.areItemStackTagsEqual(stack, existingStack))
           if (existingStack.stackSize + stack.stackSize < inventory.getInventoryStackLimit()
               && existingStack.stackSize + stack.stackSize < existingStack.getMaxStackSize())
             return true;
       }
   }
   return false;
 }
コード例 #3
0
ファイル: RMFurnaceTile.java プロジェクト: Roblomal/ProjectE
  private void pushSmeltStack() {
    ItemStack stack = getStackInSlot(1);

    for (int i = inputStorage[0]; i <= inputStorage[1]; i++) {
      if (stack != null && stack.stackSize == stack.getMaxStackSize()) {
        return;
      }

      ItemStack slotStack = getStackInSlot(i);

      if (slotStack != null && (stack == null || Utils.areItemStacksEqual(slotStack, stack))) {
        if (stack == null) {
          inventory[1] = slotStack.copy();
          inventory[i] = null;
          return;
        }

        int remain = stack.getMaxStackSize() - stack.stackSize;

        if (slotStack.stackSize <= remain) {
          inventory[i] = null;
          inventory[1].stackSize += stack.stackSize;
          return;
        } else {
          this.decrStackSize(i, remain);
          inventory[1].stackSize += remain;
          return;
        }
      }
    }
  }
コード例 #4
0
ファイル: Util.java プロジェクト: umamama/MinecraftMods
 public static ItemStack insertItem(
     IInventory inventory, ItemStack itemStack, boolean test, boolean force) {
   if (test) {
     itemStack = itemStack.copy();
   }
   int size = inventory.getSizeInventory();
   for (int i = 0; i < size; i++) {
     if (inventory.isItemValidForSlot(i, itemStack) || force) {
       ItemStack storedItem = inventory.getStackInSlot(i);
       if (storedItem != null) {
         if (equalItemAndNBT(storedItem, itemStack)) {
           int maxStackSize =
               Math.min(itemStack.getMaxStackSize(), inventory.getInventoryStackLimit());
           int add = Math.min(itemStack.stackSize, maxStackSize - storedItem.stackSize);
           if (!test) {
             storedItem.stackSize += add;
           }
           itemStack.stackSize -= add;
           inventory.setInventorySlotContents(i, storedItem);
         }
       } else {
         storedItem = itemStack.copy();
         storedItem.stackSize = Math.min(itemStack.stackSize, itemStack.getMaxStackSize());
         if (!test) {
           inventory.setInventorySlotContents(i, storedItem);
         }
         itemStack.stackSize -= storedItem.stackSize;
       }
       if (itemStack.stackSize <= 0) {
         return null;
       }
     }
   }
   return itemStack;
 }
コード例 #5
0
  /**
   * 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;
  }
コード例 #6
0
  @Override
  public void markDirty() {
    super.markDirty();

    int oldStorage = storageAmount;
    if (inputStack != null) {
      if (this.identStack == null) identStack = inputStack;

      if ((maxStorage - storageAmount) > 0) {
        if (prevInputStack == null) // inputStack is new
        storageAmount += inputStack.stackSize;
        else storageAmount += inputStack.stackSize - prevInputStack.stackSize;

        if (storageAmount > maxStorage) storageAmount = maxStorage;
      }
      // Set new fake inputs
      if ((maxStorage - storageAmount) >= identStack.getMaxStackSize()) {
        inputStack = null;
        prevInputStack = null;
      } else {
        inputStack =
            Utils.copyStackWithAmount(
                identStack, identStack.getMaxStackSize() - (maxStorage - storageAmount));
        prevInputStack = inputStack.copy();
      }
    }

    if (prevOutputStack != null) // Had fake output
    {
      if (outputStack == null) // fully depleted
      storageAmount -= prevOutputStack.stackSize;
      else storageAmount -= (prevOutputStack.stackSize - outputStack.stackSize);

      if (storageAmount < 0) storageAmount = 0;
    }

    // Handle emptying of the barrel
    if (storageAmount == 0 && !lockItem) {
      identStack = null;
      outputStack = null;
      prevOutputStack = null;
      inputStack = null;
      prevInputStack = null;
      forceUpdate = true;
    } else if (identStack != null) {
      if (outputStack == null) outputStack = identStack.copy();
      outputStack.stackSize = Math.min(outputStack.getMaxStackSize(), storageAmount);
      prevOutputStack = outputStack.copy();
    }
    if (storageAmount != oldStorage || forceUpdate)
      worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    forceUpdate = false;
  }
コード例 #7
0
  @Override
  public ItemStack mergeIntoBestSlot(ItemStack stack) {
    List<ItemStack> candidates = new ArrayList<ItemStack>();
    int size = 0;
    for (int i = 0; i < 9; ++i) {
      ItemStack tmp = _craftingMatrix.getStackInSlot(i);
      if (tmp != null && tmp.isItemEqual(stack)) {
        candidates.add(tmp);
        size += tmp.stackSize;
      }
    }

    if (candidates.isEmpty()) return stack;

    stack.stackSize =
        balanceStacks(
            candidates, size, stack.getMaxStackSize() * candidates.size(), stack.stackSize);

    // If we didn't get rid of everything then see if we can dump into the first.
    if (stack.stackSize > 0) MALUtils.mergeStacks(candidates.get(0), stack);

    if (stack.stackSize == 0) return null;

    return stack;
  }
コード例 #8
0
ファイル: EntityItem.java プロジェクト: JelkeNelisse/Mod
  /**
   * Tries to merge this item with the item passed as the parameter. Returns true if successful.
   * Either this item or the other item will be removed from the world.
   */
  public boolean combineItems(EntityItem par1EntityItem) {
    if (par1EntityItem == this) {
      return false;
    } else if (par1EntityItem.isEntityAlive() && this.isEntityAlive()) {
      ItemStack var2 = this.func_92014_d();
      ItemStack var3 = par1EntityItem.func_92014_d();

      if (var3.getItem() != var2.getItem()) {
        return false;
      } else if (var3.hasTagCompound() ^ var2.hasTagCompound()) {
        return false;
      } else if (var3.hasTagCompound() && !var3.getTagCompound().equals(var2.getTagCompound())) {
        return false;
      } else if (var3.getItem().getHasSubtypes() && var3.getItemDamage() != var2.getItemDamage()) {
        return false;
      } else if (var3.stackSize < var2.stackSize) {
        return par1EntityItem.combineItems(this);
      } else if (var3.stackSize + var2.stackSize > var3.getMaxStackSize()) {
        return false;
      } else {
        var3.stackSize += var2.stackSize;
        par1EntityItem.delayBeforeCanPickup =
            Math.max(par1EntityItem.delayBeforeCanPickup, this.delayBeforeCanPickup);
        par1EntityItem.age = Math.min(par1EntityItem.age, this.age);
        par1EntityItem.func_92013_a(var3);
        this.setDead();
        return true;
      }
    } else {
      return false;
    }
  }
コード例 #9
0
  private boolean canProcess(int i) {
    if (power < machine.getMinPower(i)
        || omega < machine.getMinSpeed(i)
        || torque < machine.getMinTorque(i)) return false;

    if (i == 0 && !bedrock && drillTime <= 0 && ConfigRegistry.EXTRACTORMAINTAIN.getState())
      return false;

    if ((i == 1 || i == 2) && tank.isEmpty()) return false;

    if (inv[i] == null) return false;
    if (inv[i + 4] != null && inv[i + 4].stackSize + 1 >= inv[i + 4].getMaxStackSize())
      return false;
    if (inv[8] != null) {
      if (inv[8].stackSize + 1 > inv[8].getMaxStackSize()) return false;
      if (inv[3] != null) {
        ItemStack bonus = ExtractorBonus.getBonusItemForIngredient(inv[3]);
        if (bonus != null) {
          if (!ReikaItemHelper.matchStacks(bonus, inv[8])) return false;
        }
      }
    }
    OreType ore = this.getOreType(inv[i]);
    if (ore == null) return false;

    ItemStack itemstack = RecipesExtractor.getRecipes().getExtractionResult(inv[i]);
    if (itemstack == null) {
      return false;
    }
    if (inv[i + 4] == null) return true;
    if (!inv[i + 4].isItemEqual(itemstack)) return false;
    if (inv[i + 4].stackSize < this.getInventoryStackLimit()
        && inv[i + 4].stackSize < inv[i + 4].getMaxStackSize()) return true;
    return inv[i + 4].stackSize < itemstack.getMaxStackSize();
  }
コード例 #10
0
  public ItemStack func_174894_a(ItemStack p_174894_1_) {
    ItemStack itemstack1 = p_174894_1_.copy();

    for (int i = 0; i < this.slotsCount; ++i) {
      ItemStack itemstack2 = this.getStackInSlot(i);

      if (itemstack2 == null) {
        this.setInventorySlotContents(i, itemstack1);
        this.markDirty();
        return null;
      }

      if (ItemStack.areItemsEqual(itemstack2, itemstack1)) {
        int j = Math.min(this.getInventoryStackLimit(), itemstack2.getMaxStackSize());
        int k = Math.min(itemstack1.stackSize, j - itemstack2.stackSize);

        if (k > 0) {
          itemstack2.stackSize += k;
          itemstack1.stackSize -= k;

          if (itemstack1.stackSize <= 0) {
            this.markDirty();
            return null;
          }
        }
      }
    }

    if (itemstack1.stackSize != p_174894_1_.stackSize) {
      this.markDirty();
    }

    return itemstack1;
  }
コード例 #11
0
 void finishThrowing() {
   // try merge
   if (!worldObj.isRemote && !player.capabilities.isCreativeMode) {
     ItemStack equipped = player.getCurrentEquippedItem();
     if (equipped == null) {
       player.setCurrentItemOrArmor(0, new ItemStack(ModuleVanilla.coin));
     } else if (equipped.getItem() == ModuleVanilla.coin
         && equipped.stackSize < equipped.getMaxStackSize()) {
       ++equipped.stackSize;
       player.inventory.inventoryChanged = true;
     } else if (PlayerUtils.mergeStackable(player.inventory, new ItemStack(ModuleVanilla.coin))
         > 0) {;
     } else {
       // if fail...
       worldObj.spawnEntityInWorld(
           new EntityItem(
               worldObj,
               player.posX,
               player.posY + yOffset,
               player.posZ,
               new ItemStack(ModuleVanilla.coin)));
     }
   }
   setDead();
 }
コード例 #12
0
  public ItemStack func_174894_a(ItemStack p_174894_1_) {
    ItemStack var2 = p_174894_1_.copy();

    for (int var3 = 0; var3 < this.slotsCount; ++var3) {
      ItemStack var4 = this.getStackInSlot(var3);
      if (var4 == null) {
        this.setInventorySlotContents(var3, var2);
        this.markDirty();
        return null;
      }

      if (ItemStack.areItemsEqual(var4, var2)) {
        int var5 = Math.min(this.getInventoryStackLimit(), var4.getMaxStackSize());
        int var6 = Math.min(var2.stackSize, var5 - var4.stackSize);
        if (var6 > 0) {
          var4.stackSize += var6;
          var2.stackSize -= var6;
          if (var2.stackSize <= 0) {
            this.markDirty();
            return null;
          }
        }
      }
    }

    if (var2.stackSize != p_174894_1_.stackSize) {
      this.markDirty();
    }

    return var2;
  }
コード例 #13
0
 @SideOnly(Side.CLIENT)
 public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean b) {
   // TODO translate
   IModule module = getModule(stack);
   if (module instanceof IRocketEngine) {
     list.add("Speed: " + ((IRocketEngine) module).getSpeed(null));
     list.add("Range: " + ((IRocketEngine) module).getMaxDistance(null));
     if (module instanceof RocketEngineFluid) {
       list.add(
           "Fuel: "
               + ((RocketEngineFluid) module).getFluidAmount()
               + "/"
               + ((RocketEngineFluid) module).getCapacity()
               + "mL");
     } else if (module instanceof RocketEngineSolid) {
       ItemStack fuel = ((RocketEngineSolid) module).getInventory().getStackInSlot(0);
       if (fuel != null) {
         int max =
             Math.max(
                 fuel.getMaxStackSize(),
                 ((RocketEngineSolid) module).getInventory().getInventoryStackLimit());
         list.add("Fuel: " + fuel.getDisplayName() + " " + fuel.stackSize + "/" + max);
       } else {
         list.add("Fuel: empty");
       }
     }
   }
 }
コード例 #14
0
  /**
   * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't
   * full, etc.
   */
  private boolean canSmelt() {
    if (furnaceItemStacks[0] == null) {
      return false;
    }

    ItemStack itemstack =
        FurnaceRecipes.smelting().getSmeltingResult(furnaceItemStacks[0].getItem().itemID);

    if (itemstack == null) {
      return false;
    }

    if (furnaceItemStacks[2] == null) {
      return true;
    }

    if (!furnaceItemStacks[2].isItemEqual(itemstack)) {
      return false;
    }

    if (furnaceItemStacks[2].stackSize < getInventoryStackLimit()
        && furnaceItemStacks[2].stackSize < furnaceItemStacks[2].getMaxStackSize()) {
      return true;
    } else {
      return furnaceItemStacks[2].stackSize < itemstack.getMaxStackSize();
    }
  }
コード例 #15
0
ファイル: TEC.java プロジェクト: AhmiDarrow/ThaumicExpansion
 public static boolean canInsertBIntoA(ItemStack a, ItemStack b) {
   return a == null
       || (b != null
           && a.getItem() == b.getItem()
           && a.getItemDamage() == b.getItemDamage()
           && ItemStack.areItemStackTagsEqual(a, b)
           && a.stackSize + b.stackSize <= a.getMaxStackSize());
 }
コード例 #16
0
ファイル: ItemHelper.java プロジェクト: Bunsan/MerchantsTFC
  public static final int getItemStackMaxQuantity_SmallVessel(ItemStack itemStack) {
    Item item = itemStack.getItem();

    if (item instanceof IFood)
      return (int) ((IFood) itemStack.getItem()).getFoodMaxWeight(itemStack) / 2;

    return itemStack.getMaxStackSize();
  }
コード例 #17
0
 @Override
 public void updateEntity() {
   if (!worldObj.isRemote) {
     if (tank.getFluidAmount() > 2400) {
       if (progress > 0) {
         tank.drainInternal(15, true);
         progress--;
       } else if (progress == 0) {
         ItemStack s = MachineCraftingHandler.getFurnaceRecipe(stack[0]);
         if (s != null) {
           if (stack[1] != null) {
             if (TomsModUtils.areItemStacksEqual(stack[1], s, true, true, false)
                 && stack[1].stackSize + s.stackSize <= s.getMaxStackSize()
                 && stack[0].stackSize >= 1) {
               stack[1].stackSize += s.stackSize;
               progress = -1;
               decrStackSize(0, 1);
             }
           } else {
             progress = -1;
             stack[1] = s;
             decrStackSize(0, 1);
           }
         } else {
           progress = -1;
         }
       } else {
         ItemStack s = MachineCraftingHandler.getFurnaceRecipe(stack[0]);
         if (s != null) {
           if (stack[1] != null) {
             if (TomsModUtils.areItemStacksEqual(stack[1], s, true, true, false)
                 && stack[1].stackSize + s.stackSize <= s.getMaxStackSize()
                 && stack[0].stackSize >= 1) {
               progress = MAX_PROCESS_TIME;
             }
           } else {
             progress = MAX_PROCESS_TIME;
           }
         }
         TomsModUtils.setBlockStateWithCondition(worldObj, pos, SteamFurnace.ACTIVE, progress > 0);
       }
     } else {
       TomsModUtils.setBlockStateWithCondition(worldObj, pos, SteamFurnace.ACTIVE, false);
     }
   }
 }
コード例 #18
0
 private static boolean areItemStacksEqualItem(ItemStack par0ItemStack, ItemStack par1ItemStack) {
   return par0ItemStack.itemID != par1ItemStack.itemID
       ? false
       : (par0ItemStack.getItemDamage() != par1ItemStack.getItemDamage()
           ? false
           : (par0ItemStack.stackSize > par0ItemStack.getMaxStackSize()
               ? false
               : ItemStack.areItemStackTagsEqual(par0ItemStack, par1ItemStack)));
 }
コード例 #19
0
 /**
  * Adds an alloy, and duplicates it so the ratio can be copied eg a recipe with 2 'x' ore and 1
  * 'y' ore can be made with 4 'x' ore and 2 'y' ore...
  *
  * @param the amount of times the ratio can be added
  */
 public static void addRatioRecipe(ItemStack out, int level, List in, int levels) {
   for (int a = 1; a <= levels; a++) {
     List list2 = createDupeList(in, a);
     ItemStack out2 = out.copy();
     int ss = Math.min(out2.getMaxStackSize(), out2.stackSize * a);
     out2.stackSize = ss;
     addAlloy(out2, level, list2);
   }
 }
コード例 #20
0
  private String itemCountToStacks(ItemStack istack, int count) {
    int leftover = count % istack.getMaxStackSize();
    int stacks = (count - leftover) / istack.getMaxStackSize();

    if (stacks == 0) {
      return "" + leftover;
    } else {
      if (istack.getMaxStackSize() != 1) {
        String s = stacks + "x" + istack.getMaxStackSize();

        if (leftover > 0) {
          s = s + "+" + leftover;
        }
        return s;
      } else {
        return stacks + "";
      }
    }
  }
コード例 #21
0
ファイル: ItemHelper.java プロジェクト: Bunsan/MerchantsTFC
  public static final int getItemStackMaxQuantity(ItemStack itemStack, IInventory inventory) {
    Item item = itemStack.getItem();

    if (item instanceof IFood)
      return (int) ((IFood) itemStack.getItem()).getFoodMaxWeight(itemStack);

    if (inventory instanceof TEIngotPile) return inventory.getInventoryStackLimit();

    return Math.min(itemStack.getMaxStackSize(), inventory.getInventoryStackLimit());
  }
	@Override
	public boolean canInsertItem(int slot, ItemStack itemstack, int side)
	{
		ForgeDirection dir = ForgeDirection.getOrientation(side);
		int start = getStartInventorySide(dir);
		return slot >= start && slot < (start + getSizeInventorySide(dir)) &&
				itemstack == null ||
				(this.isItemValidForSlot(slot, itemstack) &&
				itemstack.stackSize <= Math.min(itemstack.getMaxStackSize(), getInventoryStackLimit()));
	}
コード例 #23
0
  public static ArrayList<ItemStack> dumpToIInventory(
      ArrayList<ItemStack> stacks, IInventory inventory) {

    boolean debug = false;
    ArrayList<ItemStack> remaining = new ArrayList<ItemStack>(); // returns the remainder

    ItemStack chestStack;

    for (ItemStack current : stacks) {
      if (current == null) {
        continue;
      }

      for (int i = 0; i < inventory.getSizeInventory(); i++) {

        if (current == null) {
          continue;
        }

        chestStack = inventory.getStackInSlot(i);

        if (chestStack == null) {
          if (debug) System.out.println("DUMP " + i);

          inventory.setInventorySlotContents(i, current);
          // and dont add current ot remainder at all ! sweet!
          current = null;
        } else if (chestStack.isItemEqual(current)) {

          int space = chestStack.getMaxStackSize() - chestStack.stackSize;

          int toDeposit = Math.min(space, current.stackSize);

          if (toDeposit > 0) {

            if (debug) System.out.println("merge " + i + " ; toDeposit =  " + toDeposit);
            current.stackSize -= toDeposit;
            chestStack.stackSize += toDeposit;

            if (current.stackSize == 0) {
              current = null;
            }
          }
        }
      } // finished current pass over inventory
      if (current != null) {
        if (debug) System.out.println("remaining.add : stackSize = " + current.stackSize);
        remaining.add(current);
      }
    }

    if (debug) System.out.println("remaining" + remaining.size());
    return remaining;
  }
コード例 #24
0
 public void fillExport() {
   if (_exportable.empty()) return;
   if (_export == null) {
     _export = _exportable.take();
   } else {
     int request = Math.min(SLOT_STACK_LIMIT, _export.getMaxStackSize()) - _export.stackSize;
     ItemStack taken = _exportable.take(_export, request);
     if (taken != null) _export.stackSize += taken.stackSize;
     else _export = _exportable.take();
   }
 }
コード例 #25
0
ファイル: FurnaceEntity.java プロジェクト: Kilok/UltraTech
 private boolean canSmelt() {
   if (this.inventory[0] == null) {
     return false;
   } else {
     ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.inventory[0]);
     if (itemstack == null) return false;
     if (this.inventory[1] == null) return true;
     if (!this.inventory[1].isItemEqual(itemstack)) return false;
     int result = inventory[1].stackSize + itemstack.stackSize;
     return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
   }
 }
コード例 #26
0
 public ItemStack take(ItemStack template, int amount) {
   Key k = Key.of(template);
   Integer count = _elements.get(k);
   if (count == null) return null;
   ItemStack stack = k.stack().copy();
   stack.stackSize =
       Math.min(stack.getMaxStackSize(), Math.min(SLOT_STACK_LIMIT, Math.min(amount, count)));
   _size -= stack.stackSize;
   if (stack.stackSize >= count) _elements.remove(k);
   else _elements.put(k, count - stack.stackSize);
   return stack;
 }
コード例 #27
0
  private static ItemStack func_102014_c(
      IInventory par0IInventory, ItemStack par1ItemStack, int par2, int par3) {
    ItemStack itemstack1 = par0IInventory.getStackInSlot(par2);

    if (canInsertItemToInventory(par0IInventory, par1ItemStack, par2, par3)) {
      boolean flag = false;

      if (itemstack1 == null) {
        int max =
            Math.min(par1ItemStack.getMaxStackSize(), par0IInventory.getInventoryStackLimit());
        if (max >= par1ItemStack.stackSize) {
          par0IInventory.setInventorySlotContents(par2, par1ItemStack);
          par1ItemStack = null;
        } else {
          par0IInventory.setInventorySlotContents(par2, par1ItemStack.splitStack(max));
        }
        flag = true;
      } else if (areItemStacksEqualItem(itemstack1, par1ItemStack)) {
        int max =
            Math.min(par1ItemStack.getMaxStackSize(), par0IInventory.getInventoryStackLimit());
        if (max > itemstack1.stackSize) {
          int l = Math.min(par1ItemStack.stackSize, max - itemstack1.stackSize);
          par1ItemStack.stackSize -= l;
          itemstack1.stackSize += l;
          flag = l > 0;
        }
      }

      if (flag) {
        if (par0IInventory instanceof TileEntityHopper) {
          ((TileEntityHopper) par0IInventory).setTransferCooldown(8);
          par0IInventory.onInventoryChanged();
        }

        par0IInventory.onInventoryChanged();
      }
    }

    return par1ItemStack;
  }
コード例 #28
0
 private boolean canSmelt() {
   if (this.furnaceItemStacks[INPUT] == null || this.waterLevel == 0) {
     return false;
   } else {
     ItemStack itemstack =
         FurnaceRecipes.smelting().getSmeltingResult(this.furnaceItemStacks[INPUT]);
     if (itemstack == null) return false;
     if (this.furnaceItemStacks[OUTPUT] == null) return true;
     if (!this.furnaceItemStacks[OUTPUT].isItemEqual(itemstack)) return false;
     int result = furnaceItemStacks[OUTPUT].stackSize + itemstack.stackSize;
     return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
   }
 }
コード例 #29
0
 public static ItemStack addToOccupiedSlot(
     IInventory inventory, int slot, ItemStack stack, ItemStack existingStack) {
   int stackLimit = Math.min(inventory.getInventoryStackLimit(), stack.getMaxStackSize());
   if (stack.stackSize + existingStack.stackSize > stackLimit) {
     int stackDiff = stackLimit - existingStack.stackSize;
     existingStack.stackSize = stackLimit;
     stack.stackSize -= stackDiff;
     inventory.setInventorySlotContents(slot, existingStack);
     return stack;
   }
   existingStack.stackSize += Math.min(stack.stackSize, stackLimit);
   inventory.setInventorySlotContents(slot, existingStack);
   return stackLimit >= stack.stackSize ? null : stack.splitStack(stack.stackSize - stackLimit);
 }
コード例 #30
0
ファイル: LiquidTank.java プロジェクト: Xephi/Traincraft-164
  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;
  }