diff --git a/README.md b/README.md index da05b45..d6b5e97 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tubelib_addons1/chest.lua b/tubelib_addons1/chest.lua new file mode 100644 index 0000000..c8703ed --- /dev/null +++ b/tubelib_addons1/chest.lua @@ -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, +}) diff --git a/tubelib_addons1/funnel.lua b/tubelib_addons1/funnel.lua index 82be6d5..c2f9858 100644 --- a/tubelib_addons1/funnel.lua +++ b/tubelib_addons1/funnel.lua @@ -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, diff --git a/tubelib_addons1/init.lua b/tubelib_addons1/init.lua index 6d39186..48cd012 100644 --- a/tubelib_addons1/init.lua +++ b/tubelib_addons1/init.lua @@ -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')