示例#1
0
  private SideData getFromSlot(Slot slot) {
    if (slot.slotNumber < tileEntity.getSizeInventory()) {
      IInvConfiguration config = (IInvConfiguration) tileEntity;

      for (SideData data : config.getSideData()) {
        for (int id : data.availableSlots) {
          if (id == slot.getSlotIndex()) {
            return data;
          }
        }
      }
    }

    return null;
  }
示例#2
0
  public static boolean canInsert(
      TileEntity tileEntity, EnumColor color, ItemStack itemStack, int side, boolean force) {
    if (!(tileEntity instanceof IInventory)) {
      return false;
    }

    if (force && tileEntity instanceof TileEntityLogisticalSorter) {
      return ((TileEntityLogisticalSorter) tileEntity).canSendHome(itemStack);
    }

    if (!force && tileEntity instanceof IInvConfiguration) {
      IInvConfiguration config = (IInvConfiguration) tileEntity;
      int tileSide = config.getOrientation();
      EnumColor configColor =
          config
              .getEjector()
              .getInputColor(
                  ForgeDirection.getOrientation(MekanismUtils.getBaseOrientation(side, tileSide))
                      .getOpposite());

      if (config.getEjector().hasStrictInput() && configColor != null && configColor != color) {
        return false;
      }
    }

    IInventory inventory = (IInventory) tileEntity;

    if (!(inventory instanceof ISidedInventory)) {
      inventory = InventoryUtils.checkChestInv(inventory);

      for (int i = 0; i <= inventory.getSizeInventory() - 1; i++) {
        if (!force) {
          if (!inventory.isItemValidForSlot(i, itemStack)) {
            continue;
          }
        }

        ItemStack inSlot = inventory.getStackInSlot(i);

        if (inSlot == null) {
          return true;
        } else if (inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) {
          if (inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) {
            return true;
          } else {
            int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize();

            if (rejects < itemStack.stackSize) {
              return true;
            }
          }
        }
      }
    } else {
      ISidedInventory sidedInventory = (ISidedInventory) inventory;
      int[] slots =
          sidedInventory.getAccessibleSlotsFromSide(
              ForgeDirection.getOrientation(side).getOpposite().ordinal());

      if (slots != null && slots.length != 0) {
        if (force
            && sidedInventory instanceof TileEntityBin
            && ForgeDirection.getOrientation(side).getOpposite().ordinal() == 0) {
          slots = sidedInventory.getAccessibleSlotsFromSide(1);
        }

        for (int get = 0; get <= slots.length - 1; get++) {
          int slotID = slots[get];

          if (!force) {
            if (!sidedInventory.isItemValidForSlot(slotID, itemStack)
                || !sidedInventory.canInsertItem(
                    slotID,
                    itemStack,
                    ForgeDirection.getOrientation(side).getOpposite().ordinal())) {
              continue;
            }
          }

          ItemStack inSlot = inventory.getStackInSlot(slotID);

          if (inSlot == null) {
            return true;
          } else if (inSlot.isItemEqual(itemStack) && inSlot.stackSize < inSlot.getMaxStackSize()) {
            if (inSlot.stackSize + itemStack.stackSize <= inSlot.getMaxStackSize()) {
              return true;
            } else {
              int rejects = (inSlot.stackSize + itemStack.stackSize) - inSlot.getMaxStackSize();

              if (rejects < itemStack.stackSize) {
                return true;
              }
            }
          }
        }
      }
    }

    return false;
  }