Applied Energistics 2

Applied Energistics 2

156M Downloads

Api crafting question

SirEndii opened this issue ยท 4 comments

commented

Describe the bug
Hey, i wanted to craft items with the AE API, but i does not work. There is probably a NullPointerException (see screenshot), but I don't understand from what.
I tried the following methods to craft things with AE.
1.

String itemName = (String) item[0];
        long amount = (long) (double) item[1];
        ItemStack itemToCraft = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)));
        if (itemToCraft.isEmpty())
            throw new NullPointerException("Item " + itemName + " does not exists");
        IAEItemStack aeItemToCraft = findAEStackFromItemStack(monitor, itemToCraft);
        if (aeItemToCraft == null)
            throw new NullPointerException("Item " + itemName + " does not exists in the ME system");
        if (!aeItemToCraft.isCraftable())
            throw new NullPointerException("Item " + itemName + " isn't craftable");
        aeItemToCraft = aeItemToCraft.copy();
        aeItemToCraft.setStackSize(amount);
        synchronized(this) {
            try {
                final ICraftingGrid craftingGrid = node.getGrid().getCache(ICraftingGrid.class);
                final Future<ICraftingJob> job = craftingGrid.beginCraftingJob(world, node.getGrid(), this, aeItemToCraft, null);
                final ICraftingLink result = craftingGrid.submitJob(job.get(), (ICraftingRequester) this, null, true, MeBridgeTileEntity.this);

            } catch(InterruptedException | ExecutionException ex) {

            }
        }
  1. and now with lambda
        String itemName = (String) item[0];
        long amount = (long) (double) item[1];
        ItemStack itemToCraft = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)));
        if (itemToCraft.isEmpty())
            throw new NullPointerException("Item " + itemName + " does not exists");
        IAEItemStack aeItemToCraft = findAEStackFromItemStack(monitor, itemToCraft);
        if (aeItemToCraft == null)
            throw new NullPointerException("Item " + itemName + " does not exists in the ME system");
        if (!aeItemToCraft.isCraftable())
            throw new NullPointerException("Item " + itemName + " isn't craftable");
        aeItemToCraft = aeItemToCraft.copy();
        aeItemToCraft.setStackSize(amount);
        synchronized(this) {
            
              ICraftingGrid craftingGrid = node.getGrid().getCache(ICraftingGrid.class);
			craftingGrid.beginCraftingJob(world, node.getGrid(), this, aeToCraft, job -> {
				ICraftingLink result = craftingGrid.submitJob(job, (ICraftingRequester) this, null, false,
						TileEntityMEBridge.this);
             });
        }

Additional context
image
Here is an screenshot, i want to call this with CC.

Environment
AE-Version: 8.2.0-beta.2
Forge-Version: 8.2.0-beta.2

commented

This is impossible to debug without a proper stacktrace.

commented

You're right. I debugged everything (aeItemToCraft, amount, itemName...) and nothing is null. I will try to start the crafting with another method(not CC) to see a stacktrace.

And thank you, that you want to help me!

commented

So, i tested the crafting within tick()

        if(tick == 300) {
            IMEMonitor<IAEItemStack> grid = ((IStorageGrid) node.getGrid().getCache(IStorageGrid.class)).getInventory(AppEngApi.getInstance().getApi().storage().getStorageChannel(IItemStorageChannel.class));
            Object[] items = new Object[]{"minecraft:stick", 10000.0D};
            craft(items, grid);
        }
Caused by: java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:203) ~[?:1.8.0_261] {}
	at java.util.Optional.<init>(Optional.java:96) ~[?:1.8.0_261] {}
	at java.util.Optional.of(Optional.java:108) ~[?:1.8.0_261] {}
	at de.srendi.advancedperipherals.common.blocks.tileentity.MeBridgeTileEntity.player(MeBridgeTileEntity.java:177) ~[?:?] {re:classloading}
	at appeng.me.storage.NetworkInventoryHandler.testPermission(NetworkInventoryHandler.java:125) ~[appliedenergistics2:8.2.0-beta.2] {re:classloading}
	at appeng.me.storage.NetworkInventoryHandler.extractItems(NetworkInventoryHandler.java:176) ~[appliedenergistics2:8.2.0-beta.2] {re:classloading}
	at appeng.me.cache.NetworkMonitor.extractItems(NetworkMonitor.java:85) ~[appliedenergistics2:8.2.0-beta.2] {re:classloading}
	at appeng.crafting.MECraftingInventory.<init>(MECraftingInventory.java:119) ~[appliedenergistics2:8.2.0-beta.2] {re:classloading}
	at appeng.crafting.CraftingJob.<init>(CraftingJob.java:88) ~[appliedenergistics2:8.2.0-beta.2] {re:classloading}
	at appeng.me.cache.CraftingGridCache.beginCraftingJob(CraftingGridCache.java:442) ~[appliedenergistics2:8.2.0-beta.2] {re:classloading}
	at de.srendi.advancedperipherals.common.blocks.tileentity.MeBridgeTileEntity.craft(MeBridgeTileEntity.java:280) ~[?:?] {re:classloading}
	at de.srendi.advancedperipherals.common.blocks.tileentity.MeBridgeTileEntity.tick(MeBridgeTileEntity.java:170) ~[?:?] {re:classloading}
	at net.minecraft.world.World.tickBlockEntities(World.java:538) ~[forge:?] {re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:374) ~[forge:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:884) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	... 5 more

And this is the stacktrace

commented

The PlayerEntity(placed) was null, i fixed this. But now i have this issue:

java.lang.NullPointerException: Ticking block entity
	at de.srendi.advancedperipherals.common.blocks.tileentity.MeBridgeTileEntity.tick(MeBridgeTileEntity.java:170) ~[main/:?] {re:classloading}
	at net.minecraft.world.World.tickBlockEntities(World.java:538) ~[forge-1.16.4-35.1.36_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B}
	at net.minecraft.client.world.ClientWorld.tickEntities(ClientWorld.java:181) ~[forge-1.16.4-35.1.36_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A,re:mixin,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1530) ~[forge-1.16.4-35.1.36_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:979) ~[forge-1.16.4-35.1.36_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:612) ~[forge-1.16.4-35.1.36_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.4-35.1.36_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_261] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_261] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_261] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_261] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.4-35.1.36_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.6.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.6.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.4-35.1.36_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}

MeBridgeTileEntity.java:170 is

IMEMonitor<IAEItemStack> grid = ((IStorageGrid)
node.getGrid().getCache(IStorageGrid.class)).getInventory(AppEngApi.getInstance().
getApi().storage().getStorageChannel(IItemStorageChannel.class));