Rewrite chests

This commit is contained in:
ShadowNinja 2013-12-17 19:15:20 -05:00
parent c5d287f5f5
commit 78cacdcbc6
125 changed files with 321 additions and 719 deletions

View File

@ -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
View 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

View File

@ -24,80 +24,17 @@ minetest.register_craft({
}
})
minetest.register_craftitem(":technic:copper_chest", {
description = "Copper Chest",
stack_max = 99,
})
minetest.register_craftitem(":technic:copper_locked_chest", {
description = "Copper Locked Chest",
stack_max = 99,
technic.chests:register("Copper", {
width = 10,
infotext = false,
color = false,
locked = false,
})
minetest.register_node(":technic:copper_chest", {
description = "Copper 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_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",
"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
technic.chests:register("Copper", {
width = 10,
infotext = false,
color = false,
locked = true,
})
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
})

View File

@ -1,3 +1,5 @@
default
technic
moreores
pipeworks

View File

@ -1,20 +1,19 @@
local chest_mark_colors = {
{'_black','Black'},
{'_blue','Blue'},
{'_brown','Brown'},
{'_cyan','Cyan'},
{'_dark_green','Dark Green'},
{'_dark_grey','Dark Grey'},
{'_green','Green'},
{'_grey','Grey'},
{'_magenta','Magenta'},
{'_orange','Orange'},
{'_pink','Pink'},
{'_red','Red'},
{'_violet','Violet'},
{'_white','White'},
{'_yellow','Yellow'},
{'','None'}
'Black',
'Blue',
'Brown',
'Cyan',
'Dark Green',
'Dark Grey',
'Green',
'Grey',
'Magenta',
'Orange',
'Pink',
'Red',
'Violet',
'White',
'Yellow',
}
minetest.register_craft({
@ -43,245 +42,17 @@ minetest.register_craft({
}
})
minetest.register_craftitem(":technic:gold_chest", {
description = "Gold Chest",
stack_max = 99,
})
minetest.register_craftitem(":technic:gold_locked_chest", {
description = "Gold Locked Chest",
stack_max = 99,
technic.chests:register("Gold", {
width = 12,
infotext = true,
color = true,
locked = false,
})
function get_pallette_buttons ()
local buttons_string=""
for y=0,3,1 do
for x=0,3,1 do
local file_name="ui_colorbutton"..(y*4+x)..".png"
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
technic.chests:register("Gold", {
width = 12,
infotext = true,
color = true,
locked = true,
})
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

View File

@ -2,12 +2,15 @@
-- namespace: technic
-- (c) 2012-2013 by RealBadAngel <mk@realbadangel.pl>
modpath=minetest.get_modpath("technic_chests")
modpath = minetest.get_modpath("technic_chests")
-- chests
dofile(modpath.."/chest_commons.lua")
technic.chests = {}
dofile(modpath.."/common.lua")
dofile(modpath.."/register.lua")
dofile(modpath.."/iron_chest.lua")
dofile(modpath.."/copper_chest.lua")
dofile(modpath.."/silver_chest.lua")
dofile(modpath.."/gold_chest.lua")
dofile(modpath.."/mithril_chest.lua")

View File

@ -1,3 +1,4 @@
minetest.register_craft({
output = 'technic:iron_chest 1',
recipe = {
@ -24,80 +25,17 @@ minetest.register_craft({
}
})
minetest.register_craftitem(":technic:iron_chest", {
description = "Iron Chest",
stack_max = 99,
})
minetest.register_craftitem(":technic:iron_locked_chest", {
description = "Iron Locked Chest",
stack_max = 99,
technic.chests:register("Iron", {
width = 9,
infotext = false,
color = false,
locked = false,
})
minetest.register_node(":technic:iron_chest", {
description = "Iron 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_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",
"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
technic.chests:register("Iron", {
width = 9,
infotext = false,
color = false,
locked = true,
})
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
})

View File

@ -24,130 +24,17 @@ minetest.register_craft({
}
})
minetest.register_node(":technic:mithril_chest", {
description = "Mithril Chest",
tiles = {"technic_mithril_chest_top.png", "technic_mithril_chest_top.png", "technic_mithril_chest_side.png",
"technic_mithril_chest_side.png", "technic_mithril_chest_side.png", "technic_mithril_chest_front.png"},
paramtype2 = "facedir",
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,
technic.chests:register("Mithril", {
width = 13,
infotext = false,
color = false,
locked = false,
})
minetest.register_node(":technic:mithril_locked_chest", {
description = "Mithril Locked Chest",
tiles = {"technic_mithril_chest_top.png", "technic_mithril_chest_top.png", "technic_mithril_chest_side.png",
"technic_mithril_chest_side.png", "technic_mithril_chest_side.png", "technic_mithril_chest_locked.png"},
paramtype2 = "facedir",
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,
technic.chests:register("Mithril", {
width = 13,
infotext = false,
color = false,
locked = true,
})

175
technic_chests/register.lua Normal file
View 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

View File

@ -24,122 +24,17 @@ minetest.register_craft({
}
})
minetest.register_craftitem(":technic:silver_chest", {
description = "Silver Chest",
stack_max = 99,
})
minetest.register_craftitem(":technic:silver_locked_chest", {
description = "Silver Locked Chest",
stack_max = 99,
technic.chests:register("Silver", {
width = 11,
infotext = true,
color = false,
locked = false,
})
silver_chest_formspec =
"invsize[11,10;]"..
"list[current_name;main;0,1;11,4;]"..
"list[current_player;main;0,6;8,4;]"..
"background[-0.19,-0.25;11.4,10.75;ui_form_bg.png]"..
"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
technic.chests:register("Silver", {
width = 11,
infotext = true,
color = false,
locked = true,
})
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
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 605 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 778 B

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 866 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 866 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 855 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 831 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 856 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 848 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 855 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 865 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 869 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 847 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 848 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 830 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 849 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 855 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 855 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 905 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 772 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 852 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Some files were not shown because too many files have changed in this diff Show More