2017-01-27 13:42:05 +02:00
local function get_chest_neighborpos ( pos , param2 , side )
if side == " right " then
if param2 == 0 then
return { x = pos.x - 1 , y = pos.y , z = pos.z }
elseif param2 == 1 then
return { x = pos.x , y = pos.y , z = pos.z + 1 }
elseif param2 == 2 then
return { x = pos.x + 1 , y = pos.y , z = pos.z }
elseif param2 == 3 then
return { x = pos.x , y = pos.y , z = pos.z - 1 }
end
else
if param2 == 0 then
return { x = pos.x + 1 , y = pos.y , z = pos.z }
elseif param2 == 1 then
return { x = pos.x , y = pos.y , z = pos.z - 1 }
elseif param2 == 2 then
return { x = pos.x - 1 , y = pos.y , z = pos.z }
elseif param2 == 3 then
return { x = pos.x , y = pos.y , z = pos.z + 1 }
end
end
end
2017-03-16 05:23:21 +02:00
-- This is a helper function to register both chests and trapped chests. Trapped chests will make use of the additional parameters
2017-03-20 17:38:16 +02:00
local register_chest = function ( basename , desc , longdesc , usagehelp , hidden , mesecons , on_rightclick_addendum , on_rightclick_addendum_left , on_rightclick_addendum_right , drop )
2017-03-16 05:16:37 +02:00
if not drop then
drop = " mcl_chests: " .. basename
else
drop = " mcl_chests: " .. drop
end
2017-03-16 02:48:52 +02:00
minetest.register_node ( " mcl_chests: " .. basename , {
description = desc ,
_doc_items_longdesc = longdesc ,
_doc_items_usagehelp = usagehelp ,
2017-03-20 17:38:16 +02:00
_doc_items_hidden = hidden ,
2017-01-27 13:42:05 +02:00
tiles = { " default_chest_top.png " , " default_chest_top.png " , " default_chest_side.png " ,
" default_chest_side.png " , " default_chest_side.png " , " default_chest_front.png " } ,
paramtype2 = " facedir " ,
stack_max = 64 ,
2017-03-16 05:16:37 +02:00
drop = drop ,
2017-03-11 06:34:58 +02:00
groups = { handy = 1 , axey = 1 , container = 2 , deco_block = 1 , material_wood = 1 } ,
2017-01-27 13:42:05 +02:00
is_ground_content = false ,
2017-02-11 19:46:23 +02:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-01-27 13:42:05 +02:00
on_construct = function ( pos )
local param2 = minetest.get_node ( pos ) . param2
local meta = minetest.get_meta ( pos )
2017-06-09 23:47:59 +03:00
--[[ This is a workaround for Minetest issue 5894
< https : // github.com / minetest / minetest / issues / 5894 > .
Apparently if we don ' t do this, double chests initially don ' t work when
placed at chunk borders , and some chests randomly don ' t work after
placing . ] ]
-- FIXME: Remove this workaround when the bug has been fixed.
-- BEGIN OF WORKAROUND --
meta : set_string ( " workaround " , " ignore_me " )
meta : set_string ( " workaround " , nil ) -- Done to keep metadata clean
-- END OF WORKAROUND --
2017-03-29 21:06:14 +03:00
local inv = meta : get_inventory ( )
inv : set_size ( " main " , 9 * 3 )
2017-06-12 21:36:50 +03:00
--[[ The "input" list is *another* workaround (hahahaha!) around the fact that Minetest
does not support listrings to put items into an alternative list if the first one
happens to be full . See < https : // github.com / minetest / minetest / issues / 5343 > .
This list is a hidden input - only list and immediately puts items into the appropriate chest .
It is only used for listrings and hoppers . This workaround is not that bad because it only
requires a simple “ inventory allows ” check for large chests . ] ]
-- FIXME: Refactor the listrings as soon Minetest supports alternative listrings
-- BEGIN OF LISTRING WORKAROUND
inv : set_size ( " input " , 1 )
-- END OF LISTRING WORKAROUND
2017-03-16 02:48:52 +02:00
if minetest.get_node ( get_chest_neighborpos ( pos , param2 , " right " ) ) . name == " mcl_chests: " .. basename then
2017-03-29 21:06:14 +03:00
minetest.swap_node ( pos , { name = " mcl_chests: " .. basename .. " _right " , param2 = param2 } )
2017-01-27 13:42:05 +02:00
local p = get_chest_neighborpos ( pos , param2 , " right " )
2017-03-30 18:18:27 +03:00
minetest.swap_node ( p , { name = " mcl_chests: " .. basename .. " _left " , param2 = param2 } )
2017-03-16 02:48:52 +02:00
elseif minetest.get_node ( get_chest_neighborpos ( pos , param2 , " left " ) ) . name == " mcl_chests: " .. basename then
2017-03-29 21:06:14 +03:00
minetest.swap_node ( pos , { name = " mcl_chests: " .. basename .. " _left " , param2 = param2 } )
2017-01-27 13:42:05 +02:00
local p = get_chest_neighborpos ( pos , param2 , " left " )
2017-03-30 18:18:27 +03:00
minetest.swap_node ( p , { name = " mcl_chests: " .. basename .. " _right " , param2 = param2 } )
2017-01-27 13:42:05 +02:00
end
end ,
after_dig_node = function ( pos , oldnode , oldmetadata , digger )
local meta = minetest.get_meta ( pos )
local meta2 = meta
meta : from_table ( oldmetadata )
local inv = meta : get_inventory ( )
for i = 1 , inv : get_size ( " main " ) do
local stack = inv : get_stack ( " main " , i )
if not stack : is_empty ( ) then
local p = { x = pos.x + math.random ( 0 , 10 ) / 10 - 0.5 , y = pos.y , z = pos.z + math.random ( 0 , 10 ) / 10 - 0.5 }
minetest.add_item ( p , stack )
end
end
meta : from_table ( meta2 : to_table ( ) )
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 ) )
end ,
2017-03-16 02:48:52 +02:00
on_metadata_inventory_put = function ( pos , listname , index , stack , player )
2017-01-27 13:42:05 +02:00
minetest.log ( " action " , player : get_player_name ( ) ..
" moves stuff to chest at " .. minetest.pos_to_string ( pos ) )
2017-06-12 21:36:50 +03:00
-- BEGIN OF LISTRING WORKAROUND
if listname == " input " then
local inv = minetest.get_inventory ( { type = " node " , pos = pos } )
inv : add_item ( " main " , stack )
end
-- END OF LISTRING WORKAROUND
2017-01-27 13:42:05 +02:00
end ,
2017-03-16 02:48:52 +02:00
on_metadata_inventory_take = function ( pos , listname , index , stack , player )
2017-01-27 13:42:05 +02:00
minetest.log ( " action " , player : get_player_name ( ) ..
" takes stuff from chest at " .. minetest.pos_to_string ( pos ) )
end ,
2017-02-22 17:03:59 +02:00
_mcl_blast_resistance = 2.5 ,
2017-02-27 02:13:03 +02:00
_mcl_hardness = 2.5 ,
2017-03-16 03:13:35 +02:00
2017-03-16 05:16:37 +02:00
on_rightclick = function ( pos , node , clicker )
minetest.show_formspec ( clicker : get_player_name ( ) ,
" mcl_chests: " .. basename .. " _ " .. pos.x .. " _ " .. pos.y .. " _ " .. pos.z ,
" size[9,8.75] " ..
mcl_vars.inventory_header ..
2017-07-08 17:28:25 +03:00
" background[-0.19,-0.25;9.41,10.48;mcl_chests_inventory_chest.png] " ..
" image[0,-0.2;5,0.75;mcl_chests_fnt_chest.png] " ..
2017-03-16 05:16:37 +02:00
" list[nodemeta: " .. pos.x .. " , " .. pos.y .. " , " .. pos.z .. " ;main;0,0.5;9,3;] " ..
" list[current_player;main;0,4.5;9,3;9] " ..
" list[current_player;main;0,7.74;9,1;] " ..
" listring[nodemeta: " .. pos.x .. " , " .. pos.y .. " , " .. pos.z .. " ;main] " ..
" listring[current_player;main] " )
if on_rightclick_addendum then
on_rightclick_addendum ( pos , node , clicker )
end
end ,
2017-03-16 03:13:35 +02:00
mesecons = mesecons ,
2017-01-27 13:42:05 +02:00
} )
2017-03-16 02:48:52 +02:00
minetest.register_node ( " mcl_chests: " .. basename .. " _left " , {
2017-01-27 13:42:05 +02:00
tiles = { " default_chest_top_big.png " , " default_chest_top_big.png " , " default_chest_side.png " ,
" default_chest_side.png " , " default_chest_side_big.png^[transformFX " , " default_chest_front_big.png " } ,
paramtype2 = " facedir " ,
2017-03-11 06:34:58 +02:00
groups = { handy = 1 , axey = 1 , container = 2 , not_in_creative_inventory = 1 , material_wood = 1 } ,
2017-03-16 05:16:37 +02:00
drop = drop ,
2017-01-27 13:42:05 +02:00
is_ground_content = false ,
2017-02-11 19:46:23 +02:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-01-27 13:42:05 +02:00
on_destruct = function ( pos )
local n = minetest.get_node ( pos )
2017-03-16 02:48:52 +02:00
if n.name == " mcl_chests: " .. basename then
2017-01-27 13:42:05 +02:00
return
end
local param2 = n.param2
local p = get_chest_neighborpos ( pos , param2 , " left " )
2017-03-16 02:48:52 +02:00
if not p or minetest.get_node ( p ) . name ~= " mcl_chests: " .. basename .. " _right " then
2017-01-27 13:42:05 +02:00
return
end
2017-03-16 02:48:52 +02:00
minetest.swap_node ( p , { name = " mcl_chests: " .. basename , param2 = param2 } )
2017-01-27 13:42:05 +02:00
end ,
after_dig_node = function ( pos , oldnode , oldmetadata , digger )
local meta = minetest.get_meta ( pos )
local meta2 = meta
meta : from_table ( oldmetadata )
local inv = meta : get_inventory ( )
for i = 1 , inv : get_size ( " main " ) do
local stack = inv : get_stack ( " main " , i )
if not stack : is_empty ( ) then
local p = { x = pos.x + math.random ( 0 , 10 ) / 10 - 0.5 , y = pos.y , z = pos.z + math.random ( 0 , 10 ) / 10 - 0.5 }
minetest.add_item ( p , stack )
end
end
meta : from_table ( meta2 : to_table ( ) )
end ,
2017-06-12 21:36:50 +03:00
-- BEGIN OF LISTRING WORKAROUND
allow_metadata_inventory_put = function ( pos , listname , index , stack , player )
if listname == " input " then
local inv = minetest.get_inventory ( { type = " node " , pos = pos } )
if inv : room_for_item ( " main " , stack ) then
return - 1
else
local other_pos = get_chest_neighborpos ( pos , minetest.get_node ( pos ) . param2 , " left " )
local other_inv = minetest.get_inventory ( { type = " node " , pos = other_pos } )
if other_inv : room_for_item ( " main " , stack ) then
return - 1
else
return 0
end
end
else
return stack : get_count ( )
end
end ,
-- END OF LISTRING WORKAROUND
2017-01-27 13:42:05 +02:00
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 ) )
end ,
2017-03-16 02:48:52 +02:00
on_metadata_inventory_put = function ( pos , listname , index , stack , player )
2017-01-27 13:42:05 +02:00
minetest.log ( " action " , player : get_player_name ( ) ..
" moves stuff to chest at " .. minetest.pos_to_string ( pos ) )
2017-06-12 21:36:50 +03:00
-- BEGIN OF LISTRING WORKAROUND
if listname == " input " then
local inv = minetest.get_inventory ( { type = " node " , pos = pos } )
local leftover = inv : add_item ( " main " , stack )
if not leftover : is_empty ( ) then
local other_pos = get_chest_neighborpos ( pos , minetest.get_node ( pos ) . param2 , " left " )
local other_inv = minetest.get_inventory ( { type = " node " , pos = other_pos } )
2017-06-12 21:49:35 +03:00
other_inv : add_item ( " main " , leftover )
2017-06-12 21:36:50 +03:00
end
end
-- END OF LISTRING WORKAROUND
2017-01-27 13:42:05 +02:00
end ,
2017-03-16 02:48:52 +02:00
on_metadata_inventory_take = function ( pos , listname , index , stack , player )
2017-01-27 13:42:05 +02:00
minetest.log ( " action " , player : get_player_name ( ) ..
" takes stuff from chest at " .. minetest.pos_to_string ( pos ) )
end ,
2017-02-22 17:03:59 +02:00
_mcl_blast_resistance = 2.5 ,
2017-02-27 02:13:03 +02:00
_mcl_hardness = 2.5 ,
2017-03-16 03:13:35 +02:00
2017-03-16 05:16:37 +02:00
on_rightclick = function ( pos , node , clicker )
local pos_other = get_chest_neighborpos ( pos , node.param2 , " left " )
2017-03-16 03:13:35 +02:00
2017-03-16 05:16:37 +02:00
minetest.show_formspec ( clicker : get_player_name ( ) ,
" mcl_chests: " .. basename .. " _ " .. pos.x .. " _ " .. pos.y .. " _ " .. pos.z ,
" size[9,11.5] " ..
2017-07-08 17:28:25 +03:00
" background[-0.19,-0.25;9.41,12.5;mcl_chests_inventory_chest_large.png] " ..
2017-03-16 05:16:37 +02:00
mcl_vars.inventory_header ..
" list[nodemeta: " .. pos.x .. " , " .. pos.y .. " , " .. pos.z .. " ;main;0,0.5;9,3;] " ..
" list[nodemeta: " .. pos_other.x .. " , " .. pos_other.y .. " , " .. pos_other.z .. " ;main;0,3.5;9,3;] " ..
" list[current_player;main;0,7.5;9,3;9] " ..
" list[current_player;main;0,10.75;9,1;] " ..
2017-06-12 21:36:50 +03:00
-- BEGIN OF LISTRING WORKAROUND
" listring[current_player;main] " ..
" listring[nodemeta: " .. pos.x .. " , " .. pos.y .. " , " .. pos.z .. " ;input] " ..
-- END OF LISTRING WORKAROUND
2017-03-16 05:16:37 +02:00
" listring[current_player;main] " ..
" listring[nodemeta: " .. pos.x .. " , " .. pos.y .. " , " .. pos.z .. " ;main] " ..
" listring[current_player;main] " ..
" listring[nodemeta: " .. pos_other.x .. " , " .. pos_other.y .. " , " .. pos_other.z .. " ;main] " )
if on_rightclick_addendum_left then
on_rightclick_addendum_left ( pos , node , clicker )
end
end ,
2017-03-16 03:13:35 +02:00
mesecons = mesecons ,
2017-01-27 13:42:05 +02:00
} )
2017-03-16 02:48:52 +02:00
minetest.register_node ( " mcl_chests: " .. basename .. " _right " , {
2017-01-27 13:42:05 +02:00
tiles = { " default_chest_top_big.png^[transformFX " , " default_chest_top_big.png^[transformFX " , " default_chest_side.png " ,
" default_chest_side.png " , " default_chest_side_big.png " , " default_chest_front_big.png^[transformFX " } ,
paramtype2 = " facedir " ,
2017-03-11 06:34:58 +02:00
groups = { handy = 1 , axey = 1 , container = 2 , not_in_creative_inventory = 1 , material_wood = 1 } ,
2017-03-16 05:16:37 +02:00
drop = drop ,
2017-01-27 13:42:05 +02:00
is_ground_content = false ,
2017-02-11 19:46:23 +02:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-01-27 13:42:05 +02:00
on_destruct = function ( pos )
local n = minetest.get_node ( pos )
2017-03-16 02:48:52 +02:00
if n.name == " mcl_chests: " .. basename then
2017-01-27 13:42:05 +02:00
return
end
local param2 = n.param2
local p = get_chest_neighborpos ( pos , param2 , " right " )
2017-03-16 02:48:52 +02:00
if not p or minetest.get_node ( p ) . name ~= " mcl_chests: " .. basename .. " _left " then
2017-01-27 13:42:05 +02:00
return
end
2017-03-16 02:48:52 +02:00
minetest.swap_node ( p , { name = " mcl_chests: " .. basename , param2 = param2 } )
2017-01-27 13:42:05 +02:00
end ,
after_dig_node = function ( pos , oldnode , oldmetadata , digger )
local meta = minetest.get_meta ( pos )
local meta2 = meta
meta : from_table ( oldmetadata )
local inv = meta : get_inventory ( )
for i = 1 , inv : get_size ( " main " ) do
local stack = inv : get_stack ( " main " , i )
if not stack : is_empty ( ) then
local p = { x = pos.x + math.random ( 0 , 10 ) / 10 - 0.5 , y = pos.y , z = pos.z + math.random ( 0 , 10 ) / 10 - 0.5 }
minetest.add_item ( p , stack )
end
end
meta : from_table ( meta2 : to_table ( ) )
end ,
2017-06-12 21:36:50 +03:00
-- BEGIN OF LISTRING WORKAROUND
allow_metadata_inventory_put = function ( pos , listname , index , stack , player )
if listname == " input " then
local other_pos = get_chest_neighborpos ( pos , minetest.get_node ( pos ) . param2 , " right " )
local other_inv = minetest.get_inventory ( { type = " node " , pos = other_pos } )
if other_inv : room_for_item ( " main " , stack ) then
return - 1
else
local inv = minetest.get_inventory ( { type = " node " , pos = pos } )
if inv : room_for_item ( " main " , stack ) then
return - 1
else
return 0
end
end
else
return stack : get_count ( )
end
end ,
-- END OF LISTRING WORKAROUND
2017-01-27 13:42:05 +02:00
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 ) )
end ,
2017-03-16 02:48:52 +02:00
on_metadata_inventory_put = function ( pos , listname , index , stack , player )
2017-01-27 13:42:05 +02:00
minetest.log ( " action " , player : get_player_name ( ) ..
" moves stuff to chest at " .. minetest.pos_to_string ( pos ) )
2017-06-12 21:36:50 +03:00
-- BEGIN OF LISTRING WORKAROUND
2017-06-12 22:04:35 +03:00
if listname == " input " then
local other_pos = get_chest_neighborpos ( pos , minetest.get_node ( pos ) . param2 , " right " )
local other_inv = minetest.get_inventory ( { type = " node " , pos = other_pos } )
local leftover = other_inv : add_item ( " main " , stack )
if not leftover : is_empty ( ) then
local inv = minetest.get_inventory ( { type = " node " , pos = pos } )
inv : add_item ( " main " , leftover )
end
2017-06-12 21:36:50 +03:00
end
-- END OF LISTRING WORKAROUND
2017-01-27 13:42:05 +02:00
end ,
2017-03-16 02:48:52 +02:00
on_metadata_inventory_take = function ( pos , listname , index , stack , player )
2017-01-27 13:42:05 +02:00
minetest.log ( " action " , player : get_player_name ( ) ..
" takes stuff from chest at " .. minetest.pos_to_string ( pos ) )
end ,
2017-02-22 17:03:59 +02:00
_mcl_blast_resistance = 2.5 ,
2017-02-27 02:13:03 +02:00
_mcl_hardness = 2.5 ,
2017-03-16 03:13:35 +02:00
2017-03-16 05:16:37 +02:00
on_rightclick = function ( pos , node , clicker )
local pos_other = get_chest_neighborpos ( pos , node.param2 , " right " )
minetest.show_formspec ( clicker : get_player_name ( ) ,
" mcl_chests: " .. basename .. " _ " .. pos.x .. " _ " .. pos.y .. " _ " .. pos.z ,
" size[9,11.5] " ..
2017-07-08 17:28:25 +03:00
" background[-0.19,-0.25;9.41,12.5;mcl_chests_inventory_chest_large.png] " ..
2017-03-16 05:16:37 +02:00
mcl_vars.inventory_header ..
" list[nodemeta: " .. pos_other.x .. " , " .. pos_other.y .. " , " .. pos_other.z .. " ;main;0,0.5;9,3;] " ..
" list[nodemeta: " .. pos.x .. " , " .. pos.y .. " , " .. pos.z .. " ;main;0,3.5;9,3;] " ..
" list[current_player;main;0,7.5;9,3;9] " ..
" list[current_player;main;0,10.75;9,1;] " ..
2017-06-12 21:36:50 +03:00
-- BEGIN OF LISTRING WORKAROUND
" listring[current_player;main] " ..
" listring[nodemeta: " .. pos.x .. " , " .. pos.y .. " , " .. pos.z .. " ;input] " ..
-- END OF LISTRING WORKAROUND
2017-03-16 05:16:37 +02:00
" listring[current_player;main] " ..
" listring[nodemeta: " .. pos_other.x .. " , " .. pos_other.y .. " , " .. pos_other.z .. " ;main] " ..
" listring[current_player;main] " ..
" listring[nodemeta: " .. pos.x .. " , " .. pos.y .. " , " .. pos.z .. " ;main] " )
if on_rightclick_addendum_right then
on_rightclick_addendum_right ( pos , node , clicker )
end
end ,
2017-03-16 03:13:35 +02:00
mesecons = mesecons ,
} )
2017-03-20 19:12:05 +02:00
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , " mcl_chests: " .. basename , " nodes " , " mcl_chests: " .. basename .. " _left " )
doc.add_entry_alias ( " nodes " , " mcl_chests: " .. basename , " nodes " , " mcl_chests: " .. basename .. " _right " )
end
2017-03-16 02:48:52 +02:00
end
register_chest ( " chest " ,
" Chest " ,
" Chests are containers which provide 27 inventory slots. Chests can be turned into large chests with double the capacity by placing two chests next to each other. " ,
2017-03-20 17:38:16 +02:00
" To acccess the inventory of a chest or large chest, rightclick it. When broken, the items of the chest will drop out. " ,
false
2017-03-16 02:48:52 +02:00
)
2017-03-16 05:16:37 +02:00
local trapped_chest_mesecons_rules = {
{ x = 1 , y = 0 , z = 0 } ,
{ x = - 1 , y = 0 , z = 0 } ,
{ x = 0 , y = 0 , z = 1 } ,
{ x = 0 , y = 0 , z =- 1 } ,
{ x = 0 , y =- 1 , z = 0 }
}
2017-03-16 02:48:52 +02:00
register_chest ( " trapped_chest " ,
" Trapped Chest " ,
" A trapped chest is a container which provides 27 inventory slots. It looks identical to a regular chest, but when it is opened, it sends a redstone signal to its adjacent blocks. Trapped chests can be turned into large trapped chests with double the capacity by placing two trapped chests next to each other. " ,
2017-03-16 03:13:35 +02:00
" To acccess the inventory of a trapped chest or a large trapped chest, rightclick it. When broken, the items will drop out. " ,
2017-03-20 17:38:16 +02:00
nil ,
2017-03-16 03:13:35 +02:00
{ receptor = {
state = mesecon.state . off ,
2017-03-16 05:16:37 +02:00
rules = trapped_chest_mesecons_rules ,
} } ,
function ( pos , node , clicker )
local meta = minetest.get_meta ( pos )
meta : set_int ( " players " , 1 )
minetest.swap_node ( pos , { name = " mcl_chests:trapped_chest_on " , param2 = node.param2 } )
mesecon : receptor_on ( pos , trapped_chest_mesecons_rules )
end ,
function ( pos , node , clicker )
local meta = minetest.get_meta ( pos )
meta : set_int ( " players " , 1 )
minetest.swap_node ( pos , { name = " mcl_chests:trapped_chest_on_left " , param2 = node.param2 } )
mesecon : receptor_on ( pos , trapped_chest_mesecons_rules )
local pos_other = get_chest_neighborpos ( pos , node.param2 , " left " )
minetest.swap_node ( pos_other , { name = " mcl_chests:trapped_chest_on_right " , param2 = node.param2 } )
mesecon : receptor_on ( pos_other , trapped_chest_mesecons_rules )
end ,
function ( pos , node , clicker )
local pos_other = get_chest_neighborpos ( pos , node.param2 , " right " )
-- Save number of players in left part of the chest only
local meta = minetest.get_meta ( pos_other )
meta : set_int ( " players " , 1 )
minetest.swap_node ( pos , { name = " mcl_chests:trapped_chest_on_right " , param2 = node.param2 } )
mesecon : receptor_on ( pos , trapped_chest_mesecons_rules )
minetest.swap_node ( pos_other , { name = " mcl_chests:trapped_chest_on_left " , param2 = node.param2 } )
mesecon : receptor_on ( pos_other , trapped_chest_mesecons_rules )
end
2017-03-16 03:13:35 +02:00
)
register_chest ( " trapped_chest_on " ,
2017-03-30 18:24:12 +03:00
nil , nil , nil , true ,
2017-03-16 03:13:35 +02:00
{ receptor = {
state = mesecon.state . on ,
2017-03-16 05:16:37 +02:00
rules = trapped_chest_mesecons_rules ,
} } ,
function ( pos , node , clicker )
local meta = minetest.get_meta ( pos )
local players = meta : get_int ( " players " )
players = players + 1
meta : set_int ( " players " , players )
end ,
function ( pos , node , clicker )
local meta = minetest.get_meta ( pos )
local players = meta : get_int ( " players " )
players = players + 1
meta : set_int ( " players " , players )
end ,
function ( pos , node , clicker )
local pos_other = get_chest_neighborpos ( pos , node.param2 , " right " )
local meta = minetest.get_meta ( pos_other )
local players = meta : get_int ( " players " )
players = players + 1
meta : set_int ( " players " , players )
end ,
" trapped_chest "
2017-03-16 02:48:52 +02:00
)
2017-01-27 13:42:05 +02:00
2017-03-16 05:16:37 +02:00
-- Disable trapped chest when it has been closed
minetest.register_on_player_receive_fields ( function ( player , formname , fields )
if formname : find ( " mcl_chests:trapped_chest_ " ) == 1 then
if fields.quit then
local x , y , z = formname : match ( " mcl_chests:trapped_chest_(.-)_(.-)_(.*) " )
local pos = { x = tonumber ( x ) , y = tonumber ( y ) , z = tonumber ( z ) }
if not pos or not pos.x or not pos.y or not pos.z then return end
local node = minetest.get_node ( pos )
local meta , players , pos_other
if node.name == " mcl_chests:trapped_chest_on " or node.name == " mcl_chests:trapped_chest_on_left " then
meta = minetest.get_meta ( pos )
players = meta : get_int ( " players " )
players = players - 1
elseif node.name == " mcl_chests:trapped_chest_on_right " then
pos_other = get_chest_neighborpos ( pos , node.param2 , " right " )
meta = minetest.get_meta ( pos_other )
players = meta : get_int ( " players " )
players = players - 1
end
if node.name == " mcl_chests:trapped_chest_on " then
if players <= 0 then
meta : set_int ( " players " , 0 )
minetest.swap_node ( pos , { name = " mcl_chests:trapped_chest " , param2 = node.param2 } )
mesecon : receptor_off ( pos , trapped_chest_mesecons_rules )
else
meta : set_int ( " players " , players )
end
elseif node.name == " mcl_chests:trapped_chest_on_left " then
if players <= 0 then
meta : set_int ( " players " , 0 )
minetest.swap_node ( pos , { name = " mcl_chests:trapped_chest_left " , param2 = node.param2 } )
mesecon : receptor_off ( pos , trapped_chest_mesecons_rules )
pos_other = get_chest_neighborpos ( pos , node.param2 , " left " )
minetest.swap_node ( pos_other , { name = " mcl_chests:trapped_chest_right " , param2 = node.param2 } )
mesecon : receptor_off ( pos_other , trapped_chest_mesecons_rules )
else
meta : set_int ( " players " , players )
end
elseif node.name == " mcl_chests:trapped_chest_on_right " then
if players <= 0 then
meta : set_int ( " players " , 0 )
minetest.swap_node ( pos , { name = " mcl_chests:trapped_chest_right " , param2 = node.param2 } )
mesecon : receptor_off ( pos , trapped_chest_mesecons_rules )
minetest.swap_node ( pos_other , { name = " mcl_chests:trapped_chest_left " , param2 = node.param2 } )
mesecon : receptor_off ( pos_other , trapped_chest_mesecons_rules )
else
meta : set_int ( " players " , players )
end
end
end
end
end )
2017-01-27 13:42:05 +02:00
minetest.register_craft ( {
output = ' mcl_chests:chest ' ,
recipe = {
{ ' group:wood ' , ' group:wood ' , ' group:wood ' } ,
{ ' group:wood ' , ' ' , ' group:wood ' } ,
{ ' group:wood ' , ' group:wood ' , ' group:wood ' } ,
}
2017-02-01 00:32:56 +02:00
} )
2017-02-06 22:33:38 +02:00
2017-02-13 15:33:16 +02:00
minetest.register_craft ( {
type = ' fuel ' ,
recipe = ' mcl_chests:chest ' ,
burntime = 15
} )
2017-03-16 02:48:52 +02:00
minetest.register_craft ( {
type = ' fuel ' ,
recipe = ' mcl_chests:trapped_chest ' ,
burntime = 15
} )
2017-02-06 22:33:38 +02:00
minetest.register_node ( " mcl_chests:ender_chest " , {
description = " Ender Chest " ,
2017-03-16 05:18:42 +02:00
_doc_items_longdesc = " Ender chests grant you access to a single personal interdimensional inventory with 27 slots. This inventory is the same no matter from which ender chest you access it from. If you put one item into one ender chest, you will find it in all other ender chests worldwide. Each player will only see their own items, but not the items of other players. " ,
2017-03-11 01:23:49 +02:00
_doc_items_usagehelp = " Rightclick the ender chest to access your personal interdimensional inventory. " ,
2017-02-06 22:33:38 +02:00
tiles = { " mcl_chests_ender_chest_top.png " , " mcl_chests_ender_chest_bottom.png " ,
" mcl_chests_ender_chest_right.png " , " mcl_chests_ender_chest_left.png " ,
" mcl_chests_ender_chest_back.png " , " mcl_chests_ender_chest_front.png " } ,
2017-02-13 20:06:12 +02:00
-- Note: The “container” group is missing here because the ender chest does not
-- have an inventory on its own
2017-03-11 06:34:58 +02:00
groups = { pickaxey = 1 , deco_block = 1 , material_stone = 1 } ,
2017-02-06 22:33:38 +02:00
is_ground_content = false ,
2017-02-06 23:10:20 +02:00
paramtype = " light " ,
2017-02-06 22:33:38 +02:00
light_source = 7 ,
paramtype2 = " facedir " ,
2017-02-11 19:46:23 +02:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2017-02-06 22:33:38 +02:00
drop = " mcl_core:obsidian 8 " ,
on_construct = function ( pos )
local meta = minetest.get_meta ( pos )
meta : set_string ( " formspec " ,
" size[9,8.75] " ..
2017-02-20 04:56:18 +02:00
mcl_vars.inventory_header ..
2017-07-08 17:28:25 +03:00
" background[-0.19,-0.25;9.41,10.48;mcl_chests_inventory_chest.png] " ..
" image[0,-0.2;5,0.75;mcl_chests_fnt_ender_chest.png] " ..
2017-02-06 22:33:38 +02:00
" list[current_player;enderchest;0,0.5;9,3;] " ..
" list[current_player;main;0,4.5;9,3;9] " ..
" list[current_player;main;0,7.74;9,1;] " ..
" listring[current_player;enderchest] " ..
" listring[current_player;main] " )
end ,
2017-02-22 17:03:59 +02:00
_mcl_blast_resistance = 3000 ,
2017-02-27 02:13:03 +02:00
_mcl_hardness = 22.5 ,
2017-02-06 22:33:38 +02:00
} )
minetest.register_on_joinplayer ( function ( player )
local inv = player : get_inventory ( )
inv : set_size ( " enderchest " , 9 * 3 )
end )
minetest.register_craft ( {
output = ' mcl_chests:ender_chest ' ,
recipe = {
{ ' mcl_core:obsidian ' , ' mcl_core:obsidian ' , ' mcl_core:obsidian ' } ,
{ ' mcl_core:obsidian ' , ' mcl_end:ender_eye ' , ' mcl_core:obsidian ' } ,
{ ' mcl_core:obsidian ' , ' mcl_core:obsidian ' , ' mcl_core:obsidian ' } ,
}
} )
2017-02-07 02:17:00 +02:00
-- Shulker boxes
local boxtypes = {
2017-02-07 03:17:06 +02:00
white = " White Shulker Box " ,
grey = " Light Grey Shulker Box " ,
orange = " Orange Shulker Box " ,
cyan = " Cyan Shulker Box " ,
magenta = " Magenta Shulker Box " ,
2017-02-07 02:31:40 +02:00
violet = " Purple Shulker Box " ,
2017-02-07 03:17:06 +02:00
lightblue = " Light Blue Shulker Box " ,
blue = " Blue Shulker Box " ,
yellow = " Yellow Shulker Box " ,
brown = " Brown Shulker Box " ,
green = " Lime Shulker Box " ,
dark_green = " Green Shulker Box " ,
pink = " Pink Shulker Box " ,
red = " Red Shulker Box " ,
dark_grey = " Grey Shulker Box " ,
black = " Black Shulker Box " ,
2017-02-07 02:17:00 +02:00
}
for color , desc in pairs ( boxtypes ) do
minetest.register_node ( " mcl_chests: " .. color .. " _shulker_box " , {
description = desc ,
2017-03-11 01:23:49 +02:00
_doc_items_longdesc = " A shulker box is a portable container which provides 27 inventory slots for any item except shulker boxes. Shulker boxes keep their inventory when broken, so shulker boxes as well as their contents can be taken as a single item. Shulker boxes come in many different colors. " ,
_doc_items_usagehelp = " To access the inventory of a shulker box, place and right-click it. To take a shulker box and its contents with you, just break and collect it, the items will not fall out. Place the shulker box again to be able to retrieve its contents. " ,
2017-02-07 02:17:00 +02:00
tiles = { " mcl_chests_ " .. color .. " _shulker_box_top.png " , " mcl_chests_ " .. color .. " _shulker_box_bottom.png " ,
" mcl_chests_ " .. color .. " _shulker_box_side.png " , " mcl_chests_ " .. color .. " _shulker_box_side.png " ,
" mcl_chests_ " .. color .. " _shulker_box_side.png " , " mcl_chests_ " .. color .. " _shulker_box_side.png " } ,
2017-03-29 23:58:31 +03:00
groups = { handy = 1 , pickaxey = 1 , container = 3 , deco_block = 1 , dig_by_piston = 1 , shulker_box = 1 } ,
2017-02-07 02:17:00 +02:00
is_ground_content = false ,
2017-02-11 19:46:23 +02:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2017-02-07 02:17:00 +02:00
stack_max = 1 ,
drop = " " ,
2017-06-13 15:46:21 +03:00
paramtype = " light " ,
sunlight_propagates = true ,
2017-06-12 23:36:31 +03:00
paramtype2 = " facedir " ,
2017-06-13 19:15:08 +03:00
-- TODO: Make shulker boxes rotatable
-- This doesn't work, it just destroys the inventory:
-- on_place = minetest.rotate_node,
2017-02-07 02:17:00 +02:00
on_construct = function ( pos )
local meta = minetest.get_meta ( pos )
meta : set_string ( " formspec " ,
" size[9,8.75] " ..
2017-02-20 04:56:18 +02:00
mcl_vars.inventory_header ..
2017-07-08 17:28:25 +03:00
" background[-0.19,-0.25;9.41,10.48;mcl_chests_inventory_chest.png] " ..
" image[0,-0.2;5,0.75;mcl_chests_fnt_shulker_box.png] " ..
2017-02-07 02:17:00 +02:00
" list[current_name;main;0,0.5;9,3;] " ..
" list[current_player;main;0,4.5;9,3;9] " ..
" list[current_player;main;0,7.74;9,1;] " ..
" listring[current_name;main] " ..
" listring[current_player;main] " )
local inv = meta : get_inventory ( )
inv : set_size ( " main " , 9 * 3 )
end ,
after_place_node = function ( pos , placer , itemstack , pointed_thing )
local nmeta = minetest.get_meta ( pos )
local ninv = nmeta : get_inventory ( )
local imeta = itemstack : get_metadata ( )
local iinv_main = minetest.deserialize ( imeta )
ninv : set_list ( " main " , iinv_main )
ninv : set_size ( " main " , 9 * 3 )
2017-02-08 22:16:18 +02:00
if minetest.setting_getbool ( " creative_mode " ) then
if not ninv : is_empty ( " main " ) then
return nil
else
return itemstack
end
else
return nil
end
2017-02-07 02:17:00 +02:00
end ,
2017-03-30 03:32:46 +03:00
on_destruct = function ( pos )
2017-02-07 02:17:00 +02:00
local meta = minetest.get_meta ( pos )
local inv = meta : get_inventory ( )
local items = { }
for i = 1 , inv : get_size ( " main " ) do
2017-02-08 22:16:18 +02:00
local stack = inv : get_stack ( " main " , i )
items [ i ] = stack : to_string ( )
2017-02-07 02:17:00 +02:00
end
local data = minetest.serialize ( items )
local boxitem = ItemStack ( " mcl_chests: " .. color .. " _shulker_box " )
boxitem : set_metadata ( data )
2017-02-08 22:16:18 +02:00
if minetest.setting_getbool ( " creative_mode " ) then
if not inv : is_empty ( " main " ) then
minetest.add_item ( pos , boxitem )
end
else
minetest.add_item ( pos , boxitem )
end
2017-02-07 02:17:00 +02:00
end ,
allow_metadata_inventory_put = function ( pos , listname , index , stack , player )
-- Do not allow to place shulker boxes into shulker boxes
local group = minetest.get_item_group ( stack : get_name ( ) , " shulker_box " )
if group == 0 or group == nil then
return stack : get_count ( )
else
return 0
end
end ,
2017-02-22 17:03:59 +02:00
_mcl_blast_resistance = 30 ,
2017-02-27 02:13:03 +02:00
_mcl_hardness = 6 ,
2017-02-07 02:17:00 +02:00
} )
minetest.register_craft ( {
type = " shapeless " ,
output = ' mcl_chests: ' .. color .. ' _shulker_box ' ,
recipe = { ' group:shulker_box ' , ' mcl_dye: ' .. color }
} )
end
minetest.register_craft ( {
2017-02-07 02:31:40 +02:00
output = ' mcl_chests:violet_shulker_box ' ,
2017-02-07 02:17:00 +02:00
recipe = {
{ ' mcl_mobitems:shulker_shell ' } ,
{ ' mcl_chests:chest ' } ,
{ ' mcl_mobitems:shulker_shell ' } ,
}
} )
2017-02-06 22:33:38 +02:00