mirror of
https://github.com/minetest-mods/more_chests.git
synced 2025-06-29 22:00:33 +02:00
Mod rewrite and new models (#21)
* Aliases moved to utils folder * Method to generate two different formspec layouts, big and small * Log Actions moved to separate module * Added method to generate a chest definition * Rewritten models * Add Fridge model * Add Toolbox models * "Mod loaded" message; Updated localization template * Add Italian localization * Fridge now has both normal and big (2 blocks) models * Fixed mixed indentation * Rewritten README; improved IT and FR (thanks to @louisroyer) localizations.
This commit is contained in:
26
models/cobble.lua
Normal file
26
models/cobble.lua
Normal file
@ -0,0 +1,26 @@
|
||||
local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua")
|
||||
local S = minetest.get_translator("more_chests")
|
||||
|
||||
local cobble = gen_def({
|
||||
description = S("Cobble Chest"),
|
||||
type = "chest",
|
||||
size = "small",
|
||||
tiles = {
|
||||
top = "default_cobble.png",
|
||||
side = "default_cobble.png",
|
||||
front = "cobblechest_front.png"
|
||||
},
|
||||
pipeworks_enabled = true,
|
||||
recipe = {
|
||||
{"group:wood", "default:cobble", "group:wood"},
|
||||
{"default:cobble", "default:steel_ingot", "default:cobble"},
|
||||
{"group:wood", "default:cobble", "group:wood"}
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("more_chests:cobble", cobble)
|
||||
minetest.register_craft({
|
||||
output = "more_chests:cobble",
|
||||
recipe = cobble.recipe,
|
||||
})
|
45
models/dropbox.lua
Normal file
45
models/dropbox.lua
Normal file
@ -0,0 +1,45 @@
|
||||
local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua")
|
||||
local actions = dofile(minetest.get_modpath("more_chests") .. "/utils/actions.lua")
|
||||
local S = minetest.get_translator("more_chests")
|
||||
|
||||
local dropbox = gen_def({
|
||||
description = S("Dropbox"),
|
||||
type = "dropbox",
|
||||
size = "small",
|
||||
tiles = {
|
||||
top = "dropbox_top.png",
|
||||
side = "dropbox_side.png",
|
||||
front = "dropbox_front.png"
|
||||
},
|
||||
pipeworks_enabled = true,
|
||||
recipe = {
|
||||
{"group:wood", "", "group:wood"},
|
||||
{"group:wood", "default:steel_ingot", "group:wood"},
|
||||
{"group:wood", "group:wood", "group:wood"}
|
||||
},
|
||||
allow_metadata_inventory_move = false,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if actions.has_locked_chest_privilege(meta, player) then
|
||||
return stack:get_count()
|
||||
end
|
||||
local target = meta:get_inventory():get_list(listname)[index]
|
||||
local target_name = target:get_name()
|
||||
local stack_count = stack:get_count()
|
||||
if target_name == stack:get_name()
|
||||
and target:get_count() < stack_count then
|
||||
return stack_count
|
||||
end
|
||||
if target_name ~= "" then
|
||||
return 0
|
||||
end
|
||||
return stack_count
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("more_chests:dropbox", dropbox)
|
||||
minetest.register_craft({
|
||||
output = "more_chests:dropbox",
|
||||
recipe = dropbox.recipe,
|
||||
})
|
50
models/fridge.lua
Normal file
50
models/fridge.lua
Normal file
@ -0,0 +1,50 @@
|
||||
local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua")
|
||||
local S = minetest.get_translator("more_chests")
|
||||
|
||||
-- TODO model open
|
||||
|
||||
local fridge = gen_def({
|
||||
description = S("Fridge"),
|
||||
type = "fridge",
|
||||
size = "small",
|
||||
tiles = {
|
||||
side = "fridge_side.png",
|
||||
front = "fridge_front.png",
|
||||
},
|
||||
recipe = {
|
||||
{"", "default:steel_ingot", ""},
|
||||
{"default:steel_ingot", "default:ice", "default:steel_ingot"},
|
||||
{"", "default:steel_ingot", ""}
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node("more_chests:fridge", fridge)
|
||||
minetest.register_craft({
|
||||
output = "more_chests:fridge",
|
||||
recipe = fridge.recipe,
|
||||
})
|
||||
|
||||
|
||||
local big_fridge = gen_def({
|
||||
description = S("Big Fridge"),
|
||||
type = "fridge",
|
||||
size = "big",
|
||||
node_box = {
|
||||
{-0.5, -0.5, -0.5, 0.5, 1.5, 0.5},
|
||||
},
|
||||
tiles = {
|
||||
side = "fridge_side.png",
|
||||
front = "fridge_front.png",
|
||||
},
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:ice", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node("more_chests:big_fridge", big_fridge)
|
||||
minetest.register_craft({
|
||||
output = "more_chests:big_fridge",
|
||||
recipe = big_fridge.recipe,
|
||||
})
|
54
models/secret.lua
Normal file
54
models/secret.lua
Normal file
@ -0,0 +1,54 @@
|
||||
local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua")
|
||||
local actions = dofile(minetest.get_modpath("more_chests") .. "/utils/actions.lua")
|
||||
local S = minetest.get_translator("more_chests")
|
||||
|
||||
local open = "size[8,10]"..
|
||||
default.gui_bg ..
|
||||
default.gui_bg_img ..
|
||||
default.gui_slots ..
|
||||
"list[current_name;main;0,0.3;8,4;]" ..
|
||||
"list[current_player;main;0,4.85;8,1;]" ..
|
||||
"list[current_player;main;0,6.08;8,3;8]" ..
|
||||
"listring[current_name;main]" ..
|
||||
"listring[current_player;main]" ..
|
||||
"button[3,9;2,1;open;close]" ..
|
||||
default.get_hotbar_bg(0,4.85)
|
||||
|
||||
local closed = "size[2,1]" ..
|
||||
"button[0,0;2,1;open;open]"
|
||||
|
||||
local secret = gen_def({
|
||||
description = S("Secret Chest"),
|
||||
type = "secret chest",
|
||||
size = "small",
|
||||
tiles = {
|
||||
top = "secret_top.png",
|
||||
side = "secret_side.png",
|
||||
front = "secret_front.png"
|
||||
},
|
||||
formspec = open,
|
||||
pipeworks_enabled = true,
|
||||
recipe = {
|
||||
{"group:wood", "default:cobble", "group:wood"},
|
||||
{"group:wood", "default:steel_ingot", "group:wood"},
|
||||
{"group:wood", "group:wood", "group:wood"}
|
||||
},
|
||||
})
|
||||
|
||||
secret.on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if actions.has_locked_chest_privilege(meta, sender) then
|
||||
if fields.open == "open" then
|
||||
meta:set_string("formspec", open)
|
||||
else
|
||||
meta:set_string("formspec", closed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("more_chests:secret", secret)
|
||||
minetest.register_craft({
|
||||
output = "more_chests:secret",
|
||||
recipe = secret.recipe,
|
||||
})
|
72
models/shared.lua
Normal file
72
models/shared.lua
Normal file
@ -0,0 +1,72 @@
|
||||
local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua")
|
||||
local actions = dofile(minetest.get_modpath("more_chests") .. "/utils/actions.lua")
|
||||
local S = minetest.get_translator("more_chests")
|
||||
|
||||
local function get_formspec(string)
|
||||
return "size[8,10]" ..
|
||||
default.gui_bg ..
|
||||
default.gui_bg_img ..
|
||||
default.gui_slots ..
|
||||
"list[current_name;main;0,0.3;8,4;]" ..
|
||||
"list[current_player;main;0,4.85;8,1;]" ..
|
||||
"list[current_player;main;0,6;8,3;8]" ..
|
||||
"field[.25,9.5;8,1;shared;" ..
|
||||
S("Shared with (separate names with spaces)") ..
|
||||
":;" .. string .. "]" ..
|
||||
"button[6,9.2;2,1;submit;" ..
|
||||
S("submit") .. "]" ..
|
||||
"listring[current_name;main]" ..
|
||||
"listring[current_player;main]" ..
|
||||
default.get_hotbar_bg(0,4.85)
|
||||
end
|
||||
|
||||
local function check_privs(meta, player)
|
||||
local name = player:get_player_name()
|
||||
local shared = " " .. meta:get_string("shared") .. " "
|
||||
if name == meta:get_string("owner") then
|
||||
return true
|
||||
elseif shared:find(" " .. name .. " ") then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local shared = gen_def({
|
||||
description = S("Shared Chest"),
|
||||
type = "shared chest",
|
||||
size = "small",
|
||||
tiles = {
|
||||
top = "shared_top.png",
|
||||
side = "shared_side.png",
|
||||
front = "shared_front.png"
|
||||
},
|
||||
formspec = get_formspec(""),
|
||||
pipeworks_enabled = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
recipe = {
|
||||
{"group:wood", "default:leaves", "group:wood"},
|
||||
{"group:wood", "default:steel_ingot", "group:wood"},
|
||||
{"group:wood", "group:wood", "group:wood"}
|
||||
},
|
||||
allow_metadata_inventory_move = actions.get_allow_metadata_inventory_move{"shared chest", check_privs=check_privs},
|
||||
allow_metadata_inventory_put = actions.get_allow_metadata_inventory_put{"shared chest", check_privs=check_privs},
|
||||
allow_metadata_inventory_take = actions.get_allow_metadata_inventory_take{"shared chest", check_privs=check_privs},
|
||||
})
|
||||
|
||||
shared.on_receive_fields = function(pos, formspec, fields, sender)
|
||||
local meta = minetest.get_meta(pos);
|
||||
if fields.shared then
|
||||
if meta:get_string("owner") == sender:get_player_name() then
|
||||
meta:set_string("shared", fields.shared)
|
||||
meta:set_string("formspec", get_formspec(fields.shared))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("more_chests:shared", shared)
|
||||
minetest.register_craft({
|
||||
output = "more_chests:shared",
|
||||
recipe = shared.recipe,
|
||||
})
|
34
models/toolbox.lua
Normal file
34
models/toolbox.lua
Normal file
@ -0,0 +1,34 @@
|
||||
local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua")
|
||||
local S = minetest.get_translator("more_chests")
|
||||
|
||||
local function register_toolbox(description, type, side_tile, recipe)
|
||||
local def = gen_def({
|
||||
description = description,
|
||||
type = "toolbox",
|
||||
size = "big",
|
||||
-- node_box = {-0.5, -0.5, -0.5, 1.5, 0.5, 0.5}, -- makes it two blocks wide
|
||||
tiles = {
|
||||
side = side_tile,
|
||||
front = "toolbox_" .. type .. "_front.png",
|
||||
top = "toolbox_" .. type .. "_top.png",
|
||||
},
|
||||
recipe = recipe,
|
||||
})
|
||||
minetest.register_node("more_chests:toolbox_" .. type, def)
|
||||
end
|
||||
|
||||
local function gen_recipe(craft_item)
|
||||
return {
|
||||
{craft_item, craft_item, craft_item},
|
||||
{craft_item, "group:pickaxe", craft_item},
|
||||
{craft_item, craft_item, craft_item}
|
||||
}
|
||||
end
|
||||
|
||||
register_toolbox(S("Wooden Toolbox"), "wood", "default_wood.png", gen_recipe("default:wood"))
|
||||
register_toolbox(S("Aspen Wood Toolbox"), "aspen", "default_aspen_wood.png", gen_recipe("default:aspen_wood"))
|
||||
register_toolbox(S("Acacia Wood Toolbox"), "acacia", "default_acacia_wood.png", gen_recipe("default:acacia_wood"))
|
||||
register_toolbox(S("Junglewood Toolbox"), "jungle", "default_junglewood.png", gen_recipe("default:junglewood"))
|
||||
register_toolbox(S("Pine Wood Toolbox"), "pine", "default_pine_wood.png", gen_recipe("default:pine_wood"))
|
||||
|
||||
register_toolbox(S("Steel Toolbox"), "steel", "default_steel_block.png", gen_recipe("default:steel_ingot"))
|
34
models/wifi.lua
Normal file
34
models/wifi.lua
Normal file
@ -0,0 +1,34 @@
|
||||
local gen_def = dofile(minetest.get_modpath("more_chests") .. "/utils/base.lua")
|
||||
local S = minetest.get_translator("more_chests")
|
||||
|
||||
local wifi = gen_def({
|
||||
description = S("Wifi Chest"),
|
||||
type = "wifi chest",
|
||||
size = "small",
|
||||
tiles = {
|
||||
top = "wifi_top.png",
|
||||
side = "wifi_side.png",
|
||||
front = "wifi_front.png"
|
||||
},
|
||||
recipe = {
|
||||
{"group:wood", "default:mese", "group:wood"},
|
||||
{"group:wood", "default:steel_ingot", "group:wood"},
|
||||
{"group:wood", "group:wood", "group:wood"}
|
||||
},
|
||||
allow_metadata_inventory_move = false,
|
||||
allow_metadata_inventory_put = false,
|
||||
allow_metadata_inventory_take = false,
|
||||
})
|
||||
|
||||
wifi.can_dig = function(pos, player) return true end
|
||||
|
||||
minetest.register_node("more_chests:wifi", wifi)
|
||||
minetest.register_craft({
|
||||
output = "more_chests:wifi",
|
||||
recipe = wifi.recipe,
|
||||
})
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local inv = player:get_inventory()
|
||||
inv:set_size("more_chests:wifi", 8*4)
|
||||
end)
|
Reference in New Issue
Block a user