This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hilburn's profile picture

Item Id Database

Started by hilburn, 16 July 2014 - 04:34 AM
hilburn #1
Posted 16 July 2014 - 06:34 AM
Ok, so basically one of my current projects is an Applied Energistics powered store, powered by CC. The concept was to have a MAC and processing site initially loaded with 500 or so patterns as well as having the ability for people to supply their own patterns, and that's all working fine.

My problem comes with the craftingRequest() method (OpenPeripherals), as it requires a table to be passed with {["id"] = X, ["qty"] = Y, (["dmg"] = Z)}. Or rather, I should say my problem comes with the interface with it. Rather than having the user type in the ID of the item, I'd like for them to be able to do it by name and then only deal with IDs if there are a pair of items with the same name (eg. Item Cannon from RotaryCraft and OpenBlocks) although even then I'd rather display the mod name and let them choose by that.

Is there a way, not necessarily in game, to get hold of a list of all the item ids and their corresponding name for the currently installed modpack? If not then it's not the end of the world, I'll just plug into my home ME unit, craft one of everything I can and then scan it (loop through id 1-50,000, dmg 1-64, see if it can craft, if so, pull the name), but I'd rather not use this solution as a) I'm designing it in a creative world so I don't have a particularly comprehensive ME system, b.) I'd quite like to be able to attach other information to the items, such as which mod it is from - NEI style, and that information is not available from an inventory scan and c) lazy

Cheers guys, any help you can give would be apprecated
Edited on 16 July 2014 - 04:34 AM
Bomb Bloke #2
Posted 16 July 2014 - 07:55 AM
Generally, the only way to do it (other than the scanner you've considered) is to run a MineCraft mod which dumps the list to a text file when the game launches. Coders have done this in the past, but the only online release I've seen is for some old MC version - the author didn't have any personal need to update it.

So unless you've already got some idea how to build a mod, the scanner sounds like the way to go; I've used such a system myself in the past. For mass items, I'd recommend rigging a computer up to run a command block as a peripheral (in a separate world if you like - so long as it's the same pack), allowing you to spam item spawning commands and quickly generate loads of example materials for it to check the names of.

The only problem is that sometimes OpenPeripheral doesn't get the proper names of certain items, but rather returns the "internal" names instead. And as you say, this won't get you the source mod titles.
hilburn #3
Posted 16 July 2014 - 08:18 AM
Ooooh I like the command block idea, most of my designs are for survival servers so I've never really used command blocks as peripherals and the idea never occurred to me
hilburn #4
Posted 16 July 2014 - 10:05 PM
Update - I wrote some code that would let me, while standing on a PIM - have every item in the game given to me by a command block, scanned and then destroyed by the PIM with it's ID, name, dmg value and rawname stored in a file

The table structure is a bit odd, it is along the lines of {ID={NAME={DMG,RAWNAME}}} as this allowed me to easily check for things like Wool 35:16 == Wool 35:0 so stop generating wool and move onto the next ID
However - due to this method spawning some random entities that do not appear in NEI and really do not react well to being scanned with OpenPeripherals (Notably 199:5 tile.normalface.cube and 432:7 tile.electriore so far) to the degree that I've had to delete the worlds (hence the random start code which let's me set the command block as starting wherever the last run conked out)

Thought it might prove useful to anyone else in the same situation as me, just don't run it in a world you care about, because it will almost definitely break it at some point


command = peripheral.wrap("left")
pim = peripheral.wrap("front")
me = "ValiarMarcus"
itemdata={}
function isNew(lid,lname)
if itemdata[lid]==nil then
  return true
else
  for i,j in pairs(itemdata[lid]) do
   if i==lname then return false end
  end
end
return true
end
function addnew(item)
if itemdata[item[1]]==nil then itemdata[item[1]]={} end
itemdata[item[1]][item[2]] = {["dmg"]=item[3], ["rawName"]=item[4]}
end
function saveFile()
if fs.exists("ItemID.dat") then
  fs.delete("ItemID.dat")
end
file = fs.open("ItemID.dat", "w")
file.write(textutils.serialize(itemdata))
file.close()
end
function loadFile()
if fs.exists("ItemID.dat") then
file = fs.open("ItemID.dat", "r")
itemdata = textutils.unserialize(file.readAll())
file.close()
end
end
function newItem(ID, DMG)
local com = "give "..me.." "..ID.." 1 "..DMG
command.setCommand(com)
command.runCommand()
sleep(0.05)
pim.condenseItems()
local slot1 = pim.getStackInSlot(1)
pim.destroyStack(1)
if slot1==nil then
  return false
elseif isNew(ID,slot1.name) then
  addnew({slot1.id, slot1.name, slot1.dmg, slot1.rawName})
  saveFile()
  return true
else
  return false
end
end
loadFile()
temp=command.getCommand()
pass1=string.gsub(temp,"give "..me.." ","")
pass2=string.gsub(pass1," 1 %d","")
if pass2==nil then pass2=1 end
for id = pass2,31999 do
dmg = 0
while newItem(id, dmg) do
  dmg=dmg+1
end
end
Edited on 16 July 2014 - 08:06 PM
theoriginalbit #5
Posted 17 July 2014 - 01:46 AM
The table structure should have been

{id=35, dmg=6, qty=1}

And omitting the dmg when there's an item without a damage value.

As for the crash, I suggest that if you're running the latest OpenPeripheral that you get the stack trace if the crash and report it over at the OpenPeripheral GitHub, so that someone can fix the problem.