Made it so the chest is an actual chest after the items are spawned.

master
DonBatman 2015-10-16 08:18:47 -07:00
parent b2bd5d1646
commit f1ef6aac4b
2 changed files with 162 additions and 61 deletions

223
init.lua
View File

@ -1,11 +1,84 @@
--To add or delete items modify the lines below.
--Add or delete local item#
--For each local item# add or delete the minetest.spawn_item in the next section.
local item1 = "default:diamond 3"
local item2 = "default:steel_ingot 10"
local item3 = "default:sand 5"
local item4 = "default:pick_steel"
--local item4 = "default:pick_steel"
local item5 = "default:mese_crystal 3"
-- if you want to add more items or have less please edit lines 30+
local item_spawn = function(pos, node, player, itemstack, pointed_thing)
minetest.add_node(pos, {name="myitemchest:chest_open_storage", param2=node.param2})
minetest.add_node({x=pos.x,y=pos.y+1,z=pos.z}, {name="myitemchest:chest_formspec", param2=node.param2})
minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item1)
minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item2)
minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item3)
--minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item4)
minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item5)
end
local check_air = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local nodea = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
if nodea.name ~= "air" then
minetest.chat_send_player( placer:get_player_name(), "Need room above chest" )
return
end
return minetest.item_place(itemstack, placer, pointed_thing)
end
local dig_it = function(pos, node, digger)
local meta = minetest.get_meta({x=pos.x,y=pos.y+1,z=pos.z});
local inv = meta:get_inventory()
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") == true then
minetest.remove_node({x=pos.x,y=pos.y+1,z=pos.z})
minetest.remove_node(pos)
minetest.spawn_item(pos,"myitemchest:chest_storage")
else
minetest.chat_send_player( digger:get_player_name(), "Chest is not empty" )
end
end
local closed_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3125, 0.5, 0.3125, 0.375},
}
}
local open_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3125, 0.5, -0.4375, 0.375},
{-0.5, -0.5, 0.3125, 0.5, 0.1875, 0.375},
{-0.5, -0.5, -0.3125, -0.4375, 0.1875, 0.375},
{0.4375, -0.5, -0.3125, 0.5, 0.1875, 0.375},
{-0.5, -0.5, -0.3125, 0.5, 0.1875, -0.25},
{-0.5, 0.1875, 0.4375, 0.5, 0.875, 0.5},
{-0.5, 0.1875, 0.375, 0.5, 0.25, 0.5},
{-0.5, 0.8125, 0.375, 0.5, 0.875, 0.5},
{-0.5, 0.1875, 0.375, -0.4375, 0.875, 0.5},
{0.4375, 0.1875, 0.375, 0.5, 0.875, 0.5},
}
}
local chest_formspec =
"size[8,9]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[current_name;main;0,0.3;8,4;]" ..
"list[current_player;main;0,4.85;8,1;]" ..
"list[current_player;main;0,6.08;8,3;8]" ..
"listring[current_name;main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
minetest.register_node("myitemchest:chest", {
description = "Chest",
description = "Item Chest",
tiles = {
"myitemchest_chest_top.png",
"myitemchest_chest_top.png",
@ -19,47 +92,43 @@ minetest.register_node("myitemchest:chest", {
paramtype2 = "facedir",
groups = {choppy = 2},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3125, 0.5, 0.3125, 0.375},
}
},
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
minetest.set_node(pos, {name="myitemchest:chest_open", param2=node.param2})
minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item1)
minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item2)
minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item3)
minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item4)
minetest.spawn_item({x=pos.x,y=pos.y+0.5,z=pos.z}, item5)
end,
node_box = closed_box,
selection_box = closed_box,
on_place = check_air,
on_rightclick = item_spawn,
})
minetest.register_node("myitemchest:chest2", {
description = "Chest",
minetest.register_node("myitemchest:chest_storage", {
description = "Storage Chest",
tiles = {
"myitemchest_chest_top.png",
"myitemchest_chest_top.png",
"myitemchest_chest_top.png",
"myitemchest_chest_top.png",
"myitemchest_chest_top.png",
"myitemchest_chest_top.png"
"myitemchest_chest_front.png",
"myitemchest_chest_front.png",
"myitemchest_chest_front.png",
"myitemchest_chest_front.png"
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
groups = {choppy = 2},
drop = "myitemchest:chest_storage",
groups = {choppy = 2,not_in_creative_inventory=0},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3125, 0.5, 0.3125, 0.375},
}
},
node_box = closed_box,
on_place = check_air,
after_place_node = function(pos, placer, itemstack, pointed_thing)
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})
end,
on_dig = dig_it,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
minetest.swap_node(pos, {name="myitemchest:chest_open", param2=node.param2})
local timer = minetest.get_node_timer(pos)
timer:start(5)
minetest.swap_node(pos, {name="myitemchest:chest_open_storage", param2=node.param2})
end,
})
minetest.register_node("myitemchest:chest_open", {
minetest.register_node("myitemchest:chest_open_storage", {
description = "Chest Open",
tiles = {
"myitemchest_chest_open_top.png",
@ -72,41 +141,73 @@ minetest.register_node("myitemchest:chest_open", {
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
drop = "myitemchest:chest2",
drop = "myitemchest:chest_storage",
groups = {choppy = 2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
node_box = open_box,
selection_box = open_box,
on_dig = dig_it,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
minetest.swap_node(pos, {name="myitemchest:chest_storage", param2=node.param2})
end,
on_timer = function(pos, elapsed)
local timer = minetest.get_node_timer(pos)
local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = "myitemchest:chest_storage", param2=node.param2})
end,
})
minetest.register_node("myitemchest:chest_formspec", {
description = "Chest fs",
tiles = {
"myitemchest_air.png"
},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
alpha = 100,
drop = "myitemchest:chest_storage",
groups = {choppy = 2,not_in_creative_inventory=1},
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3125, 0.5, -0.4375, 0.375},
{-0.5, -0.5, 0.3125, 0.5, 0.1875, 0.375},
{-0.5, -0.5, -0.3125, -0.4375, 0.1875, 0.375},
{0.4375, -0.5, -0.3125, 0.5, 0.1875, 0.375},
{-0.5, -0.5, -0.3125, 0.5, 0.1875, -0.25},
{-0.5, 0.1875, 0.4375, 0.5, 0.875, 0.5},
{-0.5, 0.1875, 0.375, 0.5, 0.25, 0.5},
{-0.5, 0.8125, 0.375, 0.5, 0.875, 0.5},
{-0.5, 0.1875, 0.375, -0.4375, 0.875, 0.5},
{0.4375, 0.1875, 0.375, 0.5, 0.875, 0.5},
{-0.4375, -1.4375, -0.25, 0.4375, -0.9125, 0.3125},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3125, 0.5, -0.4375, 0.375},
{-0.5, -0.5, 0.3125, 0.5, 0.1875, 0.375},
{-0.5, -0.5, -0.3125, -0.4375, 0.1875, 0.375},
{0.4375, -0.5, -0.3125, 0.5, 0.1875, 0.375},
{-0.5, -0.5, -0.3125, 0.5, 0.1875, -0.25},
{-0.5, 0.1875, 0.4375, 0.5, 0.875, 0.5},
{-0.5, 0.1875, 0.375, 0.5, 0.25, 0.5},
{-0.5, 0.8125, 0.375, 0.5, 0.875, 0.5},
{-0.5, 0.1875, 0.375, -0.4375, 0.875, 0.5},
{0.4375, 0.1875, 0.375, 0.5, 0.875, 0.5},
}
},
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
minetest.swap_node(pos, {name="myitemchest:chest2", param2=node.param2})
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", chest_formspec)
meta:set_string("infotext", "Chest")
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
end,
on_dig = function(pos, node, digger)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
local nodeu = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
if inv:is_empty("main") == true 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(pos)
minetest.spawn_item(pos,"myitemchest:chest_storage")
end
else return
end
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,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" moves stuff to 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 chest at " .. minetest.pos_to_string(pos))
end,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B