mirror of
https://github.com/joe7575/techpack.git
synced 2024-12-26 15:37:30 +01:00
further commands added
This commit is contained in:
parent
94da9c8a53
commit
5e5ba05d0c
@ -25,7 +25,7 @@ sl_robot.register_action("get_ms_time", {
|
||||
|
||||
sl_robot.register_action("forward", {
|
||||
cmnd = function(self, steps)
|
||||
steps = tonumber(steps or 1)
|
||||
steps = math.min(tonumber(steps or 1), 9)
|
||||
local idx = 1
|
||||
while idx <= steps do
|
||||
local meta = minetest.get_meta(self.meta.pos)
|
||||
@ -42,7 +42,33 @@ sl_robot.register_action("forward", {
|
||||
coroutine.yield()
|
||||
end
|
||||
end,
|
||||
help = "tbd"
|
||||
help = " go one (or more) steps forward\n"..
|
||||
" Syntax: $forward(<steps>)\n"..
|
||||
" Example: $forward(4)"
|
||||
})
|
||||
|
||||
sl_robot.register_action("backward", {
|
||||
cmnd = function(self, steps)
|
||||
steps = math.min(tonumber(steps or 1), 9)
|
||||
local idx = 1
|
||||
while idx <= steps do
|
||||
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")
|
||||
local new_pos = sl_robot.move_robot(robot_pos, robot_param2, -1)
|
||||
if new_pos then -- not blocked?
|
||||
if new_pos.y == robot_pos.y then -- forward move?
|
||||
idx = idx + 1
|
||||
end
|
||||
meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
|
||||
--minetest.log("action", "[robby] forward "..meta:get_string("robot_pos"))
|
||||
end
|
||||
coroutine.yield()
|
||||
end
|
||||
end,
|
||||
help = " go one (or more) steps backward\n"..
|
||||
" Syntax: $backward(<steps>)\n"..
|
||||
" Example: $backward(4)"
|
||||
})
|
||||
|
||||
sl_robot.register_action("left", {
|
||||
@ -55,7 +81,8 @@ sl_robot.register_action("left", {
|
||||
--minetest.log("action", "[robby] left "..meta:get_string("robot_pos"))
|
||||
coroutine.yield()
|
||||
end,
|
||||
help = "tbd"
|
||||
help = " turn left\n"..
|
||||
" Example: $left()"
|
||||
})
|
||||
|
||||
sl_robot.register_action("right", {
|
||||
@ -68,7 +95,8 @@ sl_robot.register_action("right", {
|
||||
--minetest.log("action", "[robby] right "..meta:get_string("robot_pos"))
|
||||
coroutine.yield()
|
||||
end,
|
||||
help = "tbd"
|
||||
help = " turn right\n"..
|
||||
" Example: $right()"
|
||||
})
|
||||
|
||||
sl_robot.register_action("up", {
|
||||
@ -86,7 +114,8 @@ sl_robot.register_action("up", {
|
||||
--minetest.log("action", "[robby] up "..meta:get_string("robot_pos"))
|
||||
coroutine.yield()
|
||||
end,
|
||||
help = "tbd"
|
||||
help = " go one step up (2 steps max.)\n"..
|
||||
" Example: $up()"
|
||||
})
|
||||
|
||||
sl_robot.register_action("down", {
|
||||
@ -104,11 +133,15 @@ sl_robot.register_action("down", {
|
||||
--minetest.log("action", "[robby] down "..meta:get_string("robot_pos"))
|
||||
coroutine.yield()
|
||||
end,
|
||||
help = "tbd"
|
||||
help = " go down again (2 steps max.)\n"..
|
||||
" you have to go up before\n"..
|
||||
" Example: $down()"
|
||||
})
|
||||
|
||||
sl_robot.register_action("take", {
|
||||
cmnd = function(self, num, slot)
|
||||
num = math.min(tonumber(num or 1), 99)
|
||||
slot = math.min(tonumber(slot or 1), 8)
|
||||
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")
|
||||
@ -116,12 +149,18 @@ sl_robot.register_action("take", {
|
||||
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'"
|
||||
help = " take 'num' items from a chest or a node\n"..
|
||||
" with an inventory in front of the robot\n"..
|
||||
" and put the item into the own inventory,\n"..
|
||||
" specified by 'slot'.\n"..
|
||||
" Syntax: $take(num, slot)\n"..
|
||||
" Example: $take(99, 1)"
|
||||
})
|
||||
|
||||
sl_robot.register_action("add", {
|
||||
cmnd = function(self, num, slot)
|
||||
num = math.min(tonumber(num or 1), 99)
|
||||
slot = math.min(tonumber(slot or 1), 8)
|
||||
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")
|
||||
@ -129,8 +168,43 @@ sl_robot.register_action("add", {
|
||||
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"
|
||||
help = " take 'num' items from the own inventory\n"..
|
||||
" specified by 'slot' and add it to the nodes\n"..
|
||||
" inventory in front of the robot.\n"..
|
||||
" Syntax: $add(num, slot)\n"..
|
||||
" Example: $add(99, 1)"
|
||||
})
|
||||
|
||||
sl_robot.register_action("place", {
|
||||
cmnd = function(self, slot, dir)
|
||||
slot = math.min(tonumber(slot or 1), 8)
|
||||
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_place(self.meta.pos, robot_pos, robot_param2, self.meta.owner, dir, slot)
|
||||
minetest.log("action", "[robby] place "..meta:get_string("robot_pos"))
|
||||
coroutine.yield()
|
||||
end,
|
||||
help = " places an node in front of, above (up),\n"..
|
||||
" or below (down) the robot. The node is taken\n"..
|
||||
" from the own inventory, specified by 'slot'.\n"..
|
||||
' Examples: $place(1) $place(1, "U"), $place(1, "D")'
|
||||
})
|
||||
|
||||
sl_robot.register_action("dig", {
|
||||
cmnd = function(self, slot, dir)
|
||||
slot = math.min(tonumber(slot or 1), 8)
|
||||
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_dig(self.meta.pos, robot_pos, robot_param2, self.meta.owner, dir, slot)
|
||||
minetest.log("action", "[robby] dig "..meta:get_string("robot_pos"))
|
||||
coroutine.yield()
|
||||
end,
|
||||
help = " dig an node in front of, above (up),\n"..
|
||||
" or below (down) the robot. The node is placed\n"..
|
||||
" into the own inventory, specified by 'slot'.\n"..
|
||||
' Examples: $dig(1) $dig(1, "U"), $dig(1, "D")'
|
||||
})
|
||||
|
||||
sl_robot.register_action("stop", {
|
||||
|
@ -87,12 +87,6 @@ function sl_robot.new_pos(pos, param2, step)
|
||||
return vector.add(pos, vector.multiply(Face2Dir[param2], step))
|
||||
end
|
||||
|
||||
local function fake_player(name)
|
||||
return {
|
||||
get_player_name = function() return name end,
|
||||
}
|
||||
end
|
||||
|
||||
-- use Voxel Manipulator to read the node
|
||||
local function read_node_with_vm(pos)
|
||||
local vm = VoxelManip()
|
||||
@ -121,6 +115,30 @@ local function check_pos(posA, posB)
|
||||
return false
|
||||
end
|
||||
|
||||
local function fake_player(name)
|
||||
return {
|
||||
get_player_name = function() return name end,
|
||||
}
|
||||
end
|
||||
|
||||
local function place_node(pos, owner, node_name, param2)
|
||||
local under = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
minetest.set_node(pos, {name=node_name, param2=param2})
|
||||
local pointed_thing = {type="node", under=under, above=pos}
|
||||
local itemstack = ItemStack(node_name)
|
||||
pcall(minetest.after_place_node, pos, fake_player(owner), itemstack, pointed_thing)
|
||||
end
|
||||
|
||||
local function remove_node(pos)
|
||||
local node = minetest.get_node_or_nil(pos) or read_node_with_vm(pos)
|
||||
if minetest.registered_nodes[node.name].after_dig_node then
|
||||
return -- don't remove nodes with some intelligence
|
||||
end
|
||||
minetest.remove_node(pos)
|
||||
return ItemStack(node.name)
|
||||
end
|
||||
|
||||
|
||||
function sl_robot.place_robot(pos1, pos2, param2, player_name)
|
||||
if check_pos(pos1, pos2) then
|
||||
minetest.set_node(pos1, {name = "sl_robot:robot", param2 = param2})
|
||||
@ -224,15 +242,18 @@ end
|
||||
-- 2
|
||||
-- 3
|
||||
function sl_robot.robot_down(pos, param2)
|
||||
local pos1 = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local pos2 = {x=pos.x, y=pos.y-2, z=pos.z}
|
||||
local pos3 = {x=pos.x, y=pos.y-3, z=pos.z}
|
||||
local node1 = minetest.get_node_or_nil(pos1) or read_node_with_vm(pos1)
|
||||
if node1.name == "air" and check_pos(pos2, pos3) then
|
||||
minetest.remove_node(pos)
|
||||
minetest.set_node(pos2, {name="sl_robot:robot", param2=param2})
|
||||
minetest.sound_play('sl_robot_step', {pos = pos2})
|
||||
return pos2
|
||||
local pos1 = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local pos2 = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
if check_pos(pos1, pos2) then
|
||||
local node = minetest.get_node(pos2)
|
||||
if node.name == "sl_robot:robot_foot" then
|
||||
minetest.swap_node(pos, {name="sl_robot:robot_leg"})
|
||||
else
|
||||
minetest.swap_node(pos, {name="sl_robot:robot_foot"})
|
||||
end
|
||||
minetest.set_node(pos1, {name="sl_robot:robot", param2=param2})
|
||||
minetest.sound_play('sl_robot_step', {pos = pos1})
|
||||
return pos1
|
||||
end
|
||||
return nil
|
||||
end
|
||||
@ -280,6 +301,45 @@ function sl_robot.robot_add(base_pos, robot_pos, param2, owner, num, slot)
|
||||
end
|
||||
end
|
||||
|
||||
function sl_robot.robot_place(base_pos, robot_pos, param2, owner, dir, slot)
|
||||
local pos1
|
||||
if dir == "U" then
|
||||
pos1 = {x=robot_pos.x, y=robot_pos.y+1, z=robot_pos.z}
|
||||
elseif dir == "D" then
|
||||
pos1 = {x=robot_pos.x, y=robot_pos.y-1, z=robot_pos.z}
|
||||
else
|
||||
pos1 = sl_robot.new_pos(robot_pos, param2, 1)
|
||||
end
|
||||
if minetest.is_protected(pos1, owner) then
|
||||
return
|
||||
end
|
||||
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(1)
|
||||
if taken then
|
||||
place_node(pos1, owner, taken:get_name(), param2)
|
||||
end
|
||||
end
|
||||
|
||||
function sl_robot.robot_dig(base_pos, robot_pos, param2, owner, dir, slot)
|
||||
local pos1
|
||||
if dir == "U" then
|
||||
pos1 = {x=robot_pos.x, y=robot_pos.y+1, z=robot_pos.z}
|
||||
elseif dir == "D" then
|
||||
pos1 = {x=robot_pos.x, y=robot_pos.y-1, z=robot_pos.z}
|
||||
else
|
||||
pos1 = sl_robot.new_pos(robot_pos, param2, 1)
|
||||
end
|
||||
if minetest.is_protected(pos1, owner) then
|
||||
return
|
||||
end
|
||||
local item = remove_node(pos1)
|
||||
if item then
|
||||
local src_inv = minetest.get_inventory({type="node", pos=base_pos})
|
||||
local src_list = src_inv:get_list("main")
|
||||
src_list[slot]:add_item(item)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("sl_robot:robot", {
|
||||
description = "SaferLua Robot",
|
||||
|
Loading…
Reference in New Issue
Block a user