mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 23:33:44 +01:00
robby take/add commands added
This commit is contained in:
parent
49f6c8c13a
commit
94da9c8a53
@ -103,6 +103,17 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
|
|||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
if minetest.is_protected(pos, player:get_player_name()) then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if meta:get_int("state") == tubelib.RUNNING then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
local function formspec1(meta)
|
local function formspec1(meta)
|
||||||
local running = meta:get_int("state") == tubelib.RUNNING
|
local running = meta:get_int("state") == tubelib.RUNNING
|
||||||
local cmnd = running and "stop;Stop" or "start;Start"
|
local cmnd = running and "stop;Stop" or "start;Start"
|
||||||
@ -233,7 +244,7 @@ local function reset_robot(pos, meta)
|
|||||||
minetest.log("action", "[robby] reset_robot "..meta:get_string("robot_pos"))
|
minetest.log("action", "[robby] reset_robot "..meta:get_string("robot_pos"))
|
||||||
|
|
||||||
if robot_pos then
|
if robot_pos then
|
||||||
minetest.after(5, minetest.remove_node, robot_pos)
|
minetest.after(5, minetest.remove_node, table.copy(robot_pos))
|
||||||
end
|
end
|
||||||
|
|
||||||
local param2 = (minetest.get_node(pos).param2 + 1) % 4
|
local param2 = (minetest.get_node(pos).param2 + 1) % 4
|
||||||
@ -436,6 +447,7 @@ minetest.register_node("sl_robot:base", {
|
|||||||
on_timer = on_timer,
|
on_timer = on_timer,
|
||||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||||
|
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
|
@ -37,10 +37,7 @@ sl_robot.register_action("forward", {
|
|||||||
idx = idx + 1
|
idx = idx + 1
|
||||||
end
|
end
|
||||||
meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
|
meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
|
||||||
minetest.log("action", "[robby] forward "..meta:get_string("robot_pos"))
|
--minetest.log("action", "[robby] forward "..meta:get_string("robot_pos"))
|
||||||
else -- blocked
|
|
||||||
-- because of unloaded areas and the LBM replace blocked robots
|
|
||||||
--minetest.set_node(robot_pos, {name = "sl_robot:robot_dummy", param2 = robot_param2})
|
|
||||||
end
|
end
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
@ -55,7 +52,7 @@ sl_robot.register_action("left", {
|
|||||||
local robot_param2 = meta:get_int("robot_param2")
|
local robot_param2 = meta:get_int("robot_param2")
|
||||||
robot_param2 = sl_robot.turn_robot(robot_pos, robot_param2, "L")
|
robot_param2 = sl_robot.turn_robot(robot_pos, robot_param2, "L")
|
||||||
meta:set_int("robot_param2", robot_param2)
|
meta:set_int("robot_param2", robot_param2)
|
||||||
minetest.log("action", "[robby] left "..meta:get_string("robot_pos"))
|
--minetest.log("action", "[robby] left "..meta:get_string("robot_pos"))
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end,
|
end,
|
||||||
help = "tbd"
|
help = "tbd"
|
||||||
@ -68,7 +65,7 @@ sl_robot.register_action("right", {
|
|||||||
local robot_param2 = meta:get_int("robot_param2")
|
local robot_param2 = meta:get_int("robot_param2")
|
||||||
robot_param2 = sl_robot.turn_robot(robot_pos, robot_param2, "R")
|
robot_param2 = sl_robot.turn_robot(robot_pos, robot_param2, "R")
|
||||||
meta:set_int("robot_param2", robot_param2)
|
meta:set_int("robot_param2", robot_param2)
|
||||||
minetest.log("action", "[robby] right "..meta:get_string("robot_pos"))
|
--minetest.log("action", "[robby] right "..meta:get_string("robot_pos"))
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end,
|
end,
|
||||||
help = "tbd"
|
help = "tbd"
|
||||||
@ -86,7 +83,7 @@ sl_robot.register_action("up", {
|
|||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
|
meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
|
||||||
minetest.log("action", "[robby] up "..meta:get_string("robot_pos"))
|
--minetest.log("action", "[robby] up "..meta:get_string("robot_pos"))
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end,
|
end,
|
||||||
help = "tbd"
|
help = "tbd"
|
||||||
@ -104,12 +101,38 @@ sl_robot.register_action("down", {
|
|||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
|
meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
|
||||||
minetest.log("action", "[robby] down "..meta:get_string("robot_pos"))
|
--minetest.log("action", "[robby] down "..meta:get_string("robot_pos"))
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end,
|
end,
|
||||||
help = "tbd"
|
help = "tbd"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
sl_robot.register_action("take", {
|
||||||
|
cmnd = function(self, num, slot)
|
||||||
|
local meta = minetest.get_meta(self.meta.pos)
|
||||||
|
local robot_pos = minetest.string_to_pos(meta:get_string("robot_pos"))
|
||||||
|
local robot_param2 = meta:get_int("robot_param2")
|
||||||
|
sl_robot.robot_take(self.meta.pos, robot_pos, robot_param2, self.meta.owner, num, slot)
|
||||||
|
minetest.log("action", "[robby] take "..meta:get_string("robot_pos"))
|
||||||
|
coroutine.yield()
|
||||||
|
end,
|
||||||
|
help = "take 'num' items from the nodes inventory\n"..
|
||||||
|
"in front of the robot and put into the own 'slot'"
|
||||||
|
})
|
||||||
|
|
||||||
|
sl_robot.register_action("add", {
|
||||||
|
cmnd = function(self, num, slot)
|
||||||
|
local meta = minetest.get_meta(self.meta.pos)
|
||||||
|
local robot_pos = minetest.string_to_pos(meta:get_string("robot_pos"))
|
||||||
|
local robot_param2 = meta:get_int("robot_param2")
|
||||||
|
sl_robot.robot_add(self.meta.pos, robot_pos, robot_param2, self.meta.owner, num, slot)
|
||||||
|
minetest.log("action", "[robby] add "..meta:get_string("robot_pos"))
|
||||||
|
coroutine.yield()
|
||||||
|
end,
|
||||||
|
help = "take 'num' items from the own 'slot' and\n"..
|
||||||
|
"add to the nodes inventory in front of the robot"
|
||||||
|
})
|
||||||
|
|
||||||
sl_robot.register_action("stop", {
|
sl_robot.register_action("stop", {
|
||||||
cmnd = function(self)
|
cmnd = function(self)
|
||||||
while true do
|
while true do
|
||||||
|
@ -21,10 +21,78 @@ local Face2Dir = {[0]=
|
|||||||
{x=0, y=1, z=0}
|
{x=0, y=1, z=0}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local Inventories = {
|
||||||
|
["default:chest"] = {take = "main", add = "main", fuel = "main"},
|
||||||
|
["default:chest_locked"] = {take = "main", add = "main", fuel = "main"},
|
||||||
|
["default:chest_locked"] = {take = "main", add = "main", fuel = "main"},
|
||||||
|
["default:furnace"] = {take = "dst", add = "src", fuel = "fuel"},
|
||||||
|
["default:furnace_active"] = {take = "dst", add = "src", fuel = "fuel"},
|
||||||
|
["tubelib:distributor"] = {take = "src", add = "src", fuel = "src"},
|
||||||
|
["gravelsieve:sieve"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["gravelsieve:auto_sieve0"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["gravelsieve:auto_sieve1"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["gravelsieve:auto_sieve2"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["gravelsieve:auto_sieve3"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["tubelib_addons1:autocrafter"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["tubelib_addons1:autocrafter_active"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["tubelib_addons1:chest"] = {take = "main", add = "main", fuel = "main"},
|
||||||
|
["tubelib_addons1:fermenter"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["tubelib_addons1:reformer"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["tubelib_addons1:funnel"] = {take = "main", add = "main", fuel = "main"},
|
||||||
|
["tubelib_addons1:grinder"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["tubelib_addons1:grinder_active"] = {take = "dst", add = "src", fuel = "src"},
|
||||||
|
["tubelib_addons1:harvester_base"] = {take = "main", add = "main", fuel = "fuel"},
|
||||||
|
["tubelib_addons1:quarry"] = {take = "main", add = "main", fuel = "fuel"},
|
||||||
|
["tubelib_addons1:quarry_active"] = {take = "main", add = "main", fuel = "fuel"},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
-- [""] = {take = "", add = "", fuel = ""},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- return the largest stack
|
||||||
|
local function peek(src_list)
|
||||||
|
local max_val = 0
|
||||||
|
local slot = nil
|
||||||
|
for idx,stack in ipairs(src_list) do
|
||||||
|
if stack:get_count() > max_val then
|
||||||
|
max_val = stack:get_count()
|
||||||
|
slot = idx
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return slot
|
||||||
|
end
|
||||||
|
|
||||||
|
-- try to take the number of items from an inventory
|
||||||
|
local function take_num_items(src_list, num, dst_stack)
|
||||||
|
local slot = peek(src_list)
|
||||||
|
if slot then
|
||||||
|
local taken = src_list[slot]:take_item(num)
|
||||||
|
if dst_stack:item_fits(taken) then
|
||||||
|
dst_stack:add_item(taken)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function sl_robot.new_pos(pos, param2, step)
|
function sl_robot.new_pos(pos, param2, step)
|
||||||
return vector.add(pos, vector.multiply(Face2Dir[param2], step))
|
return vector.add(pos, vector.multiply(Face2Dir[param2], step))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function fake_player(name)
|
||||||
|
return {
|
||||||
|
get_player_name = function() return name end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
-- use Voxel Manipulator to read the node
|
-- use Voxel Manipulator to read the node
|
||||||
local function read_node_with_vm(pos)
|
local function read_node_with_vm(pos)
|
||||||
local vm = VoxelManip()
|
local vm = VoxelManip()
|
||||||
@ -169,6 +237,49 @@ function sl_robot.robot_down(pos, param2)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- take items from another inventory and put it into the own inventory slot
|
||||||
|
function sl_robot.robot_take(base_pos, robot_pos, param2, owner, num, slot)
|
||||||
|
local pos1 = sl_robot.new_pos(robot_pos, param2, 1)
|
||||||
|
if minetest.is_protected(pos1, owner) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local node = minetest.get_node(pos1)
|
||||||
|
if Inventories[node.name] then
|
||||||
|
local listname = Inventories[node.name].take
|
||||||
|
local src_inv = minetest.get_inventory({type="node", pos=pos1})
|
||||||
|
if src_inv:is_empty(listname) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local src_list = src_inv:get_list(listname)
|
||||||
|
local dst_inv = minetest.get_inventory({type="node", pos=base_pos})
|
||||||
|
local dst_list = dst_inv:get_list("main")
|
||||||
|
if take_num_items(src_list, num, dst_list[slot]) then
|
||||||
|
src_inv:set_list(listname, src_list)
|
||||||
|
dst_inv:set_list("main", dst_list)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function sl_robot.robot_add(base_pos, robot_pos, param2, owner, num, slot)
|
||||||
|
local pos1 = sl_robot.new_pos(robot_pos, param2, 1)
|
||||||
|
if minetest.is_protected(pos1, owner) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local node = minetest.get_node(pos1)
|
||||||
|
if Inventories[node.name] then
|
||||||
|
local listname = Inventories[node.name].take
|
||||||
|
local dst_inv = minetest.get_inventory({type="node", pos=pos1})
|
||||||
|
local dst_list = dst_inv:get_list(listname)
|
||||||
|
local src_inv = minetest.get_inventory({type="node", pos=base_pos})
|
||||||
|
local src_list = src_inv:get_list("main")
|
||||||
|
local taken = src_list[slot]:take_item(num)
|
||||||
|
if dst_inv:room_for_item(listname, taken) then
|
||||||
|
dst_inv:add_item(listname, taken)
|
||||||
|
src_inv:set_list("main", src_list)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("sl_robot:robot", {
|
minetest.register_node("sl_robot:robot", {
|
||||||
description = "SaferLua Robot",
|
description = "SaferLua Robot",
|
||||||
@ -198,37 +309,6 @@ minetest.register_node("sl_robot:robot", {
|
|||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
---- dummy robots are used as marker for stucked robots in unloaded areas
|
|
||||||
--minetest.register_node("sl_robot:robot_dummy", {
|
|
||||||
-- description = "SaferLua Robot",
|
|
||||||
-- -- up, down, right, left, back, front
|
|
||||||
-- tiles = {
|
|
||||||
-- "sl_robot_robot_top.png^[opacity:127",
|
|
||||||
-- "sl_robot_robot_bottom.png^[opacity:127",
|
|
||||||
-- "sl_robot_robot_right.png^[opacity:127",
|
|
||||||
-- "sl_robot_robot_left.png^[opacity:127",
|
|
||||||
-- "sl_robot_robot_front.png^[opacity:127",
|
|
||||||
-- "sl_robot_robot_back.png^[opacity:127",
|
|
||||||
-- },
|
|
||||||
-- drawtype = "nodebox",
|
|
||||||
-- use_texture_alpha = true,
|
|
||||||
-- node_box = {
|
|
||||||
-- type = "fixed",
|
|
||||||
-- fixed = {
|
|
||||||
-- { -5/16, 3/16, -5/16, 5/16, 8/16, 5/16},
|
|
||||||
-- { -3/16, 2/16, -3/16, 3/16, 3/16, 3/16},
|
|
||||||
-- { -6/16, -7/16, -6/16, 6/16, 2/16, 6/16},
|
|
||||||
-- { -6/16, -8/16, -3/16, 6/16, -7/16, 3/16},
|
|
||||||
-- },
|
|
||||||
-- },
|
|
||||||
-- paramtype2 = "facedir",
|
|
||||||
-- is_ground_content = false,
|
|
||||||
-- walkable = false,
|
|
||||||
-- drop = "",
|
|
||||||
-- groups = {cracky = 3},
|
|
||||||
-- sounds = default.node_sound_metal_defaults(),
|
|
||||||
--})
|
|
||||||
|
|
||||||
minetest.register_node("sl_robot:robot_leg", {
|
minetest.register_node("sl_robot:robot_leg", {
|
||||||
description = "SaferLua Robot",
|
description = "SaferLua Robot",
|
||||||
tiles = {"sl_robot_robot.png^[transformR90]"},
|
tiles = {"sl_robot_robot.png^[transformR90]"},
|
||||||
@ -262,18 +342,3 @@ minetest.register_node("sl_robot:robot_foot", {
|
|||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
--minetest.register_lbm({
|
|
||||||
-- label = "[sl_robot] Remove Robots",
|
|
||||||
-- name = "sl_robot:update",
|
|
||||||
-- nodenames = {"sl_robot:robot", "sl_robot:robot_leg", "sl_robot:robot_foot"},
|
|
||||||
-- run_at_every_load = true,
|
|
||||||
-- action = function(pos, node)
|
|
||||||
-- if node.name == "sl_robot:robot" then
|
|
||||||
-- minetest.swap_node(pos, {name="sl_robot:robot_dummy", param2 = node.param2})
|
|
||||||
-- else
|
|
||||||
-- minetest.remove_node(pos)
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
--})
|
|
||||||
|
|
||||||
|
@ -325,6 +325,7 @@ tubelib.add_grinder_recipe({input="default:cobble", output="default:gravel"})
|
|||||||
tubelib.add_grinder_recipe({input="default:desert_cobble", output="default:gravel"})
|
tubelib.add_grinder_recipe({input="default:desert_cobble", output="default:gravel"})
|
||||||
tubelib.add_grinder_recipe({input="default:mossycobble", output="default:gravel"})
|
tubelib.add_grinder_recipe({input="default:mossycobble", output="default:gravel"})
|
||||||
tubelib.add_grinder_recipe({input="default:gravel", output="default:sand"})
|
tubelib.add_grinder_recipe({input="default:gravel", output="default:sand"})
|
||||||
|
tubelib.add_grinder_recipe({input="default:coral_skeleton", output="default:silver_sand"})
|
||||||
|
|
||||||
if minetest.global_exists("skytest") then
|
if minetest.global_exists("skytest") then
|
||||||
tubelib.add_grinder_recipe({input="default:desert_sand", output="skytest:dust"})
|
tubelib.add_grinder_recipe({input="default:desert_sand", output="skytest:dust"})
|
||||||
|
Loading…
Reference in New Issue
Block a user