Esempio n. 1
1
  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;
          }
        }
      }
    }
  }
Esempio n. 2
0
  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;
        }
      }
    }
  }
Esempio n. 3
0
  private void smeltItem() {
    ItemStack toSmelt = inventory[1];
    ItemStack smeltResult = FurnaceRecipes.smelting().getSmeltingResult(toSmelt).copy();
    ItemStack currentSmelted = getStackInSlot(outputSlot);

    if (Utils.getOreDictionaryName(toSmelt).startsWith("ore")) {
      smeltResult.stackSize *= 2;
    }

    if (currentSmelted == null) {
      setInventorySlotContents(outputSlot, smeltResult);
    } else {
      currentSmelted.stackSize += smeltResult.stackSize;
    }

    decrStackSize(1, 1);
  }
Esempio n. 4
0
  private void pushToInventories() {
    int iSide = 0;

    for (int i = 0; i < 5; i++) {
      int x = this.xCoord;
      int y = this.yCoord;
      int z = this.zCoord;

      switch (i) {
        case 0:
          x++;
          iSide = 5;
          break;
        case 2:
          z++;
          iSide = 3;
          break;
        case 3:
          x--;
          iSide = 4;
          break;
        case 4:
          y--;
          iSide = 0;
          break;
        case 1:
          z--;
          iSide = 2;
          break;
      }

      TileEntity tile = this.worldObj.getTileEntity(x, y, z);

      if (tile == null) {
        continue;
      }

      if (tile != null && tile instanceof ISidedInventory) {
        ISidedInventory inv = (ISidedInventory) tile;

        if (inv != null) {
          int[] slots = inv.getAccessibleSlotsFromSide(Facing.oppositeSide[iSide]);

          if (slots.length > 0) {
            for (int j = outputStorage[0]; j < outputStorage[1]; j++) {
              ItemStack stack = inventory[j];

              if (stack == null) {
                continue;
              }

              for (int k : slots) {
                if (inv.canInsertItem(k, stack, Facing.oppositeSide[iSide])) {
                  ItemStack otherStack = inv.getStackInSlot(k);

                  if (otherStack == null) {
                    inv.setInventorySlotContents(k, stack);
                    inventory[j] = null;
                  } else if (Utils.areItemStacksEqual(stack, otherStack)) {
                    int remain = otherStack.getMaxStackSize() - otherStack.stackSize;

                    if (stack.stackSize <= remain) {
                      otherStack.stackSize += stack.stackSize;
                      inventory[j] = null;
                    } else {
                      otherStack.stackSize += remain;
                      inventory[j].stackSize -= remain;
                    }
                  }
                }
              }
            }
          }
        }
      } else if (tile instanceof IInventory) {
        for (int j = outputStorage[0]; j <= outputStorage[1]; j++) {
          ItemStack stack = inventory[j];

          if (stack != null) {
            ItemStack result = Utils.pushStackInInv((IInventory) tile, stack);

            if (result == null) {
              inventory[j] = null;
            } else {
              inventory[j].stackSize = result.stackSize;
            }
          }
        }
      }
    }
  }
Esempio n. 5
0
  private void pullFromInventories() {
    TileEntity tile = this.worldObj.getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);

    if (tile instanceof ISidedInventory) {
      final int side = 0;
      ISidedInventory inv = (ISidedInventory) tile;

      int[] slots = inv.getAccessibleSlotsFromSide(side);

      if (slots.length > 0) {
        for (int i : slots) {
          ItemStack stack = inv.getStackInSlot(i);

          if (stack == null) {
            continue;
          }

          if (inv.canExtractItem(i, stack, side)) {
            if (TileEntityFurnace.isItemFuel(stack) || stack.getItem() == ObjHandler.kleinStars) {
              if (inventory[0] == null) {
                inventory[0] = stack;
                inv.setInventorySlotContents(i, null);
              } else if (Utils.areItemStacksEqual(stack, inventory[0])) {
                int remain = inventory[0].getMaxStackSize() - inventory[0].stackSize;

                if (stack.stackSize <= remain) {
                  inventory[0].stackSize += stack.stackSize;
                  inv.setInventorySlotContents(i, null);
                } else {
                  inventory[0].stackSize += remain;
                  stack.stackSize -= remain;
                }
              }

              continue;
            }

            for (int j = inputStorage[0]; j < inputStorage[1]; j++) {
              ItemStack otherStack = inventory[j];

              if (otherStack == null) {
                inventory[j] = stack;
                inv.setInventorySlotContents(i, null);
                break;
              } else if (Utils.areItemStacksEqual(stack, otherStack)) {
                int remain = otherStack.getMaxStackSize() - otherStack.stackSize;

                if (stack.stackSize <= remain) {
                  inventory[j].stackSize += stack.stackSize;
                  inv.setInventorySlotContents(i, null);
                  break;
                } else {
                  inventory[j].stackSize += remain;
                  stack.stackSize -= remain;
                }
              }
            }
          }
        }
      }
    } else if (tile instanceof IInventory) {
      IInventory inv = (IInventory) tile;

      for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.getStackInSlot(i);

        if (stack == null) {
          continue;
        }

        if (TileEntityFurnace.isItemFuel(stack) || stack.getItem() == ObjHandler.kleinStars) {
          ItemStack fuel = inventory[0];

          if (fuel == null) {
            inventory[0] = stack;
            inv.setInventorySlotContents(i, null);
          } else {
            int remain = fuel.getMaxStackSize() - fuel.stackSize;

            if (stack.stackSize <= remain) {
              inventory[0].stackSize += stack.stackSize;
              inv.setInventorySlotContents(i, null);
            } else {
              inventory[0].stackSize += remain;
              stack.stackSize -= remain;
            }
          }

          continue;
        } else if (FurnaceRecipes.smelting().getSmeltingResult(stack) == null) {
          continue;
        }

        for (int j = inputStorage[0]; j < inputStorage[1]; j++) {
          ItemStack otherStack = inventory[j];

          if (otherStack == null) {
            inventory[j] = stack;
            inv.setInventorySlotContents(i, null);
            break;
          } else if (Utils.areItemStacksEqual(stack, otherStack)) {
            int remain = otherStack.getMaxStackSize() - otherStack.stackSize;

            if (stack.stackSize <= remain) {
              inventory[j].stackSize += stack.stackSize;
              inv.setInventorySlotContents(i, null);
              break;
            } else {
              inventory[j].stackSize += remain;
              stack.stackSize -= remain;
            }
          }
        }
      }
    }
  }