Logistics Pipes

Logistics Pipes

13M Downloads

ComputerCraft getItemAmount()

Morketh opened this issue ยท 15 comments

commented

i keep getting an error in computercraft with and with out OpenPeripherals in stalled:

Java Exception Thrown:
java.lang.UnsupportedOerataionException: No such method.getItemAmount(Logisticspipes.utils.item.ItemIdentifier)

computer is sitting next to a request pipe and calling peripherals.getMethods("left") returns a list of methods one of which is getItemAmount however I am unable to utilize this function ive been trying for several weeks to find a solution. I dug around in the LP source code (

public int getItemAmount(ItemIdentifier item) throws Exception {
) and clearly there is a method available however im clearly not using it correctly or java isn't understanding my request. any pointers or suggestion would be helpful

commented

Wasn't exactly a CRASH it was an Exception that was thrown on the Computercraft Terminal and that was the only thing i received (both in single player and in Multiplayer) no console errors or other messages.

admiral@USS-Havok:/opt/minecraft/1.7.10/mods$ ls -shal | grep "jar" | awk '{print $10}'
[1.7.10]Treecapitator-universal-2.0.4.jar
ABO-MC1.7.10-BC7.1release4.0.3.jar
AgeOfMinecraft-1.7.10-0.0.3a.jar
buildcraft-7.1.13.jar 
buildcraft-compat-7.1.1.jar
CodeChickenCore-1.7.10-1.0.7.47-universal.jar
ComputerCraft1.74.jar
Dynmap-2.1-forge-1.7.10.jar
EnderCore-1.7.10-0.1.0.26_beta.jar
EnderIO-1.7.10-2.2.8.381.jar
EnderStorage-1.7.10-1.4.7.37-universal.jar
extrautilities-1.2.12.jar
forestry_1.7.10-4.0.11.40.jar
forgeessentials-1.7.10-server-dev.jar
forgeessentials-1.7.10-server.jar
IC2NuclearControl-2.3.2a-Butt.jar
industrialcraft-2-2.2.784-experimental.jar
ironchest-1.7.10-6.0.60.741-universal.jar
logisticspipes-0.9.3.69.jar (Also tried with logisticspipes-0.9.3.61.jar)
magicalcrops-4.0.0_PUBLIC_BETA_3.jar
Mantle-1.7.10-0.3.2b.jar
Mekanism-1.7.10-8.1.7.252.jar
MekanismGenerators-1.7.10-8.1.7.252.jar
MekanismTools-1.7.10-8.1.7.252.jar
MobiusCore-1.2.5_1.7.10.jar
ModularPowersuits-0.11.0.283d.jar
MyEssentials-Core-1.7.10-1.16r-universal.jar
MyPermissions-1.7.10-42-dev.jar
mystcraft-1.7.10-0.11.0.00.jar
MyTown2-1.7.10-0.3.2b.jar
natura-1.7.10-2.2.0.1.jar
NotEnoughItems-1.7.10-1.0.5.118-universal.jar
Numina-0.4.0.131.jar
openccsensors-1.7.5.jar
OpenModsLib-1.7.10-0.8.jar
OpenPeripheral-1.7.10-AIO-5.jar
Opis-1.2.5_1.7.10.jar
Pam's HarvestCraft 1.7.10k.jar
ProjectRed-1.7.10-4.7.0pre9.92-Base.jar
ProjectRed-1.7.10-4.7.0pre9.92-Compat.jar
ProjectRed-1.7.10-4.7.0pre9.92-Fabrication.jar
ProjectRed-1.7.10-4.7.0pre9.92-Integration.jar
ProjectRed-1.7.10-4.7.0pre9.92-Lighting.jar
ProjectRed-1.7.10-4.7.0pre9.92-Mechanical.jar
ProjectRed-1.7.10-4.7.0pre9.92-World.jar
Railcraft_1.7.10-9.8.0.0.jar
TConstruct-1.7.10-1.8.5.jar
twilightforest-1.7.10-2.3.7.jar
Waila-1.5.10_1.7.10.jar
worldedit-forge-mc1.7.10-6.1.1-SNAPSHOT-dist.jar

I have tested with and with out, OpenMods + OpenPeripheral however i have not done any testing with out the openccsensors. Im fairly sure that its not ccsensors however probably should be tested with just LP and CC.
Also running cat latest.log | grep "java.lang.UnsupportedOerataionException" provides zero results in the server log neither does cat fml-server-* | grep "java.lang.UnsupportedOerataionException" the only trace of that error is inside the computer terminal when you call the program

screen = peripheral.wrap("left")
LPipe = peripheral.wrap("right")
term.redirect(screen)
itemList = LPipe.getAvailableItems()

--textutils.tabulate(peripheral.getMethods("right"))

term.clear()
term.setCursorPos(1,1)

--LPipe.getItemAmount(4)
LPipe.getItemAmount("cobbleStone")

EDIT: forgot MC version info
forge-1.7.10-10.13.4.1566-1.7.10-universal

The client is additionally running:

ABO-MC1.7.10-BC7.1release4.0.3.jar
AgeOfMinecraft-1.7.10-0.0.3a.jar
buildcraft-7.1.13.jar
buildcraft-compat-7.1.1.jar
CodeChickenCore-1.7.10-1.0.7.47-universal.jar
ComputerCraft1.74.jar
EnderCore-1.7.10-0.1.0.26_beta.jar
EnderIO-1.7.10-2.2.8.381.jar
EnderStorage-1.7.10-1.4.7.37-universal.jar
extrautilities-1.2.12.jar
forestry_1.7.10-4.0.11.40.jar
forgeessentials-1.7.10-1.4.3.1035-client.jar
IC2NuclearControl-2.3.2a-Butt.jar
industrialcraft-2-2.2.784-experimental.jar
InventoryTweaks-1.59-dev-152.jar
ironchest-1.7.10-6.0.60.741-universal.jar
logisticspipes-0.9.3.69.jar
magicalcrops-4.0.0_PUBLIC_BETA_3.jar
Mantle-1.7.10-0.3.2b.jar
Mekanism-1.7.10-8.1.7.252.jar
MekanismGenerators-1.7.10-8.1.7.252.jar
MekanismTools-1.7.10-8.1.7.252.jar
MobiusCore-1.2.5_1.7.10.jar
ModularPowersuits-0.11.0.283c.jar
mod_macros_0.10.12_for_1.7.10.litemod
mod_worldeditcui_1.7.10_00_mc1.7.10.litemod
mod_worldeditwrapper_1.2.0_we5.6.2_mc1.7.10.litemod
MouseTweaks-2.4.4-mc1.7.10.jar
mystcraft-1.7.10-0.11.0.00.jar
natura-1.7.10-2.2.0.1.jar
NotEnoughItems-1.7.10-1.0.5.118-universal.jar
Numina-0.4.0.131.jar
openccsensors-1.7.5.jar
OpenModsLib-1.7.10-0.8.jar
OpenPeripheral-1.7.10-AIO-5.jar
Opis-1.2.5_1.7.10.jar
Pam's HarvestCraft 1.7.10k.jar
ProjectRed-1.7.10-4.7.0pre9.92-Base.jar
ProjectRed-1.7.10-4.7.0pre9.92-Compat.jar
ProjectRed-1.7.10-4.7.0pre9.92-Fabrication.jar
ProjectRed-1.7.10-4.7.0pre9.92-Integration.jar
ProjectRed-1.7.10-4.7.0pre9.92-Lighting.jar
ProjectRed-1.7.10-4.7.0pre9.92-Mechanical.jar
ProjectRed-1.7.10-4.7.0pre9.92-World.jar
Railcraft_1.7.10-9.8.0.0.jar
Solarstone_IKO_Once_Pure_Mix_hd720.mp4
TConstruct-1.7.10-1.8.5.jar
twilightforest-1.7.10-2.3.7.jar
Waila-1.5.10_1.7.10.jar
XrayMod-1.7.10.litemod
Zans-Minimap-Mod-1.7.10.litemod
[1.7.10]Treecapitator-universal-2.0.4.jar
commented

"cobbleStone" Is not an LP ItemIdentifier. That is just a string.
You need to get an ItemIdentifier to use that method.

commented

Could you please post your Minecraft, LogisticsPipes, ComputerCraft and OpenPeripherals version information? Also please post the full crash log to https://gist.github.com and give us a link here.

commented

Using the Number 4 for cobblestone as reported by NEI yields the same results.

LPipe.getItemAmount(4)

again ive been trying to solve this for weeks ive tried every permutation of that command including looking around the internet for help looking for references trying to understand how LP source code works (according to the source sited above it takes an integer however it doesn't like that either)
and even if i gave it a String i would hope that your code would throw:

if (item == null) {
            throw new Exception("Invalid ItemIdentifierID");

however the only response i get off the computercraft terminal is that UnsuportedMethod. now Java might be completely different then my preferred Python code but i believe based on my research that it isnt even reaching that line of code because "cobbleStone" might not be an Identifier but its not NULL either Thats also why the number 4 crashes the Computercraft Computer. if the number 4 was invalid i should be getting the Invalid ID Exception as well but again it crashes out with an "No such method.getItemAmount" digging around the issues pages i have found a post by @davboecki on #585 that kindly informs us that the ItemIdentifier is not an ID its an Object so at this point I'm entirely confused as to why its not throwing an Invalid ID.

EDIT:
http://rs485.network/wiki/ComputerCraft_API
Wiki pages are a bit bare when it comes to information retention. That was actually the first place i looked.

commented

In java methods are defined by there name AND ny there parameters, and that is what our CC implementation refers to. So if you try to get the getItemAmount(String) method or the getItemAmount(int) method there is none. There only is a getItemAmount(ItemIdentifier) method. The one thing that's probably not correct is the error message. It should be:

if (item == null) {
            throw new Exception("Invalid ItemIdentifier");

Without the ID. The ID was our old system which was replaced by the ItemIdentifier objects.
For how to get an ItemIdentifier i'm refering you to the already mentioned post in #585 (comment).

commented

Im pretty sure its not supposed to do this either. Again with the Unsupported Operation Exception
2015-11-23_16 03 04
on the PLUS side i got an "Invalid ItemIdentifier" Exception. But this doesn't get me anywhere close to hooking a computer up to a pipe. i know this question was already asked and your answer already given on that post, however id like to ask it again; Why exactly is it so difficult to use this method of object retrieval. from a python programmers stand point i would think it would be easier to use a string/ID number (although this could get messy with the way forge likes to rearrange ID numbers between server and client perhaps use a bit of code to map every object in the game to an internal Identifier DB that we can run a lookup on?) is there a way i can grab a list of objects in the Network grab "Item Identifier objects" with out all this Red-Tape? im all about functional and keeping the program open to complex tasks the way y'all have it but im also looking at it from a Users point of view. And yes i have to agree with you making it easier on the User is a bit harder on the programmer, Ive dealt with that for years working on Python code but at some point being extremely easy to program makes exceptionally difficult to the average user (and ive been programming for 6 years im no Rookie programmer)

commented

You need to tell it the item ID first before you build the ItemIdentifier.

builder = lp.getItemIdentifierBuilder()
builder.setID(1)
... (Maybe set a damage value as well)
item = builder.build()

Now you have an ItemIdentifier.
By using getAvailableItems you should get a list of pairs of ItemIdentifier and integer representing the amount. Again help() is your friend.
We needed to go the object oriented route in some places so I decided to keep it consistant. And yes this makes it easier for us to add methods and a little bit harder for the user. But at the same time this is more powerfull, and better when it comes to performance, and we just don't have the time to maintain/implement anything complicated [To make it easier for the user] right now.

commented

@davboecki could this be added to the wiki so other travelers can find this information? you keep referring me to the Help() method is there actual documentation buried inside the LP Code (the help() has to originate someplace) if that's the case could i read those sections of the code to get answers? calling the Help() method is not really helpful on a 2 Inch Screen (even blowing it up on the monitor peripheral doesn't help much)

commented

Ok so i think i figured it out (no java exception thrown ^_^)
2015-11-24_15 32 26
This should be exactly the way it should work. now if i swap out the setID(1) for any ItemID i should be able to save results for those item types (and possibly damage values as you hinted at)
At this point i think we can close the issue.

commented

@davboecki what if you make an alternative getItemAmount(id, count) and build ItemIdentifier in java code instead of requiring it to be handcrafted? An alternative stuff can make programming more handy and would not require a bunch of code on CC side (coding in CC is not so funny, especially if the code comes longer and longer...)

commented

@Morketh I strongly recommend you to not use integer item identifier anymore. If I remember correctly, they will go away in 1.8, so it's a good time to migrate all of your old code to textual item identifiers (e.g. minecraft:stone)

commented

@hron84 I will keep that in mind. Thank you for the help on this its been really frustrating but managed to get it working none the less

commented

so there must be some other way of setting Items other then builder.setItemID(Double) which was returned using the builder.help() no methods in side that help take a string as an argument. this all seems rather Hackish to me. organizationally speaking if you could use a string as a way of setting up a builder that method should also be included in that section?

commented

Yes we still need to add methods for the new string based identifier for items in Minecraft. We just haven't done that yet.

commented