Add place commands
This commit is contained in:
parent
23f2f6e3f2
commit
7462d05aa2
35
api.lua
35
api.lua
@ -136,7 +136,7 @@ end
|
|||||||
local function turtle_dig(turtle, cptr, dir)
|
local function turtle_dig(turtle, cptr, dir)
|
||||||
local info = get_turtle_info(turtle)
|
local info = get_turtle_info(turtle)
|
||||||
local dpos = vector.add(info.spos, dir)
|
local dpos = vector.add(info.spos, dir)
|
||||||
local dnode = minetest.env:get_node(dpos)
|
local dnode = minetest.get_node(dpos)
|
||||||
if turtle_can_go(dnode.name) or dnode.name == "ignore" then
|
if turtle_can_go(dnode.name) or dnode.name == "ignore" then
|
||||||
cptr.X = 0
|
cptr.X = 0
|
||||||
return
|
return
|
||||||
@ -165,6 +165,39 @@ function tl.digdown(turtle, cptr)
|
|||||||
turtle_dig(turtle, cptr, {x = 0, y = -1, z = 0})
|
turtle_dig(turtle, cptr, {x = 0, y = -1, z = 0})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function turtle_place(turtle, cptr, dir, slot)
|
||||||
|
local info = get_turtle_info(turtle)
|
||||||
|
local ppos = vector.add(info.spos, dir)
|
||||||
|
local dnode = minetest.get_node(ppos)
|
||||||
|
if (not turtle_can_go(dnode.name)) or dnode.name == "ignore" then
|
||||||
|
cptr.X = 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local stack = turtle_invs:get_stack(turtle, slot)
|
||||||
|
if stack:is_empty() or minetest.registered_nodes[stack:get_name()] == nil then
|
||||||
|
cptr.X = 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
minetest.set_node(ppos, {name=stack:get_name()})
|
||||||
|
stack:take_item()
|
||||||
|
turtle_invs:set_stack(turtle, slot, stack)
|
||||||
|
cptr.X = u16(-1)
|
||||||
|
cptr.paused = true
|
||||||
|
end
|
||||||
|
|
||||||
|
function tl.place(turtle, cptr, slot)
|
||||||
|
local info = get_turtle_info(turtle)
|
||||||
|
turtle_place(turtle, cptr, getv(info.dir), slot)
|
||||||
|
end
|
||||||
|
|
||||||
|
function tl.placeup(turtle, cptr, slot)
|
||||||
|
turtle_place(turtle, cptr, {x = 0, y = 1, z = 0}, slot)
|
||||||
|
end
|
||||||
|
|
||||||
|
function tl.placedown(turtle, cptr, slot)
|
||||||
|
turtle_place(turtle, cptr, {x = 0, y = -1, z = 0}, slot)
|
||||||
|
end
|
||||||
|
|
||||||
local function stack_set_count(stack, count)
|
local function stack_set_count(stack, count)
|
||||||
stack = stack:to_table()
|
stack = stack:to_table()
|
||||||
if stack==nil then return nil end
|
if stack==nil then return nil end
|
||||||
|
3
cptr.lua
3
cptr.lua
@ -301,6 +301,9 @@ ITABLE_RAW = {
|
|||||||
[0x70] = "tl.dig(turtle, cptr)",
|
[0x70] = "tl.dig(turtle, cptr)",
|
||||||
[0x71] = "tl.digup(turtle, cptr)",
|
[0x71] = "tl.digup(turtle, cptr)",
|
||||||
[0x72] = "tl.digdown(turtle, cptr)",
|
[0x72] = "tl.digdown(turtle, cptr)",
|
||||||
|
[0x74] = "tl.place(turtle, cptr, cptr.X)",
|
||||||
|
[0x75] = "tl.placeup(turtle, cptr, cptr.X)",
|
||||||
|
[0x76] = "tl.placedown(turtle, cptr, cptr.X)",
|
||||||
|
|
||||||
[0x80] = "tl.refuel(turtle, cptr, cptr.X, cptr.Y)",
|
[0x80] = "tl.refuel(turtle, cptr, cptr.X, cptr.Y)",
|
||||||
}
|
}
|
||||||
|
@ -94,9 +94,12 @@ ASSEMBLER
|
|||||||
: DT PLX 0x68 PHX NXT ;
|
: DT PLX 0x68 PHX NXT ;
|
||||||
: DT-UP PLX 0x69 PHX NXT ;
|
: DT-UP PLX 0x69 PHX NXT ;
|
||||||
: DT-DN PLX 0x6a PHX NXT ;
|
: DT-DN PLX 0x6a PHX NXT ;
|
||||||
: DIG 0x70 NXT ;
|
: DIG 0x70 PHX NXT ;
|
||||||
: DIG-UP 0x71 NXT ;
|
: DIG-UP 0x71 PHX NXT ;
|
||||||
: DIG-DN 0x72 NXT ;
|
: DIG-DN 0x72 PHX NXT ;
|
||||||
|
: PLACE PLX 0x74 PHX NXT ;
|
||||||
|
: PLACE-UP PLX 0x75 PHX NXT ;
|
||||||
|
: PLACE-DN PLX 0x76 PHX NXT ;
|
||||||
|
|
||||||
: REFUEL PLY PLX 0x80 PHX NXT ;
|
: REFUEL PLY PLX 0x80 PHX NXT ;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user