mirror of
https://notabug.org/TenPlus1/protector.git
synced 2025-01-22 19:51:29 +01:00
Added chest management buttons and ability to name chest
This commit is contained in:
parent
ad35ab04cf
commit
d7b19bac50
16
README.md
16
README.md
@ -1,9 +1,15 @@
|
|||||||
minetest-protect
|
Protector Redo mod [protect]
|
||||||
================
|
|
||||||
|
|
||||||
Protector mod for minetest
|
Protector redo mod for minetest is based on glomie's mod, remade by Zeg9 and reworked by TenPlus1 to support minetest 0.4.9 and include protected doors and chests
|
||||||
based on glomie's mod, remade by Zeg9 and reworked by TenPlus1 to support minetest 0.4.9 and include protected doors and chests
|
|
||||||
|
|
||||||
https://forum.minetest.net/viewtopic.php?f=11&t=9376
|
https://forum.minetest.net/viewtopic.php?f=11&t=9376
|
||||||
|
|
||||||
Released under WTFPL
|
Released under WTFPL
|
||||||
|
|
||||||
|
0.1 - Initial release
|
||||||
|
0.2 - Texture update
|
||||||
|
0.3 - Added Protection Logo to blend in with player builds
|
||||||
|
0.4 - Code tweak for 0.4.10+
|
||||||
|
0.5 - Added protector.radius variable in init.lua (default: 5)
|
||||||
|
0.6 - Added Protected Doors (wood and steel) and Protected Chest
|
||||||
|
0.7 - Protected Chests now have "To Chest" and "To Inventory" buttons to copy contents across, also chests can be named
|
||||||
|
128
init.lua
128
init.lua
@ -44,18 +44,17 @@ end
|
|||||||
-- Protector Interface
|
-- Protector Interface
|
||||||
|
|
||||||
protector.generate_formspec = function(meta)
|
protector.generate_formspec = function(meta)
|
||||||
if meta:get_int("page") == nil then meta:set_int("page",0) end
|
|
||||||
local formspec = "size[8,7]"..default.gui_bg..default.gui_bg_img..default.gui_slots -- Added new formspec defaults
|
local formspec = "size[8,7]"..default.gui_bg..default.gui_bg_img..default.gui_slots
|
||||||
.."label[2.5,0;-- Protector interface --]"
|
.."label[2.5,0;-- Protector interface --]"
|
||||||
.."label[0,1;Punch node to show protected area]"
|
.."label[0,1;PUNCH node to show protected area or USE for area check]"
|
||||||
.."label[0,2;Members: (type nick, press Enter to add)]"
|
.."label[0,2;Members: (type player name then press Enter to add)]"
|
||||||
|
|
||||||
local members = protector.get_member_list(meta)
|
local members = protector.get_member_list(meta)
|
||||||
|
|
||||||
local npp = 12
|
local npp = 12
|
||||||
local s = 0
|
|
||||||
local i = 0
|
local i = 0
|
||||||
|
|
||||||
for _, member in ipairs(members) do
|
for _, member in ipairs(members) do
|
||||||
if s < meta:get_int("page")*15 then s = s +1 else
|
|
||||||
if i < npp then
|
if i < npp then
|
||||||
formspec = formspec .. "button["..(i%4*2)..","
|
formspec = formspec .. "button["..(i%4*2)..","
|
||||||
..math.floor(i/4+3)..";1.5,.5;protector_member;"..member.."]"
|
..math.floor(i/4+3)..";1.5,.5;protector_member;"..member.."]"
|
||||||
@ -63,14 +62,15 @@ protector.generate_formspec = function(meta)
|
|||||||
..math.floor(i/4+3)..";.75,.5;protector_del_member_"..member..";X]"
|
..math.floor(i/4+3)..";.75,.5;protector_del_member_"..member..";X]"
|
||||||
end
|
end
|
||||||
i = i +1
|
i = i +1
|
||||||
end
|
|
||||||
end
|
end
|
||||||
local add_i = i
|
|
||||||
if add_i < npp then
|
if i < npp then
|
||||||
formspec = formspec
|
formspec = formspec
|
||||||
.."field["..(add_i%4*2+1/3)..","..(math.floor(add_i/4+3)+1/3)..";1.433,.5;protector_add_member;;]"
|
.."field["..(i%4*2+1/3)..","..(math.floor(i/4+3)+1/3)..";1.433,.5;protector_add_member;;]"
|
||||||
end
|
end
|
||||||
formspec = formspec.."button_exit[1,6.2;2,0.5;close_me;<< Back]"
|
|
||||||
|
formspec = formspec.."button_exit[2.5,6.2;3,0.5;close_me;Close]"
|
||||||
|
|
||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -189,8 +189,7 @@ minetest.register_node("protector:protect", {
|
|||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
local meta = minetest.env:get_meta(pos)
|
local meta = minetest.env:get_meta(pos)
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
meta:set_string("owner", placer:get_player_name() or "")
|
||||||
meta:set_string("infotext", "Protection (owned by "..
|
meta:set_string("infotext", "Protection (owned by "..meta:get_string("owner")..")")
|
||||||
meta:get_string("owner")..")")
|
|
||||||
meta:set_string("members", "")
|
meta:set_string("members", "")
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -206,8 +205,7 @@ minetest.register_node("protector:protect", {
|
|||||||
local meta = minetest.env:get_meta(pos)
|
local meta = minetest.env:get_meta(pos)
|
||||||
if protector.can_dig(1,pos,clicker:get_player_name(),true,1) then
|
if protector.can_dig(1,pos,clicker:get_player_name(),true,1) then
|
||||||
minetest.show_formspec(clicker:get_player_name(),
|
minetest.show_formspec(clicker:get_player_name(),
|
||||||
"protector_"..minetest.pos_to_string(pos), protector.generate_formspec(meta)
|
"protector:node_"..minetest.pos_to_string(pos), protector.generate_formspec(meta))
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -265,8 +263,7 @@ minetest.register_node("protector:protect2", {
|
|||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
local meta = minetest.env:get_meta(pos)
|
local meta = minetest.env:get_meta(pos)
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
meta:set_string("owner", placer:get_player_name() or "")
|
||||||
meta:set_string("infotext", "Protection (owned by "..
|
meta:set_string("infotext", "Protection (owned by "..meta:get_string("owner")..")")
|
||||||
meta:get_string("owner")..")")
|
|
||||||
meta:set_string("members", "")
|
meta:set_string("members", "")
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -282,8 +279,7 @@ minetest.register_node("protector:protect2", {
|
|||||||
local meta = minetest.env:get_meta(pos)
|
local meta = minetest.env:get_meta(pos)
|
||||||
if protector.can_dig(1,pos,clicker:get_player_name(),true,1) then
|
if protector.can_dig(1,pos,clicker:get_player_name(),true,1) then
|
||||||
minetest.show_formspec(clicker:get_player_name(),
|
minetest.show_formspec(clicker:get_player_name(),
|
||||||
"protector_"..minetest.pos_to_string(pos), protector.generate_formspec(meta)
|
"protector:node_"..minetest.pos_to_string(pos), protector.generate_formspec(meta))
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -315,16 +311,15 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
-- If name entered into protector formspec
|
-- If name entered or button press
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player,formname,fields)
|
minetest.register_on_player_receive_fields(function(player,formname,fields)
|
||||||
if string.sub(formname,0,string.len("protector_")) == "protector_" then
|
|
||||||
local pos_s = string.sub(formname,string.len("protector_")+1)
|
if string.sub(formname,0,string.len("protector:node_")) == "protector:node_" then
|
||||||
|
|
||||||
|
local pos_s = string.sub(formname,string.len("protector:node_")+1)
|
||||||
local pos = minetest.string_to_pos(pos_s)
|
local pos = minetest.string_to_pos(pos_s)
|
||||||
local meta = minetest.env:get_meta(pos)
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
|
||||||
if meta:get_int("page") == nil then meta:set_int("page",0) end
|
|
||||||
|
|
||||||
if not protector.can_dig(1,pos,player:get_player_name(),true,1) then
|
if not protector.can_dig(1,pos,player:get_player_name(),true,1) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -340,12 +335,13 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
|
|||||||
protector.del_member(meta, string.sub(field,string.len("protector_del_member_")+1))
|
protector.del_member(meta, string.sub(field,string.len("protector_del_member_")+1))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.close_me then
|
if not fields.close_me then
|
||||||
meta:set_int("page",meta:get_int("page"))
|
minetest.show_formspec(player:get_player_name(), formname, protector.generate_formspec(meta))
|
||||||
else minetest.show_formspec(player:get_player_name(), formname, protector.generate_formspec(meta))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_entity("protector:display", {
|
minetest.register_entity("protector:display", {
|
||||||
@ -555,13 +551,17 @@ local function get_locked_chest_formspec(pos)
|
|||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
"list[nodemeta:".. spos .. ";main;0,0.3;8,4;]"..
|
"list[nodemeta:".. spos .. ";main;0,0.3;8,4;]"..
|
||||||
"list[current_player;main;0,4.85;8,1;]"..
|
"button[0,4.5;2,0.25;toup;To Chest]"..
|
||||||
|
"field[2.3,4.8;4,0.25;chestname;;]"..
|
||||||
|
"button[6,4.5;2,0.25;todn;To Inventory]"..
|
||||||
|
"list[current_player;main;0,5;8,1;]"..
|
||||||
"list[current_player;main;0,6.08;8,3;8]"..
|
"list[current_player;main;0,6.08;8,3;8]"..
|
||||||
default.get_hotbar_bg(0,4.85)
|
default.get_hotbar_bg(0,5)
|
||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Protected Chest
|
-- Protected Chest
|
||||||
|
|
||||||
minetest.register_node("protector:chest", {
|
minetest.register_node("protector:chest", {
|
||||||
description = "Protected Chest",
|
description = "Protected Chest",
|
||||||
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
|
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
|
||||||
@ -608,13 +608,68 @@ minetest.register_node("protector:chest", {
|
|||||||
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
||||||
minetest.show_formspec(
|
minetest.show_formspec(
|
||||||
clicker:get_player_name(),
|
clicker:get_player_name(),
|
||||||
"default:chest_locked",
|
"protector:chest_"..minetest.pos_to_string(pos),
|
||||||
get_locked_chest_formspec(pos)
|
get_locked_chest_formspec(pos)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Proteted Chest formspec buttons
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player,formname,fields)
|
||||||
|
|
||||||
|
if string.sub(formname,0,string.len("protector:chest_")) == "protector:chest_" then
|
||||||
|
|
||||||
|
local pos_s = string.sub(formname,string.len("protector:chest_")+1)
|
||||||
|
local pos = minetest.string_to_pos(pos_s)
|
||||||
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
|
||||||
|
local chest_inv = meta:get_inventory()
|
||||||
|
local player_inv = player:get_inventory()
|
||||||
|
|
||||||
|
if fields.toup then
|
||||||
|
|
||||||
|
-- copy contents of players inventory to chest
|
||||||
|
for i,v in ipairs( player_inv:get_list( "main" ) or {}) do
|
||||||
|
if( chest_inv and chest_inv:room_for_item('main', v)) then
|
||||||
|
local leftover = chest_inv:add_item( 'main', v )
|
||||||
|
player_inv:remove_item( "main", v )
|
||||||
|
if( leftover and not( leftover:is_empty() )) then
|
||||||
|
player_inv:add_item( "main", v )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif fields.todn then
|
||||||
|
|
||||||
|
-- copy contents of chest to players inventory
|
||||||
|
for i,v in ipairs( chest_inv:get_list( 'main' ) or {}) do
|
||||||
|
if( player_inv:room_for_item( "main", v)) then
|
||||||
|
local leftover = player_inv:add_item( "main", v )
|
||||||
|
chest_inv:remove_item( 'main', v )
|
||||||
|
if( leftover and not( leftover:is_empty() )) then
|
||||||
|
chest_inv:add_item( 'main', v )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif fields.chestname then
|
||||||
|
|
||||||
|
-- change chest infotext to display name
|
||||||
|
if fields.chestname ~= "" then
|
||||||
|
meta:set_string("infotext", "Protected Chest ("..fields.chestname..")")
|
||||||
|
else
|
||||||
|
meta:set_string("infotext", "Protected Chest")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Protected Chest recipe
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'protector:chest',
|
output = 'protector:chest',
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -623,3 +678,10 @@ minetest.register_craft({
|
|||||||
{'group:wood', 'group:wood', 'group:wood'},
|
{'group:wood', 'group:wood', 'group:wood'},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = 'protector:chest',
|
||||||
|
recipe = {
|
||||||
|
{'default:chest', 'default:copper_ingot', ''},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user