V1.03 Protected chest added, some funnel code maintenance.

This commit is contained in:
Joachim Stolberg 2018-03-29 19:31:30 +02:00
parent c60ed39ed4
commit 53c4074450
4 changed files with 133 additions and 15 deletions

@ -1,4 +1,4 @@
# TechPack V1.02
# TechPack V1.03
TechPack, a Mining, Crafting, & Farming Modpack for Minetest.
@ -74,3 +74,4 @@ Gravelsieve optional: moreores, hopper, pipeworks
- 2018-03-18 V1.00 * Tubelib, tubelib_addons1, tubelib_addons2, smartline, and gravelsieve combined to one modpack.
- 2018-03-24 V1.01 * Support for Ethereal added
- 2018-03-27 V1.02 * Timer improvements for unloaded areas
- 2018-03-29 V1.03 * Area protected chest added to tubelib_addons1

116
tubelib_addons1/chest.lua Normal file

@ -0,0 +1,116 @@
--[[
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,
})

@ -16,18 +16,17 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if listname == "main" then
return stack:get_count()
end
return 0
minetest.log("action", player:get_player_name().." moves "..stack:get_name()..
" to funnel 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 funnel at "..minetest.pos_to_string(pos))
return stack:get_count()
end
@ -93,22 +92,23 @@ minetest.register_node("tubelib_addons1:funnel", {
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
meta:set_string("formspec", formspec())
minetest.get_node_timer(pos):start(1)
end,
on_timer = scan_for_objects,
on_dig = function(pos, node, puncher, pointed_thing)
if minetest.is_protected(pos, puncher:get_player_name()) then
return
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 meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
if inv:is_empty("main") then
minetest.node_dig(pos, node, puncher, pointed_thing)
end
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,

@ -19,3 +19,4 @@ dofile(minetest.get_modpath("tubelib_addons1") .. '/fermenter.lua')
dofile(minetest.get_modpath("tubelib_addons1") .. '/reformer.lua')
dofile(minetest.get_modpath("tubelib_addons1") .. '/funnel.lua')
dofile(minetest.get_modpath("tubelib_addons1") .. "/pusher_fast.lua")
dofile(minetest.get_modpath("tubelib_addons1") .. '/chest.lua')