Rewrite chests
@ -1,77 +0,0 @@
|
|||||||
chest_groups1 = {snappy=2,choppy=2,oddly_breakable_by_hand=2,tubedevice=1,tubedevice_receiver=1}
|
|
||||||
chest_groups2 = {snappy=2,choppy=2,oddly_breakable_by_hand=2,tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1}
|
|
||||||
|
|
||||||
tubes_properties = {insert_object=function(pos,node,stack,direction)
|
|
||||||
local meta=minetest.env:get_meta(pos)
|
|
||||||
local inv=meta:get_inventory()
|
|
||||||
return inv:add_item("main",stack)
|
|
||||||
end,
|
|
||||||
can_insert=function(pos,node,stack,direction)
|
|
||||||
local meta=minetest.env:get_meta(pos)
|
|
||||||
local inv=meta:get_inventory()
|
|
||||||
return inv:room_for_item("main",stack)
|
|
||||||
end,
|
|
||||||
input_inventory="main",
|
|
||||||
connect_sides = {left=1, right=1, front=1, back=1, top=1, bottom=1},
|
|
||||||
}
|
|
||||||
|
|
||||||
chest_can_dig = function(pos,player)
|
|
||||||
local meta = minetest.env:get_meta(pos);
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
return inv:is_empty("main")
|
|
||||||
end
|
|
||||||
|
|
||||||
def_allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
if not has_locked_chest_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked chest belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return count
|
|
||||||
end
|
|
||||||
|
|
||||||
def_allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
if not has_locked_chest_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked chest belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return stack:get_count()
|
|
||||||
end
|
|
||||||
|
|
||||||
def_allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
if not has_locked_chest_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked chest belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return stack:get_count()
|
|
||||||
end
|
|
||||||
|
|
||||||
def_on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff in locked chest at "..minetest.pos_to_string(pos))
|
|
||||||
end
|
|
||||||
|
|
||||||
def_on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff to locked chest at "..minetest.pos_to_string(pos))
|
|
||||||
end
|
|
||||||
|
|
||||||
def_on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" takes stuff from locked chest at "..minetest.pos_to_string(pos))
|
|
||||||
end
|
|
||||||
|
|
||||||
function has_locked_chest_privilege(meta, player)
|
|
||||||
return player:get_player_name() == meta:get_string("owner")
|
|
||||||
end
|
|
71
technic_chests/common.lua
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
technic.chests.groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
|
||||||
|
tubedevice=1, tubedevice_receiver=1}
|
||||||
|
technic.chests.groups_noinv = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
|
||||||
|
tubedevice=1, tubedevice_receiver=1, not_in_creative_inventory=1}
|
||||||
|
|
||||||
|
technic.chests.tube = {
|
||||||
|
insert_object = function(pos, node, stack, direction)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:add_item("main",stack)
|
||||||
|
end,
|
||||||
|
can_insert = function(pos, node, stack, direction)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:room_for_item("main",stack)
|
||||||
|
end,
|
||||||
|
input_inventory = "main",
|
||||||
|
connect_sides = {left=1, right=1, front=1, back=1, top=1, bottom=1},
|
||||||
|
}
|
||||||
|
|
||||||
|
technic.chests.can_dig = function(pos, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:is_empty("main")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function inv_change(pos, count, player)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if not has_locked_chest_privilege(meta, player) then
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" tried to access a locked chest belonging to "..
|
||||||
|
meta:get_string("owner").." at "..
|
||||||
|
minetest.pos_to_string(pos))
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
|
function technic.chests.inv_move(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
return inv_change(pos, count, player)
|
||||||
|
end
|
||||||
|
function technic.chests.inv_put(pos, listname, index, stack, player)
|
||||||
|
return inv_change(pos, count, player)
|
||||||
|
end
|
||||||
|
function technic.chests.inv_take(pos, listname, index, stack, player)
|
||||||
|
return inv_change(pos, count, player)
|
||||||
|
end
|
||||||
|
|
||||||
|
function technic.chests.on_inv_move(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" moves stuff in locked chest at "
|
||||||
|
..minetest.pos_to_string(pos))
|
||||||
|
end
|
||||||
|
|
||||||
|
function technic.chests.on_inv_put(pos, listname, index, stack, player)
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" puts stuff in to locked chest at "
|
||||||
|
..minetest.pos_to_string(pos))
|
||||||
|
end
|
||||||
|
|
||||||
|
function technic.chests.on_inv_take(pos, listname, index, stack, player)
|
||||||
|
minetest.log("action", player:get_player_name()..
|
||||||
|
" takes stuff from locked chest at "
|
||||||
|
..minetest.pos_to_string(pos))
|
||||||
|
end
|
||||||
|
|
||||||
|
function has_locked_chest_privilege(meta, player)
|
||||||
|
return player:get_player_name() == meta:get_string("owner")
|
||||||
|
end
|
||||||
|
|
@ -24,80 +24,17 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craftitem(":technic:copper_chest", {
|
technic.chests:register("Copper", {
|
||||||
description = "Copper Chest",
|
width = 10,
|
||||||
stack_max = 99,
|
infotext = false,
|
||||||
})
|
color = false,
|
||||||
minetest.register_craftitem(":technic:copper_locked_chest", {
|
locked = false,
|
||||||
description = "Copper Locked Chest",
|
|
||||||
stack_max = 99,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(":technic:copper_chest", {
|
technic.chests:register("Copper", {
|
||||||
description = "Copper Chest",
|
width = 10,
|
||||||
tiles = {"technic_copper_chest_top.png", "technic_copper_chest_top.png", "technic_copper_chest_side.png",
|
infotext = false,
|
||||||
"technic_copper_chest_side.png", "technic_copper_chest_side.png", "technic_copper_chest_front.png"},
|
color = false,
|
||||||
paramtype2 = "facedir",
|
locked = true,
|
||||||
groups = chest_groups1,
|
|
||||||
tube = tubes_properties,legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",
|
|
||||||
"invsize[10,10;]"..
|
|
||||||
"label[0,0;Copper Chest]"..
|
|
||||||
"list[current_name;main;0,1;10,4;]"..
|
|
||||||
"list[current_player;main;0,6;8,4;]"..
|
|
||||||
"background[-0.19,-0.25;10.4,10.75;ui_form_bg.png]"..
|
|
||||||
"background[0,1;10,4;ui_copper_chest_inventory.png]"..
|
|
||||||
"background[0,6;8,4;ui_main_inventory.png]")
|
|
||||||
meta:set_string("infotext", "Copper Chest")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 10*4)
|
|
||||||
end,
|
|
||||||
|
|
||||||
can_dig = chest_can_dig,
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(":technic:copper_locked_chest", {
|
|
||||||
description = "Copper Locked Chest",
|
|
||||||
tiles = {"technic_copper_chest_top.png", "technic_copper_chest_top.png", "technic_copper_chest_side.png",
|
|
||||||
"technic_copper_chest_side.png", "technic_copper_chest_side.png", "technic_copper_chest_locked.png"},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = chest_groups1,
|
|
||||||
tube = tubes_properties,legacy_facedir_simple = true,
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
|
||||||
meta:set_string("infotext", "Copper Locked Chest (owned by "..
|
|
||||||
meta:get_string("owner")..")")
|
|
||||||
end,
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",
|
|
||||||
"invsize[10,10;]"..
|
|
||||||
"label[0,0;Copper Locked Chest]"..
|
|
||||||
"list[current_name;main;0,1;10,4;]"..
|
|
||||||
"list[current_player;main;0,6;8,4;]"..
|
|
||||||
"background[-0.19,-0.25;10.4,10.75;ui_form_bg.png]"..
|
|
||||||
"background[0,1;10,4;ui_copper_chest_inventory.png]"..
|
|
||||||
"background[0,6;8,4;ui_main_inventory.png]")
|
|
||||||
meta:set_string("infotext", "Copper Locked Chest")
|
|
||||||
meta:set_string("owner", "")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 10*4)
|
|
||||||
end,
|
|
||||||
|
|
||||||
can_dig = chest_can_dig,
|
|
||||||
allow_metadata_inventory_move = def_allow_metadata_inventory_move,
|
|
||||||
allow_metadata_inventory_put = def_allow_metadata_inventory_put,
|
|
||||||
allow_metadata_inventory_take = def_allow_metadata_inventory_take,
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
default
|
default
|
||||||
|
technic
|
||||||
moreores
|
moreores
|
||||||
pipeworks
|
pipeworks
|
||||||
|
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
local chest_mark_colors = {
|
local chest_mark_colors = {
|
||||||
{'_black','Black'},
|
'Black',
|
||||||
{'_blue','Blue'},
|
'Blue',
|
||||||
{'_brown','Brown'},
|
'Brown',
|
||||||
{'_cyan','Cyan'},
|
'Cyan',
|
||||||
{'_dark_green','Dark Green'},
|
'Dark Green',
|
||||||
{'_dark_grey','Dark Grey'},
|
'Dark Grey',
|
||||||
{'_green','Green'},
|
'Green',
|
||||||
{'_grey','Grey'},
|
'Grey',
|
||||||
{'_magenta','Magenta'},
|
'Magenta',
|
||||||
{'_orange','Orange'},
|
'Orange',
|
||||||
{'_pink','Pink'},
|
'Pink',
|
||||||
{'_red','Red'},
|
'Red',
|
||||||
{'_violet','Violet'},
|
'Violet',
|
||||||
{'_white','White'},
|
'White',
|
||||||
{'_yellow','Yellow'},
|
'Yellow',
|
||||||
{'','None'}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
@ -43,245 +42,17 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craftitem(":technic:gold_chest", {
|
technic.chests:register("Gold", {
|
||||||
description = "Gold Chest",
|
width = 12,
|
||||||
stack_max = 99,
|
infotext = true,
|
||||||
})
|
color = true,
|
||||||
minetest.register_craftitem(":technic:gold_locked_chest", {
|
locked = false,
|
||||||
description = "Gold Locked Chest",
|
|
||||||
stack_max = 99,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function get_pallette_buttons ()
|
technic.chests:register("Gold", {
|
||||||
local buttons_string=""
|
width = 12,
|
||||||
for y=0,3,1 do
|
infotext = true,
|
||||||
for x=0,3,1 do
|
color = true,
|
||||||
local file_name="ui_colorbutton"..(y*4+x)..".png"
|
locked = true,
|
||||||
buttons_string=buttons_string.."image_button["..(9.2+x*.7)..","..(6+y*.7)..";.81,.81;"..file_name..";color_button"..(y*4+x)..";]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return buttons_string
|
|
||||||
end
|
|
||||||
|
|
||||||
gold_chest_formspec = "invsize[12,10;]"..
|
|
||||||
"list[current_name;main;0,1;12,4;]"..
|
|
||||||
"list[current_player;main;0,6;8,4;]"..
|
|
||||||
"background[-0.19,-0.25;12.4,10.75;ui_form_bg.png]"..
|
|
||||||
"background[0,1;12,4;ui_gold_chest_inventory.png]"..
|
|
||||||
"background[0,6;8,4;ui_main_inventory.png]"..
|
|
||||||
get_pallette_buttons ()
|
|
||||||
|
|
||||||
gold_chest_inv_size = 12*4
|
|
||||||
|
|
||||||
minetest.register_node(":technic:gold_chest", {
|
|
||||||
description = "Gold Chest",
|
|
||||||
tiles = {"technic_gold_chest_top.png", "technic_gold_chest_top.png", "technic_gold_chest_side.png",
|
|
||||||
"technic_gold_chest_side.png", "technic_gold_chest_side.png", "technic_gold_chest_front.png"},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = chest_groups1,
|
|
||||||
tube = tubes_properties,
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",gold_chest_formspec..
|
|
||||||
"label[0,0;Gold Chest]"..
|
|
||||||
"image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]"..
|
|
||||||
"label[9.2,9;Color Filter: None")
|
|
||||||
meta:set_string("infotext", "Gold Chest")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", gold_chest_inv_size)
|
|
||||||
end,
|
|
||||||
|
|
||||||
can_dig = chest_can_dig,
|
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
local page="main"
|
|
||||||
if fields.edit_infotext then
|
|
||||||
page="edit_infotext"
|
|
||||||
end
|
|
||||||
if fields.save_infotext then
|
|
||||||
meta:set_string("infotext",fields.infotext_box)
|
|
||||||
end
|
|
||||||
local formspec = gold_chest_formspec.."label[0,0;Gold Chest]"
|
|
||||||
if page=="main" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]"
|
|
||||||
formspec = formspec.."label[4,0;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
if page=="edit_infotext" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;ok_icon.png;save_infotext;]"
|
|
||||||
formspec = formspec.."field[4.3,.2;6,1;infotext_box;Edit chest description:;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
formspec = formspec .. "label[9.2,9;Color Filter: "..chest_mark_colors[check_color_buttons (pos,"technic:gold_chest",fields)][2].."]"
|
|
||||||
meta:set_string("formspec",formspec)
|
|
||||||
end,
|
|
||||||
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for i=1,15,1 do
|
|
||||||
minetest.register_node(":technic:gold_chest".. chest_mark_colors[i][1], {
|
|
||||||
description = "Gold Chest",
|
|
||||||
tiles = {"technic_gold_chest_top.png", "technic_gold_chest_top.png", "technic_gold_chest_side.png",
|
|
||||||
"technic_gold_chest_side.png", "technic_gold_chest_side.png", "technic_gold_chest_front"..chest_mark_colors[i][1]..".png"},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = chest_groups2,
|
|
||||||
tube = tubes_properties,
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
drop = "technic:gold_chest",
|
|
||||||
can_dig =chest_can_dig,
|
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
local page="main"
|
|
||||||
if fields.edit_infotext then
|
|
||||||
page="edit_infotext"
|
|
||||||
end
|
|
||||||
if fields.save_infotext then
|
|
||||||
meta:set_string("infotext",fields.infotext_box)
|
|
||||||
end
|
|
||||||
local formspec = gold_chest_formspec.."label[0,0;Gold Chest]"
|
|
||||||
if page=="main" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]"
|
|
||||||
formspec = formspec.."label[4,0;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
if page=="edit_infotext" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;ok_icon.png;save_infotext;]"
|
|
||||||
formspec = formspec.."field[4.3,.2;6,1;infotext_box;Edit chest description:;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
formspec = formspec .. "label[9.2,9;Color Filter: "..chest_mark_colors[check_color_buttons (pos,"technic:gold_chest",fields)][2].."]"
|
|
||||||
meta:set_string("formspec",formspec)
|
|
||||||
end,
|
|
||||||
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_node(":technic:gold_locked_chest", {
|
|
||||||
description = "Gold Locked Chest",
|
|
||||||
tiles = {"technic_gold_chest_top.png", "technic_gold_chest_top.png", "technic_gold_chest_side.png",
|
|
||||||
"technic_gold_chest_side.png", "technic_gold_chest_side.png", "technic_gold_chest_locked.png"},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
drop = "technic:gold_locked_chest",
|
|
||||||
groups = chest_groups1,
|
|
||||||
tube = tubes_properties,
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
|
||||||
meta:set_string("infotext", "Gold Locked Chest (owned by "..
|
|
||||||
meta:get_string("owner")..")")
|
|
||||||
end,
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",
|
|
||||||
gold_chest_formspec..
|
|
||||||
"label[0,0;Gold Locked Chest]"..
|
|
||||||
"image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]"..
|
|
||||||
"label[9.2,9;Color Filter: None")
|
|
||||||
meta:set_string("owner", "")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", gold_chest_inv_size)
|
|
||||||
end,
|
|
||||||
|
|
||||||
can_dig =chest_can_dig,
|
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
local formspec = gold_chest_formspec..
|
|
||||||
"label[0,0;Gold Locked Chest]"
|
|
||||||
local page="main"
|
|
||||||
if fields.edit_infotext then
|
|
||||||
page="edit_infotext"
|
|
||||||
end
|
|
||||||
if fields.save_infotext then
|
|
||||||
meta:set_string("infotext",fields.infotext_box)
|
|
||||||
end
|
|
||||||
if page=="main" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]"
|
|
||||||
formspec = formspec.."label[4,0;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
if page=="edit_infotext" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;ok_icon.png;save_infotext;]"
|
|
||||||
formspec = formspec.."field[4.3,.2;6,1;infotext_box;Edit chest description:;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
formspec = formspec .. "label[9.2,9;Color Filter: "..chest_mark_colors[check_color_buttons (pos,"technic:gold_locked_chest",fields)][2].."]"
|
|
||||||
meta:set_string("formspec",formspec)
|
|
||||||
end,
|
|
||||||
|
|
||||||
allow_metadata_inventory_move = def_allow_metadata_inventory_move,
|
|
||||||
allow_metadata_inventory_put = def_allow_metadata_inventory_put,
|
|
||||||
allow_metadata_inventory_take = def_allow_metadata_inventory_take,
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
|
||||||
|
|
||||||
for i=1,15,1 do
|
|
||||||
minetest.register_node(":technic:gold_locked_chest".. chest_mark_colors[i][1], {
|
|
||||||
description = "Gold Locked Chest",
|
|
||||||
tiles = {"technic_gold_chest_top.png", "technic_gold_chest_top.png", "technic_gold_chest_side.png",
|
|
||||||
"technic_gold_chest_side.png", "technic_gold_chest_side.png", "technic_gold_chest_locked"..chest_mark_colors[i][1]..".png"},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
drop = "technic:gold_locked_chest",
|
|
||||||
groups = chest_groups2,
|
|
||||||
tube = tubes_properties,
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
can_dig = chest_can_dig,
|
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
local formspec = gold_chest_formspec..
|
|
||||||
"label[0,0;Gold Locked Chest]"
|
|
||||||
local page="main"
|
|
||||||
if fields.edit_infotext then
|
|
||||||
page="edit_infotext"
|
|
||||||
end
|
|
||||||
if fields.save_infotext then
|
|
||||||
meta:set_string("infotext",fields.infotext_box)
|
|
||||||
end
|
|
||||||
if page=="main" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]"
|
|
||||||
formspec = formspec.."label[4,0;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
if page=="edit_infotext" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;ok_icon.png;save_infotext;]"
|
|
||||||
formspec = formspec.."field[4.3,.2;6,1;infotext_box;Edit chest description:;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
formspec = formspec .. "label[9.2,9;Color Filter: "..chest_mark_colors[check_color_buttons (pos,"technic:gold_locked_chest",fields)][2].."]"
|
|
||||||
meta:set_string("formspec",formspec)
|
|
||||||
end,
|
|
||||||
|
|
||||||
allow_metadata_inventory_move = def_allow_metadata_inventory_move,
|
|
||||||
allow_metadata_inventory_put = def_allow_metadata_inventory_put,
|
|
||||||
allow_metadata_inventory_take = def_allow_metadata_inventory_take,
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
function check_color_buttons (pos,chest_name,fields)
|
|
||||||
if fields.color_button15 then
|
|
||||||
hacky_swap_node(pos,chest_name)
|
|
||||||
return 16
|
|
||||||
end
|
|
||||||
for i=0,14,1 do
|
|
||||||
local button="color_button"..i
|
|
||||||
if fields[button] then
|
|
||||||
hacky_swap_node(pos,chest_name..chest_mark_colors[i+1][1])
|
|
||||||
return i+1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return 16
|
|
||||||
end
|
|
||||||
|
|
||||||
|
@ -2,12 +2,15 @@
|
|||||||
-- namespace: technic
|
-- namespace: technic
|
||||||
-- (c) 2012-2013 by RealBadAngel <mk@realbadangel.pl>
|
-- (c) 2012-2013 by RealBadAngel <mk@realbadangel.pl>
|
||||||
|
|
||||||
modpath=minetest.get_modpath("technic_chests")
|
modpath = minetest.get_modpath("technic_chests")
|
||||||
|
|
||||||
-- chests
|
technic.chests = {}
|
||||||
dofile(modpath.."/chest_commons.lua")
|
|
||||||
|
dofile(modpath.."/common.lua")
|
||||||
|
dofile(modpath.."/register.lua")
|
||||||
dofile(modpath.."/iron_chest.lua")
|
dofile(modpath.."/iron_chest.lua")
|
||||||
dofile(modpath.."/copper_chest.lua")
|
dofile(modpath.."/copper_chest.lua")
|
||||||
dofile(modpath.."/silver_chest.lua")
|
dofile(modpath.."/silver_chest.lua")
|
||||||
dofile(modpath.."/gold_chest.lua")
|
dofile(modpath.."/gold_chest.lua")
|
||||||
dofile(modpath.."/mithril_chest.lua")
|
dofile(modpath.."/mithril_chest.lua")
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'technic:iron_chest 1',
|
output = 'technic:iron_chest 1',
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -24,80 +25,17 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
technic.chests:register("Iron", {
|
||||||
minetest.register_craftitem(":technic:iron_chest", {
|
width = 9,
|
||||||
description = "Iron Chest",
|
infotext = false,
|
||||||
stack_max = 99,
|
color = false,
|
||||||
})
|
locked = false,
|
||||||
minetest.register_craftitem(":technic:iron_locked_chest", {
|
|
||||||
description = "Iron Locked Chest",
|
|
||||||
stack_max = 99,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(":technic:iron_chest", {
|
technic.chests:register("Iron", {
|
||||||
description = "Iron Chest",
|
width = 9,
|
||||||
tiles = {"technic_iron_chest_top.png", "technic_iron_chest_top.png", "technic_iron_chest_side.png",
|
infotext = false,
|
||||||
"technic_iron_chest_side.png", "technic_iron_chest_side.png", "technic_iron_chest_front.png"},
|
color = false,
|
||||||
paramtype2 = "facedir",
|
locked = true,
|
||||||
groups = chest_groups1,
|
|
||||||
tube = tubes_properties,
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",
|
|
||||||
"invsize[9,10;]"..
|
|
||||||
"label[0,0;Iron Chest]"..
|
|
||||||
"list[current_name;main;0,1;9,4;]"..
|
|
||||||
"list[current_player;main;0,6;8,4;]"..
|
|
||||||
"background[-0.19,-0.25;9.4,10.75;ui_form_bg.png]"..
|
|
||||||
"background[0,1;9,4;ui_iron_chest_inventory.png]"..
|
|
||||||
"background[0,6;8,4;ui_main_inventory.png]")
|
|
||||||
meta:set_string("infotext", "Iron Chest")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 9*4)
|
|
||||||
end,
|
|
||||||
can_dig = chest_can_dig,
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(":technic:iron_locked_chest", {
|
|
||||||
description = "Iron Locked Chest",
|
|
||||||
tiles = {"technic_iron_chest_top.png", "technic_iron_chest_top.png", "technic_iron_chest_side.png",
|
|
||||||
"technic_iron_chest_side.png", "technic_iron_chest_side.png", "technic_iron_chest_locked.png"},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = chest_groups1,
|
|
||||||
tube = tubes_properties,
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
|
||||||
meta:set_string("infotext", "Locked Iron Chest (owned by "..
|
|
||||||
meta:get_string("owner")..")")
|
|
||||||
end,
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",
|
|
||||||
"invsize[9,10;]"..
|
|
||||||
"label[0,0;Iron Locked Chest]"..
|
|
||||||
"list[current_name;main;0,1;9,4;]"..
|
|
||||||
"list[current_player;main;0,6;8,4;]"..
|
|
||||||
"background[-0.19,-0.25;9.4,10.75;ui_form_bg.png]"..
|
|
||||||
"background[0,1;9,4;ui_iron_chest_inventory.png]"..
|
|
||||||
"background[0,6;8,4;ui_main_inventory.png]")
|
|
||||||
meta:set_string("infotext", "Iron Locked Chest")
|
|
||||||
meta:set_string("owner", "")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 9*4)
|
|
||||||
end,
|
|
||||||
can_dig = chest_can_dig,
|
|
||||||
allow_metadata_inventory_move = def_allow_metadata_inventory_move,
|
|
||||||
allow_metadata_inventory_put = def_allow_metadata_inventory_put,
|
|
||||||
allow_metadata_inventory_take = def_allow_metadata_inventory_take,
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
|
||||||
|
@ -24,130 +24,17 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(":technic:mithril_chest", {
|
technic.chests:register("Mithril", {
|
||||||
description = "Mithril Chest",
|
width = 13,
|
||||||
tiles = {"technic_mithril_chest_top.png", "technic_mithril_chest_top.png", "technic_mithril_chest_side.png",
|
infotext = false,
|
||||||
"technic_mithril_chest_side.png", "technic_mithril_chest_side.png", "technic_mithril_chest_front.png"},
|
color = false,
|
||||||
paramtype2 = "facedir",
|
locked = false,
|
||||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",
|
|
||||||
"invsize[13,10;]"..
|
|
||||||
"label[0,0;Mithril Chest]"..
|
|
||||||
"list[current_name;main;0,1;13,4;]"..
|
|
||||||
"list[current_player;main;0,6;8,4;]"..
|
|
||||||
"background[-0.19,-0.25;13.4,10.75;ui_form_bg.png]"..
|
|
||||||
"background[0,1;13,4;ui_mithril_chest_inventory.png]"..
|
|
||||||
"background[0,6;8,4;ui_main_inventory.png]")
|
|
||||||
meta:set_string("infotext", "Mithril Chest")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 13*4)
|
|
||||||
end,
|
|
||||||
can_dig = function(pos,player)
|
|
||||||
local meta = minetest.env:get_meta(pos);
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
return inv:is_empty("main")
|
|
||||||
end,
|
|
||||||
|
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index,
|
|
||||||
to_list, to_index, count, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff in chest at "..minetest.pos_to_string(pos))
|
|
||||||
return minetest.node_metadata_inventory_move_allow_all(
|
|
||||||
pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_offer = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff to chest at "..minetest.pos_to_string(pos))
|
|
||||||
return minetest.node_metadata_inventory_offer_allow_all(
|
|
||||||
pos, listname, index, stack, player)
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" takes stuff from chest at "..minetest.pos_to_string(pos))
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(":technic:mithril_locked_chest", {
|
technic.chests:register("Mithril", {
|
||||||
description = "Mithril Locked Chest",
|
width = 13,
|
||||||
tiles = {"technic_mithril_chest_top.png", "technic_mithril_chest_top.png", "technic_mithril_chest_side.png",
|
infotext = false,
|
||||||
"technic_mithril_chest_side.png", "technic_mithril_chest_side.png", "technic_mithril_chest_locked.png"},
|
color = false,
|
||||||
paramtype2 = "facedir",
|
locked = true,
|
||||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
|
||||||
meta:set_string("infotext", "Mithril Locked Chest (owned by "..
|
|
||||||
meta:get_string("owner")..")")
|
|
||||||
end,
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",
|
|
||||||
"invsize[13,10;]"..
|
|
||||||
"label[0,0;Mithril Locked Chest]"..
|
|
||||||
"list[current_name;main;0,1;13,4;]"..
|
|
||||||
"list[current_player;main;0,6;8,4;]"..
|
|
||||||
"background[-0.19,-0.25;13.4,10.75;ui_form_bg.png]"..
|
|
||||||
"background[0,1;13,4;ui_mithril_chest_inventory.png]"..
|
|
||||||
"background[0,6;8,4;ui_main_inventory.png]")
|
|
||||||
meta:set_string("infotext", "Mithril Locked Chest")
|
|
||||||
meta:set_string("owner", "")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 13*4)
|
|
||||||
end,
|
|
||||||
can_dig = function(pos,player)
|
|
||||||
local meta = minetest.env:get_meta(pos);
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
return inv:is_empty("main")
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
if not has_locked_chest_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked chest belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return count
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
if not has_locked_chest_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked chest belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return stack:get_count()
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
if not has_locked_chest_privilege(meta, player) then
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" tried to access a locked chest belonging to "..
|
|
||||||
meta:get_string("owner").." at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return stack:get_count()
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff in locked chest at "..minetest.pos_to_string(pos))
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" moves stuff to locked chest at "..minetest.pos_to_string(pos))
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
minetest.log("action", player:get_player_name()..
|
|
||||||
" takes stuff from locked chest at "..minetest.pos_to_string(pos))
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
175
technic_chests/register.lua
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
|
||||||
|
local chest_mark_colors = {
|
||||||
|
'Black',
|
||||||
|
'Blue',
|
||||||
|
'Brown',
|
||||||
|
'Cyan',
|
||||||
|
'Dark Green',
|
||||||
|
'Dark Grey',
|
||||||
|
'Green',
|
||||||
|
'Grey',
|
||||||
|
'Magenta',
|
||||||
|
'Orange',
|
||||||
|
'Pink',
|
||||||
|
'Red',
|
||||||
|
'Violet',
|
||||||
|
'White',
|
||||||
|
'Yellow',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local function colorid_to_postfix(id)
|
||||||
|
return (chest_mark_colors[id] and "_"..chest_mark_colors[id] or ""):lower():gsub(" ", "_")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function get_color_buttons()
|
||||||
|
local buttons_string = ""
|
||||||
|
for y = 0, 3 do
|
||||||
|
for x = 0, 3 do
|
||||||
|
local file_name = "technic_colorbutton"..(y * 4 + x)..".png"
|
||||||
|
buttons_string = buttons_string.."image_button["
|
||||||
|
..(8.1 + x * 0.7)..","..(6.1 + y * 0.7)
|
||||||
|
..";0.8,0.8;"..file_name..";color_button"
|
||||||
|
..(y * 4 + x + 1)..";]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return buttons_string
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function check_color_buttons(pos, meta, chest_name, fields)
|
||||||
|
for i = 1, 16 do
|
||||||
|
if fields["color_button"..i] then
|
||||||
|
technic.swap_node(pos, chest_name..colorid_to_postfix(i))
|
||||||
|
meta:set_string("color", chest_mark_colors[i])
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function get_receive_fields(name, data)
|
||||||
|
if not data.infotext and not data.color then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local lname = name:lower()
|
||||||
|
return function(pos, formname, fields, sender)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
local page = "main"
|
||||||
|
if fields.edit_infotext then
|
||||||
|
page = "edit_infotext"
|
||||||
|
end
|
||||||
|
if fields.save_infotext then
|
||||||
|
meta:set_string("infotext", fields.infotext_box)
|
||||||
|
end
|
||||||
|
local formspec = data.formspec
|
||||||
|
local formspec_infotext = minetest.formspec_escape(meta:get_string("infotext"))
|
||||||
|
if page == "main" and data.infotext then
|
||||||
|
formspec = formspec.."image_button[2.1,0.1;0.8,0.8;"
|
||||||
|
.."technic_pencil_icon.png;edit_infotext;]"
|
||||||
|
.."label[3,0;"..formspec_infotext.."]"
|
||||||
|
end
|
||||||
|
if page == "edit_infotext" then
|
||||||
|
formspec = formspec.."image_button[2.1,0.1;0.8,0.8;"
|
||||||
|
.."technic_checkmark_icon.png;save_infotext;]"
|
||||||
|
.."field[3.3,0.2;4.8,1;"
|
||||||
|
.."infotext_box;Edit chest description:;"
|
||||||
|
..formspec_infotext.."]"
|
||||||
|
end
|
||||||
|
if data.color then
|
||||||
|
-- This sets the node
|
||||||
|
local nn = "technic:"..lname..(data.locked and "_locked" or "").."_chest"
|
||||||
|
check_color_buttons(pos, meta, nn, fields)
|
||||||
|
local color = meta:get_string("color")
|
||||||
|
formspec = formspec.."label[8.2,9;Color Filter: "..color.."]"
|
||||||
|
end
|
||||||
|
meta:set_string("formspec", formspec)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function technic.chests:register(name, data)
|
||||||
|
local lname = name:lower()
|
||||||
|
|
||||||
|
local width = math.max(data.color and 11 or 8, data.width)
|
||||||
|
|
||||||
|
local locked_after_place = nil
|
||||||
|
local front = {"technic_"..lname.."_chest_front.png"}
|
||||||
|
data.formspec = "invsize["..width..",10;]"..
|
||||||
|
"label[0,0;"..name.." Chest]"..
|
||||||
|
"list[current_name;main;0,1;"..width..",4;]"..
|
||||||
|
"list[current_player;main;0,6;8,4;]"..
|
||||||
|
"background[-0.19,-0.25;"..width..".4,10.75;ui_form_bg.png]"..
|
||||||
|
"background[0,1;"..width..",4;technic_"..lname.."_chest_inventory.png]"..
|
||||||
|
"background[0,6;8,4;ui_main_inventory.png]"
|
||||||
|
if data.color then
|
||||||
|
data.formspec = data.formspec..get_color_buttons()
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.locked then
|
||||||
|
locked_after_place = function(pos, placer)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("owner", placer:get_player_name() or "")
|
||||||
|
meta:set_string("infotext", name.." Locked Chest (owned by "..
|
||||||
|
meta:get_string("owner")..")")
|
||||||
|
end
|
||||||
|
table.insert(front, "technic_"..lname.."_chest_lock_overlay.png")
|
||||||
|
end
|
||||||
|
|
||||||
|
local def = {
|
||||||
|
description = name..(data.locked and " Locked" or "").." Chest",
|
||||||
|
tiles = {"technic_"..lname.."_chest_top.png", "technic_"..lname.."_chest_top.png",
|
||||||
|
"technic_"..lname.."_chest_side.png", "technic_"..lname.."_chest_side.png",
|
||||||
|
"technic_"..lname.."_chest_side.png", table.concat(front, "^")},
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
groups = self.groups,
|
||||||
|
tube = self.tube,
|
||||||
|
legacy_facedir_simple = true,
|
||||||
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
after_place_node = locked_after_place,
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("formspec", data.formspec
|
||||||
|
..(data.color and "label[8.2,9;Color Filter: None" or "")
|
||||||
|
..(data.infotext and "image_button[2.1,0.1;0.8,0.8;"
|
||||||
|
.."technic_pencil_icon.png;edit_infotext;]" or ""))
|
||||||
|
meta:set_string("infotext", name.." Chest")
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
inv:set_size("main", data.width * 4)
|
||||||
|
end,
|
||||||
|
can_dig = self.can_dig,
|
||||||
|
on_receive_fields = get_receive_fields(name, data),
|
||||||
|
on_metadata_inventory_move = self.on_inv_move,
|
||||||
|
on_metadata_inventory_put = self.on_inv_put,
|
||||||
|
on_metadata_inventory_take = self.on_inv_take,
|
||||||
|
}
|
||||||
|
if data.locked then
|
||||||
|
def.allow_metadata_inventory_move = self.inv_move
|
||||||
|
def.allow_metadata_inventory_put = self.inv_put
|
||||||
|
def.allow_metadata_inventory_take = self.inv_take
|
||||||
|
end
|
||||||
|
|
||||||
|
local nn = "technic:"..lname..(data.locked and "_locked" or "").."_chest"
|
||||||
|
|
||||||
|
minetest.register_node(":"..nn, def)
|
||||||
|
|
||||||
|
if data.color then
|
||||||
|
front[3] = front[2]
|
||||||
|
for i = 1, 15 do
|
||||||
|
local postfix = colorid_to_postfix(i)
|
||||||
|
local colordef = {}
|
||||||
|
for k, v in pairs(def) do
|
||||||
|
colordef[k] = v
|
||||||
|
end
|
||||||
|
colordef.drop = nn
|
||||||
|
colordef.groups = self.groups_noinv
|
||||||
|
front[2] = "technic_chest_overlay"..postfix..".png"
|
||||||
|
colordef.tiles[6] = table.concat(front, "^")
|
||||||
|
minetest.register_node(":"..nn..postfix, colordef)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -24,122 +24,17 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craftitem(":technic:silver_chest", {
|
technic.chests:register("Silver", {
|
||||||
description = "Silver Chest",
|
width = 11,
|
||||||
stack_max = 99,
|
infotext = true,
|
||||||
})
|
color = false,
|
||||||
minetest.register_craftitem(":technic:silver_locked_chest", {
|
locked = false,
|
||||||
description = "Silver Locked Chest",
|
|
||||||
stack_max = 99,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
silver_chest_formspec =
|
technic.chests:register("Silver", {
|
||||||
"invsize[11,10;]"..
|
width = 11,
|
||||||
"list[current_name;main;0,1;11,4;]"..
|
infotext = true,
|
||||||
"list[current_player;main;0,6;8,4;]"..
|
color = false,
|
||||||
"background[-0.19,-0.25;11.4,10.75;ui_form_bg.png]"..
|
locked = true,
|
||||||
"background[0,1;11,4;ui_silver_chest_inventory.png]"..
|
|
||||||
"background[0,6;8,4;ui_main_inventory.png]"
|
|
||||||
|
|
||||||
minetest.register_node(":technic:silver_chest", {
|
|
||||||
description = "Silver Chest",
|
|
||||||
tiles = {"technic_silver_chest_top.png", "technic_silver_chest_top.png", "technic_silver_chest_side.png",
|
|
||||||
"technic_silver_chest_side.png", "technic_silver_chest_side.png", "technic_silver_chest_front.png"},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = chest_groups1,
|
|
||||||
tube = tubes_properties,
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",
|
|
||||||
silver_chest_formspec..
|
|
||||||
"label[0,0;Silver Chest]"..
|
|
||||||
"image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]")
|
|
||||||
meta:set_string("infotext", "Silver Chest")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 11*4)
|
|
||||||
end,
|
|
||||||
can_dig = chest_can_dig,
|
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
local page="main"
|
|
||||||
if fields.edit_infotext then
|
|
||||||
page="edit_infotext"
|
|
||||||
end
|
|
||||||
if fields.save_infotext then
|
|
||||||
meta:set_string("infotext",fields.infotext_box)
|
|
||||||
end
|
|
||||||
local formspec = silver_chest_formspec.."label[0,0;Silver Chest]"
|
|
||||||
if page=="main" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]"
|
|
||||||
formspec = formspec.."label[4,0;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
if page=="edit_infotext" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;ok_icon.png;save_infotext;]"
|
|
||||||
formspec = formspec.."field[4.3,.2;6,1;infotext_box;Edit chest description:;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
meta:set_string("formspec",formspec)
|
|
||||||
end,
|
|
||||||
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(":technic:silver_locked_chest", {
|
|
||||||
description = "Silver Locked Chest",
|
|
||||||
tiles = {"technic_silver_chest_top.png", "technic_silver_chest_top.png", "technic_silver_chest_side.png",
|
|
||||||
"technic_silver_chest_side.png", "technic_silver_chest_side.png", "technic_silver_chest_locked.png"},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = chest_groups1,
|
|
||||||
tube = tubes_properties,
|
|
||||||
legacy_facedir_simple = true,
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
|
||||||
meta:set_string("infotext", "Silver Locked Chest (owned by "..
|
|
||||||
meta:get_string("owner")..")")
|
|
||||||
end,
|
|
||||||
on_construct = function(pos)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
meta:set_string("formspec",
|
|
||||||
silver_chest_formspec..
|
|
||||||
"label[0,0;Silver Locked Chest]"..
|
|
||||||
"image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]")
|
|
||||||
meta:set_string("owner", "")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 11*4)
|
|
||||||
end,
|
|
||||||
can_dig = chest_can_dig,
|
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
|
||||||
local meta = minetest.env:get_meta(pos)
|
|
||||||
local page="main"
|
|
||||||
if fields.edit_infotext then
|
|
||||||
page="edit_infotext"
|
|
||||||
end
|
|
||||||
if fields.save_infotext then
|
|
||||||
meta:set_string("infotext",fields.infotext_box)
|
|
||||||
end
|
|
||||||
local formspec = silver_chest_formspec.."label[0,0;Silver Locked Chest]"
|
|
||||||
if page=="main" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;pencil_icon.png;edit_infotext;]"
|
|
||||||
formspec = formspec.."label[4,0;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
if page=="edit_infotext" then
|
|
||||||
formspec = formspec.."image_button[3.5,.1;.6,.6;ok_icon.png;save_infotext;]"
|
|
||||||
formspec = formspec.."field[4.3,.2;6,1;infotext_box;Edit chest description:;"..meta:get_string("infotext").."]"
|
|
||||||
end
|
|
||||||
meta:set_string("formspec",formspec)
|
|
||||||
end,
|
|
||||||
|
|
||||||
allow_metadata_inventory_move = def_allow_metadata_inventory_move,
|
|
||||||
allow_metadata_inventory_put = def_allow_metadata_inventory_put,
|
|
||||||
allow_metadata_inventory_take = def_allow_metadata_inventory_take,
|
|
||||||
on_metadata_inventory_move = def_on_metadata_inventory_move,
|
|
||||||
on_metadata_inventory_put = def_on_metadata_inventory_put,
|
|
||||||
on_metadata_inventory_take = def_on_metadata_inventory_take
|
|
||||||
})
|
|
||||||
|
BIN
technic_chests/textures/technic_checkmark_icon.png
Normal file
After Width: | Height: | Size: 233 B |
BIN
technic_chests/textures/technic_chest_overlay_black.png
Normal file
After Width: | Height: | Size: 248 B |
BIN
technic_chests/textures/technic_chest_overlay_blue.png
Normal file
After Width: | Height: | Size: 257 B |
BIN
technic_chests/textures/technic_chest_overlay_brown.png
Normal file
After Width: | Height: | Size: 288 B |
BIN
technic_chests/textures/technic_chest_overlay_cyan.png
Normal file
After Width: | Height: | Size: 259 B |
BIN
technic_chests/textures/technic_chest_overlay_dark_green.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
technic_chests/textures/technic_chest_overlay_dark_grey.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
technic_chests/textures/technic_chest_overlay_green.png
Normal file
After Width: | Height: | Size: 278 B |
BIN
technic_chests/textures/technic_chest_overlay_grey.png
Normal file
After Width: | Height: | Size: 299 B |
BIN
technic_chests/textures/technic_chest_overlay_magenta.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
technic_chests/textures/technic_chest_overlay_orange.png
Normal file
After Width: | Height: | Size: 302 B |
BIN
technic_chests/textures/technic_chest_overlay_pink.png
Normal file
After Width: | Height: | Size: 304 B |
BIN
technic_chests/textures/technic_chest_overlay_red.png
Normal file
After Width: | Height: | Size: 262 B |
BIN
technic_chests/textures/technic_chest_overlay_violet.png
Normal file
After Width: | Height: | Size: 287 B |
BIN
technic_chests/textures/technic_chest_overlay_white.png
Normal file
After Width: | Height: | Size: 253 B |
BIN
technic_chests/textures/technic_chest_overlay_yellow.png
Normal file
After Width: | Height: | Size: 274 B |
BIN
technic_chests/textures/technic_colorbutton0.png
Normal file
After Width: | Height: | Size: 147 B |
BIN
technic_chests/textures/technic_colorbutton1.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton10.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton11.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton12.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton13.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton14.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton15.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
technic_chests/textures/technic_colorbutton2.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton3.png
Normal file
After Width: | Height: | Size: 140 B |
BIN
technic_chests/textures/technic_colorbutton4.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton5.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton6.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton7.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton8.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_colorbutton9.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
technic_chests/textures/technic_copper_chest_inventory.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
technic_chests/textures/technic_copper_chest_lock_overlay.png
Normal file
After Width: | Height: | Size: 160 B |
Before Width: | Height: | Size: 605 B |
Before Width: | Height: | Size: 778 B After Width: | Height: | Size: 687 B |
Before Width: | Height: | Size: 858 B |
Before Width: | Height: | Size: 866 B |
Before Width: | Height: | Size: 866 B |
Before Width: | Height: | Size: 855 B |
Before Width: | Height: | Size: 851 B |
Before Width: | Height: | Size: 846 B |
Before Width: | Height: | Size: 851 B |
Before Width: | Height: | Size: 831 B |
Before Width: | Height: | Size: 856 B |
Before Width: | Height: | Size: 844 B |
Before Width: | Height: | Size: 846 B |
Before Width: | Height: | Size: 848 B |
Before Width: | Height: | Size: 860 B |
Before Width: | Height: | Size: 857 B |
Before Width: | Height: | Size: 855 B |
BIN
technic_chests/textures/technic_gold_chest_inventory.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
technic_chests/textures/technic_gold_chest_lock_overlay.png
Normal file
After Width: | Height: | Size: 204 B |
Before Width: | Height: | Size: 778 B |
Before Width: | Height: | Size: 865 B |
Before Width: | Height: | Size: 864 B |
Before Width: | Height: | Size: 869 B |
Before Width: | Height: | Size: 851 B |
Before Width: | Height: | Size: 850 B |
Before Width: | Height: | Size: 847 B |
Before Width: | Height: | Size: 848 B |
Before Width: | Height: | Size: 830 B |
Before Width: | Height: | Size: 849 B |
Before Width: | Height: | Size: 843 B |
Before Width: | Height: | Size: 842 B |
Before Width: | Height: | Size: 843 B |
Before Width: | Height: | Size: 855 B |
Before Width: | Height: | Size: 858 B |
Before Width: | Height: | Size: 855 B |
BIN
technic_chests/textures/technic_iron_chest_inventory.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
technic_chests/textures/technic_iron_chest_lock_overlay.png
Normal file
After Width: | Height: | Size: 153 B |
Before Width: | Height: | Size: 905 B |
BIN
technic_chests/textures/technic_mithril_chest_inventory.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
technic_chests/textures/technic_mithril_chest_lock_overlay.png
Normal file
After Width: | Height: | Size: 155 B |
Before Width: | Height: | Size: 772 B |
BIN
technic_chests/textures/technic_pencil_icon.png
Normal file
After Width: | Height: | Size: 294 B |
BIN
technic_chests/textures/technic_silver_chest_inventory.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
technic_chests/textures/technic_silver_chest_lock_overlay.png
Normal file
After Width: | Height: | Size: 192 B |
Before Width: | Height: | Size: 852 B |
BIN
technic_chests/textures/technic_wooden_chest_inventory.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |