mirror of
https://github.com/joe7575/techpack.git
synced 2024-08-20 21:24:05 +02:00
117 lines
3.0 KiB
Lua
117 lines
3.0 KiB
Lua
--[[
|
|
|
|
Tubelib Addons 1
|
|
================
|
|
|
|
Copyright (C) 2017-2018 Joachim Stolberg
|
|
|
|
LGPLv2.1+
|
|
See LICENSE.txt for more information
|
|
|
|
chest.lua
|
|
|
|
]]--
|
|
|
|
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
return 0
|
|
end
|
|
minetest.log("action", player:get_player_name().." moves "..stack:get_name()..
|
|
" to chest at "..minetest.pos_to_string(pos))
|
|
return stack:get_count()
|
|
end
|
|
|
|
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
return 0
|
|
end
|
|
minetest.log("action", player:get_player_name().." takes "..stack:get_name()..
|
|
" from chest at "..minetest.pos_to_string(pos))
|
|
return stack:get_count()
|
|
end
|
|
|
|
local function formspec()
|
|
return "size[9,8]"..
|
|
default.gui_bg..
|
|
default.gui_bg_img..
|
|
default.gui_slots..
|
|
"list[context;main;0.5,0;8,4;]"..
|
|
"list[current_player;main;0.5,4.3;8,4;]"..
|
|
"listring[context;main]"..
|
|
"listring[current_player;main]"
|
|
end
|
|
|
|
minetest.register_node("tubelib_addons1:chest", {
|
|
description = "Tubelib Protected Chest",
|
|
tiles = {
|
|
-- up, down, right, left, back, front
|
|
"default_chest_top.png",
|
|
"default_chest_top.png",
|
|
"default_chest_side.png",
|
|
"default_chest_side.png",
|
|
"default_chest_side.png",
|
|
"default_chest_lock.png",
|
|
},
|
|
|
|
on_construct = function(pos)
|
|
local meta = minetest.get_meta(pos)
|
|
local inv = meta:get_inventory()
|
|
inv:set_size('main', 32)
|
|
end,
|
|
|
|
after_place_node = function(pos, placer)
|
|
local meta = minetest.get_meta(pos)
|
|
meta:set_string("formspec", formspec())
|
|
meta:set_string("infotext", "Tubelib Protected Chest")
|
|
end,
|
|
|
|
can_dig = function(pos,player)
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
return false
|
|
end
|
|
local meta = minetest.get_meta(pos);
|
|
local inv = meta:get_inventory()
|
|
return inv:is_empty("main")
|
|
end,
|
|
|
|
on_dig = function(pos, node, puncher, pointed_thing)
|
|
minetest.node_dig(pos, node, puncher, pointed_thing)
|
|
end,
|
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
|
|
|
paramtype = "light",
|
|
sunlight_propagates = true,
|
|
paramtype2 = "facedir",
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
is_ground_content = false,
|
|
sounds = default.node_sound_wood_defaults(),
|
|
})
|
|
|
|
|
|
minetest.register_craft({
|
|
type = "shapeless",
|
|
output = "tubelib_addons1:chest",
|
|
recipe = {"default:chest", "tubelib:tube1", "default:steel_ingot"}
|
|
})
|
|
|
|
tubelib.register_node("tubelib_addons1:chest", {}, {
|
|
on_pull_item = function(pos, side)
|
|
local meta = minetest.get_meta(pos)
|
|
return tubelib.get_item(meta, "main")
|
|
end,
|
|
on_push_item = function(pos, side, item)
|
|
local meta = minetest.get_meta(pos)
|
|
return tubelib.put_item(meta, "main", item)
|
|
end,
|
|
on_unpull_item = function(pos, side, item)
|
|
local meta = minetest.get_meta(pos)
|
|
return tubelib.put_item(meta, "main", item)
|
|
end,
|
|
|
|
on_recv_message = function(pos, topic, payload)
|
|
return "unsupported"
|
|
end,
|
|
})
|