Advanced Peripherals

Advanced Peripherals

29M Downloads

ME Bridge getItem() throw java exception when item is referenced but not present

estafeit opened this issue ยท 12 comments

commented

Describe

Sorry, I found another one...

Using getItem() with only item name as parameter works well but under one condition : when i take the last stack of an item from the ME (so there's no more of it) and then try to getItem() by name, I get a java exception thrown at me that stops execution. Expected is an empty return i think ?

  • Doing the same with the same item, keeping one in ME works.
  • Doing the same with other items (still presents in ME) works.
  • Doing the same with another item, removing it from ME, does the same.
  • Doing the same with a random string (ie. an unknown item) works.

It seems only referenced, but absent items are affected.

I get the name from another inventory so i'm sure it's valid.

currentseed = reprocessor.getItemDetail(1)
if (currentseed) then
	print(currentseed.name)
	availibleseed = bridge.getItem({name=currentseed.name})

2023-04-16_02 03 59

Steps to reproduce

  1. Put any number of items in ME
  2. Remove them
  3. Try to call getItem() on an ME bridge with given item name as filter

Multiplayer?

No

Version

1.19.2-0.7.25r (Latest 1.19.2)

Minecraft, Forge and maybe other related mods versions

Forge 43.2.6, Minecraft 1.19.2, modpack All The Mods 8

Screenshots or Videos

No response

Crashlog/log

No response

commented

You're using the filter wrong
name needs to be an string, so you need to wrap it in parentheses

EDIT: I assume this is a var?

another edit...
Nvm, didn't read the whole thing. I'm sorry for that

commented

Do you have a log for me?

commented

AdvancedPeripherals-0.7.27r.zip

Could you test this version?
Unzip the file before using it

commented

Yes it's a variable, I don't get what you mean with the parenthesis but you must be right, i got it working like this
availibleseed = bridge.getItem({name=textutils.serialize(currentseed.name)})
This return a null value.

And sure, here it is.
latest.log

commented

Nope, sorry, it returns a null item even with something in ME :(

commented

I don't get what you mean with the parenthesis but you must be right, i got it working like this

That's what I meant with the edit. I thought you're just inputting a string without the quotation marks(I'm a bit tired and wrote parentheses instead of quotation marks...)

Thank you for the log, I'll look into that

commented

Thank you

commented

ok. Doesn't matter, i'll check for both.

Thanks again for the quick fix !

commented

Much better, no exception, and retruns an empty table/object.
Shouldn't you return nil though ? That's what i get with a random/bad item name.

commented

Much better, no exception, and retruns an empty table/object. Shouldn't you return nil though ? That's what i get with a random/bad item name.

Not sure tbh. In some places it's an empty table, in some places it's nil
I decided to use empty tables, but ig nil would be better

commented

That's a thing I want to improve in 0.8

commented

If anyone needs a workaround, you can use pcall which is a bit like you would catch a exception in java.

local function  getItem(id)
    local ok, data = pcall(storage.getItem, {name = id})
    -- if the data is nil, return an table with a zero amount
    if not data then
       return {name = id, amount = 0}
    end
end

local cobblestone = getItem("minecraft:cobblestone")
print(cobblestone.amount)