mirror of
https://github.com/mt-mods/currency.git
synced 2024-11-19 19:13:44 +01:00
Make minetest_game an optional dependency
This commit is contained in:
parent
3d6f6be190
commit
a81a47c23e
@ -1,4 +1,5 @@
|
||||
barter = {}
|
||||
currency.barter = {}
|
||||
barter = currency.barter -- Kept as a global variable for compatibility
|
||||
|
||||
local S = minetest.get_translator("currency")
|
||||
|
||||
@ -120,14 +121,14 @@ minetest.register_node("currency:barter", {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.500000,0.312500,-0.500000,0.500000,0.500000,0.500000},
|
||||
{-0.437500,-0.500000,-0.437500,-0.250000,0.500000,-0.250000},
|
||||
{-0.437500,-0.500000,-0.437500,-0.250000,0.500000,-0.250000},
|
||||
{-0.437500,-0.500000,0.250000,-0.250000,0.500000,0.437500},
|
||||
{0.250000,-0.500000,-0.437500,0.437500,0.500000,-0.250000},
|
||||
{0.250000,-0.500000,0.250000,0.437500,0.500000,0.447500},
|
||||
{0.250000,-0.500000,0.250000,0.437500,0.500000,0.447500},
|
||||
},
|
||||
},
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
sounds = currency.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", S("Barter Table"))
|
||||
|
50
crafting.lua
50
crafting.lua
@ -1,27 +1,32 @@
|
||||
minetest.register_craft({
|
||||
output = 'currency:safe',
|
||||
recipe = {
|
||||
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
|
||||
{'default:steel_ingot', 'default:mese_crystal', 'default:steel_ingot'},
|
||||
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
|
||||
}
|
||||
})
|
||||
if minetest.get_modpath("default") then
|
||||
minetest.register_craft({
|
||||
output = "currency:safe",
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:steel_ingot",
|
||||
"default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:mese_crystal",
|
||||
"default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:steel_ingot",
|
||||
"default:steel_ingot"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'currency:shop',
|
||||
recipe = {
|
||||
{'default:sign_wall'},
|
||||
{'default:chest_locked'},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "currency:shop",
|
||||
recipe = {
|
||||
{"default:sign_wall"},
|
||||
{"default:chest_locked"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'currency:barter',
|
||||
recipe = {
|
||||
{'default:sign_wall'},
|
||||
{'default:chest'},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "currency:barter",
|
||||
recipe = {
|
||||
{"default:sign_wall"},
|
||||
{"default:chest"},
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
@ -166,4 +171,3 @@ minetest.register_craft({
|
||||
recipe = "currency:minegeld_bundle",
|
||||
burntime = 1,
|
||||
})
|
||||
|
||||
|
7
init.lua
7
init.lua
@ -2,6 +2,13 @@ local modpath = minetest.get_modpath("currency")
|
||||
|
||||
minetest.log("info", "Currency mod loading...")
|
||||
|
||||
currency = {}
|
||||
if minetest.global_exists("default") then
|
||||
currency.node_sound_wood_defaults = default.node_sound_wood_defaults
|
||||
else
|
||||
currency.node_sound_wood_defaults = function() end
|
||||
end
|
||||
|
||||
dofile(modpath.."/craftitems.lua")
|
||||
minetest.log("info", "[Currency] Craft_items Loaded!")
|
||||
dofile(modpath.."/shop.lua")
|
||||
|
3
mod.conf
3
mod.conf
@ -1,5 +1,4 @@
|
||||
name = currency
|
||||
depends = default
|
||||
optional_depends = loot, pipeworks
|
||||
optional_depends = default, loot, pipeworks
|
||||
description = Provides shops, barter tables, safes, and multiple denominations of currency, called "Minegeld".
|
||||
min_minetest_version = 5.2.0
|
||||
|
8
safe.lua
8
safe.lua
@ -1,6 +1,6 @@
|
||||
local S = minetest.get_translator("currency")
|
||||
|
||||
function default.get_safe_formspec(pos)
|
||||
function currency.get_safe_formspec(pos)
|
||||
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
|
||||
local formspec =
|
||||
"size[8,9]"..
|
||||
@ -11,6 +11,10 @@ function default.get_safe_formspec(pos)
|
||||
return formspec
|
||||
end
|
||||
|
||||
if minetest.global_exists("default") then
|
||||
default.get_safe_formspec = currency.get_safe_formspec
|
||||
end
|
||||
|
||||
local function has_safe_privilege(meta, player)
|
||||
local name = ""
|
||||
if player then
|
||||
@ -100,7 +104,7 @@ minetest.register_node("currency:safe", {
|
||||
minetest.show_formspec(
|
||||
clicker:get_player_name(),
|
||||
"currency:safe",
|
||||
default.get_safe_formspec(pos)
|
||||
currency.get_safe_formspec(pos)
|
||||
)
|
||||
end
|
||||
end,
|
||||
|
45
shop.lua
45
shop.lua
@ -1,8 +1,12 @@
|
||||
local S = minetest.get_translator("currency")
|
||||
|
||||
default.shop = {}
|
||||
default.shop.current_shop = {}
|
||||
default.shop.formspec = {
|
||||
currency.shop = {}
|
||||
if minetest.global_exists("default") then
|
||||
default.shop = currency.shop
|
||||
end
|
||||
|
||||
currency.shop.current_shop = {}
|
||||
currency.shop.formspec = {
|
||||
customer = function(pos)
|
||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
local formspec = "size[8,9.5]"..
|
||||
@ -37,7 +41,7 @@ default.shop.formspec = {
|
||||
|
||||
local have_pipeworks = minetest.global_exists("pipeworks")
|
||||
|
||||
default.shop.check_privilege = function(listname,playername,meta)
|
||||
currency.shop.check_privilege = function(listname,playername,meta)
|
||||
--[[if listname == "pl1" then
|
||||
if playername ~= meta:get_string("pl1") then
|
||||
return false
|
||||
@ -56,7 +60,7 @@ default.shop.check_privilege = function(listname,playername,meta)
|
||||
end
|
||||
|
||||
|
||||
default.shop.give_inventory = function(inv,list,playername)
|
||||
currency.shop.give_inventory = function(inv,list,playername)
|
||||
player = minetest.get_player_by_name(playername)
|
||||
if player then
|
||||
for k,v in ipairs(inv:get_list(list)) do
|
||||
@ -66,18 +70,18 @@ default.shop.give_inventory = function(inv,list,playername)
|
||||
end
|
||||
end
|
||||
|
||||
default.shop.cancel = function(meta)
|
||||
--[[default.shop.give_inventory(meta:get_inventory(),"pl1",meta:get_string("pl1"))
|
||||
default.shop.give_inventory(meta:get_inventory(),"pl2",meta:get_string("pl2"))
|
||||
currency.shop.cancel = function(meta)
|
||||
--[[currency.shop.give_inventory(meta:get_inventory(),"pl1",meta:get_string("pl1"))
|
||||
currency.shop.give_inventory(meta:get_inventory(),"pl2",meta:get_string("pl2"))
|
||||
meta:set_string("pl1","")
|
||||
meta:set_string("pl2","")
|
||||
meta:set_int("pl1step",0)
|
||||
meta:set_int("pl2step",0)]]
|
||||
end
|
||||
|
||||
default.shop.exchange = function(meta)
|
||||
--[[default.shop.give_inventory(meta:get_inventory(),"pl1",meta:get_string("pl2"))
|
||||
default.shop.give_inventory(meta:get_inventory(),"pl2",meta:get_string("pl1"))
|
||||
currency.shop.exchange = function(meta)
|
||||
--[[currency.shop.give_inventory(meta:get_inventory(),"pl1",meta:get_string("pl2"))
|
||||
currency.shop.give_inventory(meta:get_inventory(),"pl2",meta:get_string("pl1"))
|
||||
meta:set_string("pl1","")
|
||||
meta:set_string("pl2","")
|
||||
meta:set_int("pl1step",0)
|
||||
@ -165,7 +169,7 @@ minetest.register_node("currency:shop", {
|
||||
"shop_front.png"},
|
||||
inventory_image = "shop_front.png",
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2,tubedevice=1,tubedevice_receiver=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
sounds = currency.node_sound_wood_defaults(),
|
||||
after_place_node = function(pos, placer, itemstack)
|
||||
local owner = placer:get_player_name()
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -205,12 +209,12 @@ minetest.register_node("currency:shop", {
|
||||
on_rightclick = function(pos, node, clicker, itemstack)
|
||||
clicker:get_inventory():set_size("customer_gives", 3*2)
|
||||
clicker:get_inventory():set_size("customer_gets", 3*2)
|
||||
default.shop.current_shop[clicker:get_player_name()] = pos
|
||||
currency.shop.current_shop[clicker:get_player_name()] = pos
|
||||
local meta = minetest.get_meta(pos)
|
||||
if clicker:get_player_name() == meta:get_string("owner") and not clicker:get_player_control().aux1 then
|
||||
minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",default.shop.formspec.owner(pos))
|
||||
minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",currency.shop.formspec.owner(pos))
|
||||
else
|
||||
minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",default.shop.formspec.customer(pos))
|
||||
minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",currency.shop.formspec.customer(pos))
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
@ -249,7 +253,7 @@ minetest.register_node("currency:shop_empty", {
|
||||
"shop_front_empty.png"},
|
||||
drop = "currency:shop",
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2,tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
sounds = currency.node_sound_wood_defaults(),
|
||||
after_dig_node = (have_pipeworks and pipeworks and pipeworks.after_dig),
|
||||
tube = {
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
@ -272,12 +276,12 @@ minetest.register_node("currency:shop_empty", {
|
||||
on_rightclick = function(pos, node, clicker, itemstack)
|
||||
clicker:get_inventory():set_size("customer_gives", 3*2)
|
||||
clicker:get_inventory():set_size("customer_gets", 3*2)
|
||||
default.shop.current_shop[clicker:get_player_name()] = pos
|
||||
currency.shop.current_shop[clicker:get_player_name()] = pos
|
||||
local meta = minetest.get_meta(pos)
|
||||
if clicker:get_player_name() == meta:get_string("owner") and not clicker:get_player_control().aux1 then
|
||||
minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",default.shop.formspec.owner(pos))
|
||||
minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",currency.shop.formspec.owner(pos))
|
||||
else
|
||||
minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",default.shop.formspec.customer(pos))
|
||||
minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",currency.shop.formspec.customer(pos))
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
@ -308,7 +312,7 @@ minetest.register_node("currency:shop_empty", {
|
||||
minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
||||
if formname == "currency:shop_formspec" and fields.exchange ~= nil and fields.exchange ~= "" then
|
||||
local name = sender:get_player_name()
|
||||
local pos = default.shop.current_shop[name]
|
||||
local pos = currency.shop.current_shop[name]
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_string("owner") == name then
|
||||
minetest.chat_send_player(name, S("This is your own shop, you can't exchange to yourself!"))
|
||||
@ -362,4 +366,3 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user