--[[ Signs Bot ========= Copyright (C) 2019-2021 Joachim Stolberg GPL v3 See LICENSE.txt for more information Signs Bot: More commands ]]-- -- for lazy programmers local M = minetest.get_meta -- Load support for I18n. local S = signs_bot.S local lib = signs_bot.lib local RegisteredInventories = {} -- -- Move from/to inventories -- -- From chest to robot function signs_bot.robot_take(base_pos, robot_pos, param2, want_count, slot) local target_pos = lib.next_pos(robot_pos, param2) local node = tubelib2.get_node_lvm(target_pos) local def = RegisteredInventories[node.name] local owner = M(base_pos):get_string("owner") -- Is known type of inventory node? if def and (not def.allow_take or def.allow_take(target_pos, nil, owner)) then local src_inv = minetest.get_inventory({type="node", pos=target_pos}) -- take specified item_name from bot slot configuration OR any item from the chest local item_name = signs_bot.bot_inv_item_name(base_pos, slot) or lib.peek_inv(src_inv, def.take_listname) if item_name then local taken = src_inv:remove_item(def.take_listname, ItemStack(item_name.." "..want_count)) local leftover = signs_bot.bot_inv_put_item(base_pos, slot, taken) src_inv:add_item(def.take_listname, leftover) end end end -- From robot to chest function signs_bot.robot_put(base_pos, robot_pos, param2, num, slot) local target_pos = lib.next_pos(robot_pos, param2) local node = tubelib2.get_node_lvm(target_pos) local def = RegisteredInventories[node.name] local owner = M(base_pos):get_string("owner") local taken = signs_bot.bot_inv_take_item(base_pos, slot, num) -- Is known type of inventory node? if taken and def and (not def.allow_put or def.allow_put(target_pos, taken, owner)) then local dst_inv = minetest.get_inventory({type="node", pos=target_pos}) local leftover = dst_inv and dst_inv:add_item(def.put_listname, taken) if leftover and leftover:get_count() > 0 then signs_bot.bot_inv_put_item(base_pos, slot, leftover) end elseif taken then signs_bot.bot_inv_put_item(base_pos, slot, taken) end end function signs_bot.robot_peek(base_pos, robot_pos, param2, want_count, slot) local target_pos = lib.next_pos(robot_pos, param2) local node = tubelib2.get_node_lvm(target_pos) local def = RegisteredInventories[node.name] local owner = M(base_pos):get_string("owner") -- Is known type of inventory node? if def and (not def.allow_take or def.allow_take(target_pos, nil, owner)) then local src_inv = minetest.get_inventory({type="node", pos=target_pos}) -- take specified item_name from bot slot configuration OR any item from the chest local item_name = signs_bot.bot_inv_item_name(base_pos, slot) or lib.peek_inv(src_inv, def.take_listname) if item_name then return src_inv:contains_item(def.take_listname, ItemStack(item_name.." "..want_count)) end end end -- From robot to furnace function signs_bot.robot_put_fuel(base_pos, robot_pos, param2, num, slot) local target_pos = lib.next_pos(robot_pos, param2) local node = tubelib2.get_node_lvm(target_pos) local def = RegisteredInventories[node.name] local owner = M(base_pos):get_string("owner") local taken = signs_bot.bot_inv_take_item(base_pos, slot, num) -- Is known type of inventory node? if taken and def and (not def.allow_fuel or def.allow_fuel(target_pos, taken, owner)) then local dst_inv = minetest.get_inventory({type="node", pos=target_pos}) local leftover = dst_inv and dst_inv:add_item(def.fuel_listname, taken) if leftover and leftover:get_count() > 0 then signs_bot.bot_inv_put_item(base_pos, slot, leftover) end end end signs_bot.register_botcommand("take_item", { mod = "item", params = " ", num_param = 2, description = S("Take items from a chest like node\nand put it into the item inventory.\n".. " is the bot inventory slot\n(1..8) or 0 for any one"), check = function(num, slot) num = tonumber(num) or 1 if num < 1 or num > 99 then return false end slot = tonumber(slot) or 0 if slot < 0 or slot > 8 then return false end return true end, cmnd = function(base_pos, mem, num, slot) num = tonumber(num) or 1 slot = tonumber(slot) or 0 signs_bot.robot_take(base_pos, mem.robot_pos, mem.robot_param2, num, slot) return signs_bot.DONE end, }) signs_bot.register_botcommand("jump_check_item", { mod = "item", params = "