From 6f9772202e3fd11ade9937e5f3540edc444f12da Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 12 Jan 2023 17:15:16 +0000 Subject: shop2 --- shop2/items.lua | 12 ++++++++---- shop2/main.lua | 3 +-- shop2/stock.lua | 8 +++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/shop2/items.lua b/shop2/items.lua index 2eb497c..82d0104 100644 --- a/shop2/items.lua +++ b/shop2/items.lua @@ -1,12 +1,16 @@ local items = {} -local function i(adr,itname,hname,price,colour) - items[adr]={itname=itname,hname=hname,price=price,adr=adr,colour=colour or colors.white} +local function i(adr,itname,hname,price,colour,check) + items[adr]={itname=itname,hname=hname,price=price,adr=adr,colour=colour or colors.white,check=check} end i("dmn","minecraft:diamond","Diamond",2,colors.cyan) i("blz","minecraft:blaze_rod","Blaze Rod",0.5,colors.yellow) i("ely","minecraft:elytra","Elytra",100,colors.purple) --- todo properly -i("mnd","minecraft:ooo","Mending Book",10,colors.green) +i("mnd","minecraft:enchanted_book","Mending Book",10,colors.green,function(idetail) + for _,ench in ipairs(idetail.enchantments or {}) do + if ench.name == "minecraft:mending" then return true end + end + return false +end) i("nth","minecraft:nether_star","Nether Star",200,colors.white) return items diff --git a/shop2/main.lua b/shop2/main.lua index e4995cc..1def219 100644 --- a/shop2/main.lua +++ b/shop2/main.lua @@ -49,7 +49,7 @@ local function proctrans(tr) if not idesc then -- some other metaname that has nothing to do with us -- presumably some other service @ac.kst. so just ignore it - tell("(debug) i didn't recognise that metaname so no transaction occurs") + -- tell("(debug) i didn't recognise that metaname so no transaction occurs") return end @@ -84,7 +84,6 @@ local function run_shop() our_addr = msg.address.address end if msg.type == "event" and msg.event == "transaction" then - print("proctransing...") proctrans(msg.transaction) end end diff --git a/shop2/stock.lua b/shop2/stock.lua index 71a6844..fb7ab1b 100644 --- a/shop2/stock.lua +++ b/shop2/stock.lua @@ -24,7 +24,13 @@ local function item_desc_matches(idesc,itemdetail) -- idesc is an entry from ITEMS -- itemdetail is something returned from getItemDetail on the chest -- if you were wondering - return idesc.itname == itemdetail.name + + if idesc.itname == itemdetail.name then + if idesc.check then return idesc.check(itemdetail) end + return true + end + return false + end local function amt_of(stockinfo,idesc) -- cgit v1.2.3