Repository: sirendii/advancedperipherals
Issue: NullPointerException crash if trying to craft an item with 0 stock with ME bridge

### Descripe

Own compiled build from current master as of writing, as AE Bridge is broken in latest release.

Game/server crashes if trying to craft an item is not in stock in the ME system.

I think the bug is here:
https://github.com/Seniorendi/AdvancedPeripherals/blob/8debb40a941977609bd80f9e9baf0b1f12a2f7d8/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java#L83

aeItem can be null, and .getRight is called just after. :)

### Steps to reproduce

Have a recipe in ME system, but no items in stock/in system. 

```lua
me = peripheral.wrap("left")
me.craftItem({name="minecraft:oak_planks", count=10})
```

### Multiplayer?

No

### Version

Own compiled build.

### Minecraft, Forge and maybe other related mods versions

Forge 40.1.0, Minecraft 1.18.2, AE2 11.0.0-alpha.6

### Screenshots or Videos

_No response_

### Crashlog/log

https://pastebin.com/298NPaBF

Changed files:
src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java
src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java

diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java
index 5c81a1a9..76db35db 100644
--- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java
+++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java
@@ -29,17 +29,32 @@ import java.util.Map;
 
 public class AppEngApi {
 
-    public static Pair<Long, AEItemKey> findAEStackFromItemStack(MEStorage monitor, ItemStack item) {
-        Pair<Long, AEItemKey> stack = null;
+    public static Pair<Long, AEItemKey> findAEStackFromItemStack(MEStorage monitor, ICraftingService crafting, ItemStack item) {
         for (Object2LongMap.Entry<AEKey> temp : monitor.getAvailableStacks()) {
             if (temp.getKey() instanceof AEItemKey key) {
                 if (key.matches(item)) {
-                    stack = Pair.of(temp.getLongValue(), key);
-                    break;
+                    return Pair.of(temp.getLongValue(), key);
                 }
             }
         }
-        return stack;
+
+        if (crafting == null) {
+            return null;
+        }
+
+        for (var temp : crafting.getCraftables(param -> true)) {
+            if(temp instanceof AEItemKey key) {
+                if (key.matches(item)) {
+                    return Pair.of(0L, key);
+                }
+            }
+        }
+
+        return null;
+    }
+
+    public static Pair<Long, AEItemKey> findAEStackFromItemStack(MEStorage monitor, ItemStack item) {
+        return findAEStackFromItemStack(monitor, null, item);
     }
 
     public static List<Object> listStacks(MEStorage monitor, ICraftingService service, int flag) {
diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java
index 74a36404..50f2bc18 100644
--- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java
+++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/CraftJob.java
@@ -79,7 +79,13 @@ public class CraftJob implements ILuaCallback {
         ICraftingService crafting = grid.getService(ICraftingService.class);
         MEStorage monitor = storage.getInventory();
         ItemStack itemstack = item;
-        Pair<Long, AEItemKey> aeItem = AppEngApi.findAEStackFromItemStack(monitor, itemstack);
+        Pair<Long, AEItemKey> aeItem = AppEngApi.findAEStackFromItemStack(monitor, crafting, itemstack);
+
+        if (aeItem == null) {
+            AdvancedPeripherals.debug("Could not get AEItem from monitor", org.apache.logging.log4j.Level.FATAL);
+            return;
+        }
+
         if (!crafting.isCraftable(aeItem.getRight())) {
             fireEvent(false, item.getDescriptionId() + " is not craftable");
             return;