コード例 #1
0
 /**
  * Called to check if the machine can process a certain item.
  *
  * @return If the item can be processed.
  */
 private boolean canProcess() {
   // Check if the item stack in input is null. If yes, it cannot be processed.
   if (this.machineItemStacks[0] == null) return false;
   // Otherwise...
   else {
     // Save the result of processing to ItemStack.
     ItemStack itemStack =
         HexProcessingCrystalSeparator.processing().getProcessingResult(machineItemStacks[0]);
     // If the result is null, it cannot be processed.
     if (itemStack == null) return false;
     // If there are no items in output slot, it can be processed.
     if (machineItemStacks[1] == null) return true;
     // If there are items in output slot, but are not same as result, it cannot be processed.
     if (!machineItemStacks[1].isItemEqual(itemStack)) return false;
     // Check if more items can fit in the output. If yes, it can be processed.
     int result = machineItemStacks[1].stackSize + itemStack.stackSize;
     return result <= getInventoryStackLimit() && result <= machineItemStacks[1].getMaxStackSize();
   }
 }
コード例 #2
0
  /** Called to execute the item processing. */
  public void processItem() {
    // If the item can be processed...
    if (canProcess()) {
      // Prepare a new ItemStack that is the result of processing.
      ItemStack itemStack =
          HexProcessingCrystalSeparator.processing().getProcessingResult(machineItemStacks[0]);

      // If there are no items in the output, put the result in.
      if (machineItemStacks[1] == null) machineItemStacks[1] = itemStack.copy();
      // If there are items, but are of same type, increment the stack.
      else if (machineItemStacks[1].getItem() == itemStack.getItem())
        machineItemStacks[1].stackSize += itemStack.stackSize;

      // Reduce the number of items in the input.
      machineItemStacks[0].stackSize--;

      // If the amount of items in input is 0, remove the items.
      if (machineItemStacks[0].stackSize == 0) machineItemStacks[0] = null;
    }
  }