Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inter = peripheral.find("trading_interface")
- local tradeList = {}
- function getTrades(sMode,targetStr)
- local ret = nil
- inter.cycleTrades()
- ret,tradeList = inter.getTrades();
- for key, value in pairs(tradeList) do
- if value ~= nil then
- local result = value["result"]
- for key, value in pairs(result) do
- if key == "minecraft:enchanted_book" then
- -- find enchanted_book
- local enchants = value["enchants"]
- for key, value in pairs(enchants) do
- local ret = nil
- if sMode then
- local pos = string.find(key,":")
- key = string.sub(key,pos+1)
- ret = string.match(key,"^"..targetStr.."$")
- else
- ret = string.find(key,targetStr)
- end
- if ret ~= nil then
- return true
- end
- end
- end
- end
- end
- end
- return false
- end
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("use \"S keywork\" to Strict matching")
- print("or just \"keywork\" to find what word have keyword")
- print("please type the keyword for find enchant_book:")
- local str = io.read()
- if str == "_res" then
- inter.restock()
- else
- local ret = false
- local sFinder = string.match(str,"^[sS][ ]+([%a_]+)[ ]*$")
- local sMode = false
- if sFinder ~= nil then
- sMode = true
- str = sFinder
- else
- str = string.match(str,"^[ ]*([%a_]+)[ ]*$")
- end
- repeat
- ret = getTrades(sMode,str)
- until ret
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement