Code cleanup and a few other things
parent
3fbba8850a
commit
f93af09f72
|
@ -0,0 +1,5 @@
|
||||||
|
#myitemchest
|
||||||
|
|
||||||
|
A Minetest mod that is a chest. When you open it items pop out. After that you can use the chest as a regular chest.
|
||||||
|
|
||||||
|
Licence - DWYWPL
|
72
init.lua
72
init.lua
|
@ -21,33 +21,46 @@ local item_spawn = function(pos, node)
|
||||||
minetest.set_node(pos, {name="myitemchest:chest_open_storage", param2=node.param2})
|
minetest.set_node(pos, {name="myitemchest:chest_open_storage", param2=node.param2})
|
||||||
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name="myitemchest:chest_formspec", param2=node.param2})
|
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name="myitemchest:chest_formspec", param2=node.param2})
|
||||||
--pos.y = pos.y-0.5
|
--pos.y = pos.y-0.5
|
||||||
|
|
||||||
for _,object in pairs(objs) do
|
for _,object in pairs(objs) do
|
||||||
object:setvelocity({x=0, y=4.5, z=0})
|
object:setvelocity({x=0, y=4.5, z=0})
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local check_air = function(itemstack, placer, pointed_thing)
|
local check_air = function(itemstack, placer, pointed_thing)
|
||||||
|
|
||||||
local pos = pointed_thing.above
|
local pos = pointed_thing.above
|
||||||
local nodea = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
|
local nodea = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
|
||||||
|
|
||||||
if nodea.name ~= "air" then
|
if nodea.name ~= "air" then
|
||||||
minetest.chat_send_player( placer:get_player_name(), "Need room above chest" )
|
minetest.chat_send_player( placer:get_player_name(), "Need room above chest" )
|
||||||
return
|
return
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return minetest.item_place(itemstack, placer, pointed_thing)
|
return minetest.item_place(itemstack, placer, pointed_thing)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local dig_it = function(pos, node, digger)
|
local dig_it = function(pos, node, digger)
|
||||||
local meta = minetest.get_meta({x=pos.x,y=pos.y+1,z=pos.z});
|
local meta = minetest.get_meta({x=pos.x,y=pos.y+1,z=pos.z});
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local nodeu = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
|
local nodeu = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
|
||||||
if nodeu.name == "myitemchest:chest_formspec" and
|
|
||||||
inv:is_empty("main") then
|
if nodeu.name == "myitemchest:chest_formspec"
|
||||||
|
and inv:is_empty("main") then
|
||||||
|
|
||||||
minetest.remove_node({x=pos.x,y=pos.y+1,z=pos.z})
|
minetest.remove_node({x=pos.x,y=pos.y+1,z=pos.z})
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
minetest.spawn_item(pos,"myitemchest:chest_storage")
|
minetest.spawn_item(pos,"myitemchest:chest_storage")
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
minetest.chat_send_player( digger:get_player_name(), "Chest is not empty" )
|
minetest.chat_send_player( digger:get_player_name(), "Chest is not empty" )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local closed_box = {
|
local closed_box = {
|
||||||
|
@ -74,15 +87,19 @@ local open_box = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local chest_formspec =
|
local chest_formspec =
|
||||||
|
|
||||||
"size[8,9]" ..
|
"size[8,9]" ..
|
||||||
|
|
||||||
default.gui_bg ..
|
default.gui_bg ..
|
||||||
default.gui_bg_img ..
|
default.gui_bg_img ..
|
||||||
default.gui_slots ..
|
default.gui_slots ..
|
||||||
|
|
||||||
"list[current_name;main;0,0.3;8,4;]" ..
|
"list[current_name;main;0,0.3;8,4;]" ..
|
||||||
"list[current_player;main;0,4.85;8,1;]" ..
|
"list[current_player;main;0,4.85;8,1;]" ..
|
||||||
"list[current_player;main;0,6.08;8,3;8]" ..
|
"list[current_player;main;0,6.08;8,3;8]" ..
|
||||||
"listring[current_name;main]" ..
|
"listring[current_name;main]" ..
|
||||||
"listring[current_player;main]" ..
|
"listring[current_player;main]" ..
|
||||||
|
|
||||||
default.get_hotbar_bg(0,4.85)
|
default.get_hotbar_bg(0,4.85)
|
||||||
|
|
||||||
minetest.register_node("myitemchest:chest", {
|
minetest.register_node("myitemchest:chest", {
|
||||||
|
@ -125,14 +142,22 @@ minetest.register_node("myitemchest:chest_storage", {
|
||||||
node_box = closed_box,
|
node_box = closed_box,
|
||||||
on_place = check_air,
|
on_place = check_air,
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name = "myitemchest:chest_formspec", param2 = node.param2})
|
|
||||||
|
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name = "myitemchest:chest_formspec", param2 = node.param2})
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_dig = dig_it,
|
on_dig = dig_it,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
||||||
|
|
||||||
local timer = minetest.get_node_timer(pos)
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
|
||||||
timer:start(5)
|
timer:start(5)
|
||||||
minetest.swap_node(pos, {name="myitemchest:chest_open_storage", param2=node.param2})
|
minetest.swap_node(pos, {name="myitemchest:chest_open_storage", param2=node.param2})
|
||||||
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -156,12 +181,18 @@ minetest.register_node("myitemchest:chest_open_storage", {
|
||||||
selection_box = open_box,
|
selection_box = open_box,
|
||||||
on_dig = dig_it,
|
on_dig = dig_it,
|
||||||
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
||||||
|
|
||||||
minetest.swap_node(pos, {name="myitemchest:chest_storage", param2=node.param2})
|
minetest.swap_node(pos, {name="myitemchest:chest_storage", param2=node.param2})
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_timer = function(pos, elapsed)
|
on_timer = function(pos, elapsed)
|
||||||
|
|
||||||
local timer = minetest.get_node_timer(pos)
|
local timer = minetest.get_node_timer(pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
minetest.swap_node(pos, {name = "myitemchest:chest_storage", param2=node.param2})
|
|
||||||
|
minetest.swap_node(pos, {name = "myitemchest:chest_storage", param2=node.param2})
|
||||||
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -185,37 +216,60 @@ minetest.register_node("myitemchest:chest_formspec", {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
meta:set_string("formspec", chest_formspec)
|
meta:set_string("formspec", chest_formspec)
|
||||||
meta:set_string("infotext", "Chest")
|
meta:set_string("infotext", "Chest")
|
||||||
|
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
inv:set_size("main", 8*4)
|
inv:set_size("main", 8*4)
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_dig = function(pos, node, digger)
|
on_dig = function(pos, node, digger)
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local nodeu = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
|
local nodeu = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||||
|
|
||||||
if inv:is_empty("main") == true then
|
if inv:is_empty("main") == true then
|
||||||
if nodeu.name == "myitemchest:chest_storage" or
|
|
||||||
nodeu.name == "myitemchest:chest_open_storage" then
|
if nodeu.name == "myitemchest:chest_storage"
|
||||||
|
or nodeu.name == "myitemchest:chest_open_storage" then
|
||||||
|
|
||||||
minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z})
|
minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
minetest.spawn_item(pos,"myitemchest:chest_storage")
|
minetest.spawn_item(pos,"myitemchest:chest_storage")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
else return
|
else return
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_metadata_inventory_move = function(pos, from_list, from_index,
|
on_metadata_inventory_move = function(pos, from_list, from_index,
|
||||||
to_list, to_index, count, player)
|
to_list, to_index, count, player)
|
||||||
|
|
||||||
minetest.log("action", player:get_player_name() ..
|
minetest.log("action", player:get_player_name() ..
|
||||||
" moves stuff in chest at " .. minetest.pos_to_string(pos))
|
" moves stuff in chest at " .. minetest.pos_to_string(pos))
|
||||||
|
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
|
|
||||||
minetest.log("action", player:get_player_name() ..
|
minetest.log("action", player:get_player_name() ..
|
||||||
" moves stuff to chest at " .. minetest.pos_to_string(pos))
|
" moves stuff to chest at " .. minetest.pos_to_string(pos))
|
||||||
|
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
|
|
||||||
minetest.log("action", player:get_player_name() ..
|
minetest.log("action", player:get_player_name() ..
|
||||||
" takes stuff from chest at " .. minetest.pos_to_string(pos))
|
" takes stuff from chest at " .. minetest.pos_to_string(pos))
|
||||||
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
DO WHAT YOU WANT TO PUBLIC LICENSE
|
||||||
|
or abbreviated DWYWPL
|
||||||
|
|
||||||
|
December 2nd 2015
|
||||||
|
License Copyright (C) 2015 Michael Tomaino (PlatinumArts@gmail.com)
|
||||||
|
www.sandboxgamemaker.com/DWYWPL/
|
||||||
|
|
||||||
|
DO WHAT YOU WANT TO PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
1. You are allowed to do whatever you want to with what content is using this license.
|
||||||
|
2. This content is provided 'as-is', without any express or implied warranty. In no event
|
||||||
|
will the authors be held liable for any damages arising from the use of this content.
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 159 KiB After Width: | Height: | Size: 154 KiB |
Loading…
Reference in New Issue