Pulling Enchant Names from Enchanted Books
#1
Posted 27 January 2014 - 07:55 PM
I'm using openperipherals, but the website seems to be down right now, and I can't find any other documentation about the various functions it adds. I've tried using getStackInSlot, but the table it returns does not contain the information needed to distinguish between individual book enchants.
My question is, is there a way to get this info?
#2
Posted 27 January 2014 - 11:28 PM
for i,v in ipairs(peripheral.getMethods(side)) do print(i..". "..v) end
That will show you all the functions the peripheral adds, although how to use them, I cannot say.
#3 Guest_cameron2621_*
Posted 25 June 2014 - 01:23 AM
Please if you did message me!
Thanks,
Cameron2621
#4
Posted 25 June 2014 - 02:10 AM
{
id = 403,
name = "Enchanted Book",
maxdmg = 0,
rawName = "item.enchantedbook",
dmg = 0,
maxSize = 1,
ench = {
"Knockback II",
}
qty = 1
}
so the following code will loop through a chest and print out all the enchantments on any enchanted item
local chest = peripheral.wrap("left")
local contents = chest.getAllStacks()
for index, item in pairs(contents) do
if item.ench then --# if there is an enchantment(s) on the item
print("Found a ", item.name, " with the enchantments: ", table.concat(item.ench, ', '))
end
end
so the above code will also output enchantments on tools, armour, etc.
Edited by theoriginalbit, 25 June 2014 - 02:12 AM.
better example code
#5 Guest_cameron2621_*
Posted 25 June 2014 - 07:00 AM
theoriginalbit, on 25 June 2014 - 02:10 AM, said:
{
id = 403,
name = "Enchanted Book",
maxdmg = 0,
rawName = "item.enchantedbook",
dmg = 0,
maxSize = 1,
ench = {
"Knockback II",
}
qty = 1
}
so the following code will loop through a chest and print out all the enchantments on any enchanted item
local chest = peripheral.wrap("left")
local contents = chest.getAllStacks()
for index, item in pairs(contents) do
if item.ench then --# if there is an enchantment(s) on the item
print("Found a ", item.name, " with the enchantments: ", table.concat(item.ench, ', '))
end
end
so the above code will also output enchantments on tools, armour, etc.Thanks, I tried this and I am getting "startup:2: attempt to call nil"
#6
Posted 25 June 2014 - 07:05 AM
#7 Guest_cameron2621_*
Posted 25 June 2014 - 07:31 AM
theoriginalbit, on 25 June 2014 - 07:05 AM, said:
Nope I have the chest on the left side, I just need something simple like this code to expand on but need the simple stuff working first. It wouldn't matter that I am using a advanced computer would it?
#8
Posted 25 June 2014 - 07:53 AM
cameron2621, on 25 June 2014 - 07:31 AM, said:
table.concat( peripheral.getMethods("left"), ", ")
#9 Guest_cameron2621_*
Posted 25 June 2014 - 07:31 PM
#10
Posted 25 June 2014 - 09:16 PM
#11
Posted 26 June 2014 - 02:02 AM
cameron2621, on 25 June 2014 - 07:31 PM, said:
#12 Guest_cameron2621_*
Posted 26 June 2014 - 02:17 AM
The output I got:
listMethods, pullIntoSlot, pull, pushIntoSlot, push, condense, swapStacks, getInvName, getStackInSlot, getSizeInventory
Edited by cameron2621, 26 June 2014 - 02:20 AM.
#13
Posted 26 June 2014 - 02:20 AM
local chest = peripheral.wrap("left")
for i = 1, chest.getSizeInventory() do --# loop over all the slot indexes
local item = chest.getStackInSlot(i) --# get the item in the slow
if item.ench then --# if there is an enchantment(s) on the item
print("Found a ", item.name, " with the enchantments: ", table.concat(item.ench, ', '))
end
end
though considering how old of a version of OpenPeripheral you're using there's every chance that we may not have been collecting information on the enchantments at that point.
Edited by theoriginalbit, 26 June 2014 - 02:21 AM.
more code comments
#14 Guest_cameron2621_*
Posted 26 June 2014 - 02:35 AM
startup:3: java.lang.reflect.InvocationTargetException
Edit: I just saw in your code:
local item = chest.getStackInSlot(i)
I changed it to just do slot one by putting a 0 there, Did not get that error but nothing happend after that. It did not write anuthing
So does this just mean I can't do it with this version. Wait untill the pack updates?
Thanks,
Cameron
Edited by cameron2621, 26 June 2014 - 02:41 AM.
#15
Posted 26 June 2014 - 02:36 AM
if item.ench then
to this:
if item and item.ench then
Edit: Re that error you just ninja'd me with, try sticking a sleep(1) just before and after wrapping the chest.
Edited by Bomb Bloke, 26 June 2014 - 02:38 AM.
#16
Posted 26 June 2014 - 02:39 AM
however a reflection exception means something else entirely, not too sure what would cause it on something so simple for you that no one else had problems with.
FTB Unleashed won't update, it has been discontinued. you'd have to move to a different pack.
#17 Guest_cameron2621_*
Posted 26 June 2014 - 02:49 AM
http://pastebin.com/yxiN1dEk#
Got that same error of the line that says:
local item = chest.getStackInSlot(i)
Edited by cameron2621, 26 June 2014 - 02:50 AM.
#18
Posted 26 June 2014 - 02:52 AM
#19 Guest_cameron2621_*
Posted 26 June 2014 - 02:59 AM
#20
Posted 26 June 2014 - 04:17 AM
Perhaps try running the code on an empty chest. If that works, try one with some items other than enchanted books in it.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











