Add place commands

This commit is contained in:
Novatux 2015-01-17 17:25:13 +01:00
parent 23f2f6e3f2
commit 7462d05aa2
3 changed files with 43 additions and 4 deletions

35
api.lua
View File

@ -136,7 +136,7 @@ end
local function turtle_dig(turtle, cptr, dir)
local info = get_turtle_info(turtle)
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
cptr.X = 0
return
@ -165,6 +165,39 @@ function tl.digdown(turtle, cptr)
turtle_dig(turtle, cptr, {x = 0, y = -1, z = 0})
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)
stack = stack:to_table()
if stack==nil then return nil end

View File

@ -301,6 +301,9 @@ ITABLE_RAW = {
[0x70] = "tl.dig(turtle, cptr)",
[0x71] = "tl.digup(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)",
}

View File

@ -94,9 +94,12 @@ ASSEMBLER
: DT PLX 0x68 PHX NXT ;
: DT-UP PLX 0x69 PHX NXT ;
: DT-DN PLX 0x6a PHX NXT ;
: DIG 0x70 NXT ;
: DIG-UP 0x71 NXT ;
: DIG-DN 0x72 NXT ;
: DIG 0x70 PHX NXT ;
: DIG-UP 0x71 PHX 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 ;