]> git.lizzy.rs Git - skycraft.git/blob - src/onload/shop_signs.lua
LuckyBlock Updates
[skycraft.git] / src / onload / shop_signs.lua
1 for nodename, nodedef in pairs(minetest.registered_nodes) do
2         if nodename:find("mcl_signs:") then
3                 minetest.override_item(nodename, {
4                         on_rightclick = function(pos, node, player, itemstack, pointed_thing)
5                                 if pos.y < 5000 then return end
6                                 local text = minetest.get_meta(pos):get_string("text") or ""
7                                 local lines = text:split("\n")
8                                 local action, amount, price = lines[1], lines[2], lines[3]
9                                 print(action, amount, price)
10                                 if not (action and amount and price) then return end
11                                 price = string.gsub(price, "%$", "")
12                                 price = tonumber(price)
13                                 amount = string.gsub(amount, "x", "")
14                                 amount = tonumber(amount)
15                                 print(action, amount, price)
16                                 if not (amount and price) then return end
17                                 local func, frameoffset
18                                 if action == "Buy" then
19                                         func, frameoffset = skycraft.buy, -1
20                                 elseif action == "Sell" then
21                                         func, frameoffset = skycraft.sell, 1
22                                 else
23                                         return
24                                 end
25                                 local framepos = vector.add(pos, {x = 0, y = frameoffset, z = 0})
26                                 if minetest.get_node(framepos).name ~= "mcl_itemframes:item_frame" then return end
27                                 local inv = minetest.get_meta(framepos):get_inventory()
28                                 if inv:is_empty("main") then return end
29                                 local itemstack = inv:get_stack("main", 1)
30                                 func(player, itemstack:get_name() .. " " .. tostring(amount), price)
31                         end,
32                 })
33         end
34 end
35