Compare commits

6 Commits

View File

@ -53,12 +53,12 @@ if( minetest.get_modpath( 'pipeworks' )) then
tubedevice = 1, tubedevice_receiver = 1 }; tubedevice = 1, tubedevice_receiver = 1 };
chesttools.chest_add.tube = { chesttools.chest_add.tube = {
insert_object = function(pos, node, stack, direction) insert_object = function(pos, node, stack, direction)
local meta = minetest.env:get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:add_item("main", stack) return inv:add_item("main", stack)
end, end,
can_insert = function(pos, node, stack, direction) can_insert = function(pos, node, stack, direction)
local meta = minetest.env:get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:room_for_item("main", stack) return inv:room_for_item("main", stack)
end, end,
@ -116,13 +116,16 @@ chesttools.on_receive_fields = function(pos, formname, fields, player)
local meta = minetest.get_meta( pos ); local meta = minetest.get_meta( pos );
local chestname = meta:get_string( 'chestname' ); local chestname = meta:get_string( 'chestname' );
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
if( fields.set_chestname and fields.chestname ) then if( fields.set_chestname and fields.chestname ) then
chestname = tostring( fields.chestname ); chestname = tostring( fields.chestname );
meta:set_string( 'chestname', chestname ); meta:set_string( 'chestname', chestname );
meta:set_string("infotext", "\""..chestname.."\" Chest (owned by "..meta:get_string("owner")..")") meta:set_string("infotext", "\""..chestname.."\" Chest (owned by "..meta:get_string("owner")..")")
-- update the normal formspec -- update the normal formspec
meta:set_string("formspec", chesttools.formspec.. meta:set_string("formspec", chesttools.formspec..
"field[1.8,10.0;6,0.5;chestname;;"..chestname.."]"); "listring[current_name;main]"..
"listring[current_player;main]"..
"field[1.8,10.0;6,0.5;chestname;;"..chestname.."]");
end end
local formspec = "size[9,10]".. local formspec = "size[9,10]"..
@ -133,7 +136,7 @@ chesttools.on_receive_fields = function(pos, formname, fields, player)
"button[7.0,4.5;0.5,0.5;drop_all;DA]".. "button[7.0,4.5;0.5,0.5;drop_all;DA]"..
"button[7.5,4.5;0.5,0.5;take_all;TA]".. "button[7.5,4.5;0.5,0.5;take_all;TA]"..
"button[8.0,4.5;0.5,0.5;swap_all;SA]".. "button[8.0,4.5;0.5,0.5;swap_all;SA]"..
"button[8.5,4.5;0.5,0.5;filter_all;FA]"; "button[8.5,4.5;0.5,0.5;filter_all;FA]"
local bm = "button[0.0,4.5;1,0.5;main;Main]"; local bm = "button[0.0,4.5;1,0.5;main;Main]";
local bc = "button[1.0,4.5;1,0.5;craft;Craft]"; local bc = "button[1.0,4.5;1,0.5;craft;Craft]";
local b1 = "button[2.0,4.5;1,0.5;bag1;Bag 1]"; local b1 = "button[2.0,4.5;1,0.5;bag1;Bag 1]";
@ -219,7 +222,9 @@ chesttools.on_receive_fields = function(pos, formname, fields, player)
if( fields[ 'main'] or selected=='main' or fields['set_chestname']) then if( fields[ 'main'] or selected=='main' or fields['set_chestname']) then
bag_nr = 0; bag_nr = 0;
formspec = formspec.. formspec = formspec..
"list[current_player;main;0.5,5.5;8,4;]"; "list[current_player;main;0.5,5.5;8,4;]"..
"listring[nodemeta:" .. spos .. ";main]"..
"listring[current_player;main]"
bm = "label[0.0,4.4;Main]"; bm = "label[0.0,4.4;Main]";
selected = 'main'; selected = 'main';
@ -228,7 +233,9 @@ chesttools.on_receive_fields = function(pos, formname, fields, player)
formspec = formspec.. formspec = formspec..
"label[0,5.5;Crafting]".. "label[0,5.5;Crafting]"..
"list[current_player;craftpreview;6.5,6.5;1,1;]".. "list[current_player;craftpreview;6.5,6.5;1,1;]"..
"list[current_player;craft;2.5,6.5;3,3;]"; "list[current_player;craft;2.5,6.5;3,3;]"..
"listring[nodemeta:" .. spos .. ";main]"..
"listring[current_player;craft]"
bc = "label[1.0,4.4;Craft]"; bc = "label[1.0,4.4;Craft]";
selected = 'craft'; selected = 'craft';
@ -258,10 +265,16 @@ chesttools.on_receive_fields = function(pos, formname, fields, player)
local pname_esc = minetest.formspec_escape(player:get_player_name()); local pname_esc = minetest.formspec_escape(player:get_player_name());
formspec = formspec.."list[detached:"..pname_esc.."_bags;bag".. formspec = formspec.."list[detached:"..pname_esc.."_bags;bag"..
tostring(bag_nr)..";1.5,5.5;1,1;]"; tostring(bag_nr)..";1.5,5.5;1,1;]";
local bag = minetest.get_inventory({type="detached", name=pname_esc.."_bags"},"bag"..tostring(bag_nr))
local slots = 4*8; local slots = 4*8;
if( slots and slots>0 ) then -- no bag present? if( bag and not(bag:get_stack("bag"..tostring(bag_nr),1):is_empty())) then -- no bag present?
formspec = formspec.. formspec = formspec..
"list[current_player;bag"..tostring(bag_nr).."contents;0.5,6.5;8,"..tostring(slots/8)..";]"; "list[current_player;bag"..tostring(bag_nr).."contents;0.5,6.5;8,"..tostring(slots/8)..";]"..
"listring[nodemeta:" .. spos .. ";main]"..
"listring[current_player;bag"..tostring(bag_nr).."contents]"
else
formspec = formspec..
"label[0.5,6.5;You have no bag in this slot.]"
end end
end end
end end
@ -366,7 +379,7 @@ chesttools.update_chest = function(pos, formname, fields, player)
local inv_size = inv:get_size("main"); local inv_size = inv:get_size("main");
for i=1, inv_size do for i=1, inv_size do
main_inv[ i ] = inv:get_stack( "main", i); main_inv[ i ] = inv:get_stack( "main", i);
print("Found: "..tostring( main_inv[ i ]:get_name())); -- print("Found: "..tostring( main_inv[ i ]:get_name()));
end end
-- actually change and initialize the new chest -- actually change and initialize the new chest
@ -413,8 +426,10 @@ chesttools.form_input_handler = function( player, formname, fields)
end end
if( formname == "chesttools:shared_chest") then if( formname == "chesttools:shared_chest") then
chesttools.on_receive_fields(pos, formname, fields, player); chesttools.on_receive_fields(pos, formname, fields, player);
return true; -- this function was responsible for handling the input
elseif( formname == "chesttools:update") then elseif( formname == "chesttools:update") then
chesttools.update_chest( pos, formname, fields, player); chesttools.update_chest( pos, formname, fields, player);
return true; -- this function was responsible for handling the input
end end
return; return;
@ -450,7 +465,8 @@ minetest.register_node( 'chesttools:shared_chest', {
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("main", 8*4) inv:set_size("main", 8*4)
meta:set_string("formspec", chesttools.formspec.. meta:set_string("formspec", chesttools.formspec..
"list[current_player;main;0.5,5.5;8,4;]"); "listring[current_name;main]"..
"listring[current_player;main]")
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
@ -512,7 +528,7 @@ minetest.register_node( 'chesttools:shared_chest', {
local name = user:get_player_name(); local name = user:get_player_name();
local pos = minetest.get_pointed_thing_position( pointed_thing, mode ); local pos = minetest.get_pointed_thing_position( pointed_thing, mode );
local node = minetest.env:get_node_or_nil( pos ); local node = minetest.get_node_or_nil( pos );
if( node == nil or not( node.name )) then if( node == nil or not( node.name )) then
return nil; return nil;