From 130389705b8fd2380065341181fbcff90a287b6b Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 8 Jul 2018 10:04:45 +0200 Subject: [PATCH] Better migrate options, fix 'default' dependency --- currency_migrate.lua | 38 ++++++++++++++++++++------------------ currency_override.lua | 11 ++++++----- depends.txt | 1 + init.lua | 23 +++++++++++++++++------ mod.conf | 1 + 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/currency_migrate.lua b/currency_migrate.lua index ad49c85..2f851e0 100644 --- a/currency_migrate.lua +++ b/currency_migrate.lua @@ -41,7 +41,7 @@ local function list_add_list(inv, list_name, list) return leftover_list end -local function migrate_shop_node(pos, node) +function exchange_shop.migrate_shop_node(pos, node) local meta = minetest.get_meta(pos) local owner = meta:get_string("owner") local title = meta:get_string("infotext") @@ -76,22 +76,24 @@ local function migrate_shop_node(pos, node) minetest.swap_node(pos, node) end -minetest.register_lbm({ - label = "currency shop to exchange shop migration", - name = "exchange_shop:currency_migrate", - nodenames = { "currency:shop" }, - run_at_every_load = true, -- TODO this for testing only - action = migrate_shop_node -}) +if exchange_shop.migrate.use_lbm then + minetest.register_lbm({ + label = "currency shop to exchange shop migration", + name = "exchange_shop:currency_migrate", + nodenames = { "currency:shop" }, + run_at_every_load = false, + action = exchange_shop.migrate_shop_node + }) --- Clean up garbage -minetest.register_on_joinplayer(function(player) - local inv = player:get_inventory() - for i, name in pairs({"customer_gives", "customer_gets"}) do - if inv:get_size(name) > 0 then - local leftover = list_add_list(inv, "main", inv:get_list(name)) - list_add_list(inv, "craft", leftover) - inv:set_size(name, 0) + -- Clean up garbage + minetest.register_on_joinplayer(function(player) + local inv = player:get_inventory() + for i, name in pairs({"customer_gives", "customer_gets"}) do + if inv:get_size(name) > 0 then + local leftover = list_add_list(inv, "main", inv:get_list(name)) + list_add_list(inv, "craft", leftover) + inv:set_size(name, 0) + end end - end -end) \ No newline at end of file + end) +end diff --git a/currency_override.lua b/currency_override.lua index a6e9da2..c2759ca 100644 --- a/currency_override.lua +++ b/currency_override.lua @@ -1,8 +1,5 @@ -local def = table.copy(minetest.registered_nodes["currency:shop"]) -def.groups.not_in_creative_inventory = 1 minetest.override_item("currency:shop", { - groups = def.groups, on_construct = function() end, after_place_node = function(pos, ...) local node = minetest.get_node(pos) @@ -14,6 +11,10 @@ minetest.override_item("currency:shop", { new_def.on_construct(pos) end new_def.after_place_node(pos, unpack({...})) - + end, + on_rightclick = function(pos, node, ...) + exchange_shop.migrate_shop_node(pos, node) + local new_def = minetest.registered_nodes[exchange_shop.shopname] + new_def.on_rightclick(pos, node, unpack({...})) end -}) \ No newline at end of file +}) diff --git a/depends.txt b/depends.txt index a0e4e11..4167e2f 100644 --- a/depends.txt +++ b/depends.txt @@ -1,3 +1,4 @@ +default currency? bitchange? wrench? \ No newline at end of file diff --git a/init.lua b/init.lua index d503121..e8c7c5c 100644 --- a/init.lua +++ b/init.lua @@ -5,23 +5,34 @@ exchange_shop.shopname = "exchange_shop:shop" local modpath = minetest.get_modpath("exchange_shop") local has_currency = minetest.get_modpath("currency") local has_bitchange = minetest.get_modpath("bitchange") -local migrate_currency = true -- TODO testing! -local slow_migrate_currency = false + +-- Currency migrate options +exchange_shop.migrate = { + use_lbm = false, + -- ^ Runs once on each unique loaded mapblock + on_interact = true + -- ^ Converts shop nodes "on the fly" +} if has_bitchange then minetest.register_alias("exchange_shop:shop", "bitchange:shop") exchange_shop.shopname = "bitchange:shop" else + minetest.register_alias("bitchange:shop", "exchange_shop:shop") dofile(modpath .. "/shop_functions.lua") dofile(modpath .. "/shop.lua") end if has_currency then - if migrate_currency then - dofile(modpath .. "/currency_migrate.lua") - end - if slow_migrate_currency then + local new_groups = table.copy(minetest.registered_nodes["currency:shop"].groups) + new_groups.not_in_creative_inventory = 1 + minetest.override_item("currency:shop", { + groups = new_groups + }) + + dofile(modpath .. "/currency_migrate.lua") + if exchange_shop.migrate.on_interact then dofile(modpath .. "/currency_override.lua") end end diff --git a/mod.conf b/mod.conf index 941d0d3..3f4a198 100644 --- a/mod.conf +++ b/mod.conf @@ -1,2 +1,3 @@ name = exchange_shop +depends = default optional_depends = currency, bitchange, wrench