Allow turtle to dig.
This commit is contained in:
parent
13a946a868
commit
e9af014dd8
97
api.lua
97
api.lua
@ -2,6 +2,78 @@ local MOVE_COST = 100
|
||||
local FUEL_EFFICIENCY = 300
|
||||
tl = {}
|
||||
|
||||
local function delay(x)
|
||||
return function() return x end
|
||||
end
|
||||
|
||||
local function create_turtle_player(turtle_id, dir)
|
||||
local info = turtles.get_turtle_info(turtle_id)
|
||||
local inv = turtles.get_turtle_inventory(turtle_id)
|
||||
local under_pos = vector.add(info.spos, dir)
|
||||
local above_pos = vector.add(under_pos, dir)
|
||||
local pitch
|
||||
local yaw
|
||||
if dir.z > 0 then
|
||||
yaw = 0
|
||||
pitch = 0
|
||||
elseif dir.z < 0 then
|
||||
yaw = math.pi
|
||||
pitch = 0
|
||||
elseif dir.x > 0 then
|
||||
yaw = 3*math.pi/2
|
||||
pitch = 0
|
||||
elseif dir.x < 0 then
|
||||
yaw = math.pi/2
|
||||
pitch = 0
|
||||
elseif dir.y > 0 then
|
||||
yaw = 0
|
||||
pitch = -math.pi/2
|
||||
else
|
||||
yaw = 0
|
||||
pitch = math.pi/2
|
||||
end
|
||||
local player = {
|
||||
get_inventory_formspec = delay(""), -- TODO
|
||||
get_look_dir = delay(vector.new(dir)),
|
||||
get_look_pitch = delay(pitch),
|
||||
get_look_yaw = delay(yaw),
|
||||
get_player_control = delay({jump = false, right = false, left = false, LMB = false, RMB = false, sneak = false, aux1 = false, down = false, up = false}),
|
||||
get_player_control_bits = delay(0),
|
||||
get_player_name = delay("turtle:" .. tostring(turtle_id)),
|
||||
is_player = delay(true),
|
||||
is_turtle = true,
|
||||
set_inventory_formspec = delay(),
|
||||
getpos = function() vector.subtract(info.spos, {x = 0, y = 1.5, z = 0}) end,
|
||||
get_hp = delay(20),
|
||||
get_inventory = function() return turtles.get_turtle_inventory(turtle_id) end,
|
||||
get_wielded_item = function() return turtles.get_turtle_inventory(turtle_id):get_stack("main", info.wield_index or 1) end,
|
||||
get_wield_index = function() return info.wield_index or 1 end,
|
||||
get_wield_list = delay("main"),
|
||||
moveto = delay(), -- TODO
|
||||
punch = delay(),
|
||||
remove = delay(),
|
||||
right_click = delay(), -- TODO
|
||||
setpos = delay(), -- TODO
|
||||
set_hp = delay(),
|
||||
set_properties = delay(),
|
||||
set_wielded_item = function(self, item)
|
||||
turtles.get_turtle_inventory(turtle_id):set_stack("main", info.wield_index or 1, item)
|
||||
end,
|
||||
set_animation = delay(),
|
||||
set_attach = delay(), -- TODO???
|
||||
set_detach = delay(),
|
||||
set_bone_position = delay(),
|
||||
}
|
||||
local pointed_thing = {type = "node", under = under_pos, above = above_pos}
|
||||
return player, pointed_thing
|
||||
end
|
||||
|
||||
function tl.select(turtle, cptr, slot)
|
||||
if 1 <= slot and slot < turtles.get_turtle_inventory(turtle):get_size("main") then
|
||||
turtles.get_turtle_info(turtle).wield_index = slot
|
||||
end
|
||||
end
|
||||
|
||||
local function tl_move(turtle, cptr, dir)
|
||||
local info = turtles.get_turtle_info(turtle)
|
||||
if info.energy < MOVE_COST then
|
||||
@ -84,7 +156,16 @@ function tl.detectdown(turtle, cptr)
|
||||
end
|
||||
|
||||
local function turtle_dig(turtle, cptr, dir)
|
||||
-- TODO
|
||||
local player, pointed_thing = create_turtle_player(turtle, dir)
|
||||
local wieldstack = player:get_wielded_item()
|
||||
local on_use = (minetest.registered_items[wieldstack:get_name()] or {}).on_use
|
||||
if on_use then
|
||||
player:set_wielded_item(on_use(wieldstack, player, pointed_thing) or wieldstack)
|
||||
else
|
||||
local under_node = minetest.get_node(pointed_thing.under)
|
||||
local on_dig = (minetest.registered_nodes[under_node.name] or {on_dig = minetest.node_dig}).on_dig
|
||||
on_dig(pointed_thing.under, under_node, player)
|
||||
end
|
||||
end
|
||||
|
||||
function tl.dig(turtle, cptr)
|
||||
@ -100,21 +181,21 @@ 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 function turtle_place(turtle, cptr, dir)
|
||||
-- TODO
|
||||
end
|
||||
|
||||
function tl.place(turtle, cptr, slot)
|
||||
function tl.place(turtle, cptr)
|
||||
local info = turtles.get_turtle_info(turtle)
|
||||
turtle_place(turtle, cptr, minetest.facedir_to_dir(info.dir), slot)
|
||||
turtle_place(turtle, cptr, minetest.facedir_to_dir(info.dir))
|
||||
end
|
||||
|
||||
function tl.placeup(turtle, cptr, slot)
|
||||
turtle_place(turtle, cptr, {x = 0, y = 1, z = 0}, slot)
|
||||
function tl.placeup(turtle, cptr)
|
||||
turtle_place(turtle, cptr, {x = 0, y = 1, z = 0})
|
||||
end
|
||||
|
||||
function tl.placedown(turtle, cptr, slot)
|
||||
turtle_place(turtle, cptr, {x = 0, y = -1, z = 0}, slot)
|
||||
function tl.placedown(turtle, cptr)
|
||||
turtle_place(turtle, cptr, {x = 0, y = -1, z = 0})
|
||||
end
|
||||
|
||||
local function stack_set_count(stack, count)
|
||||
|
7
cptr.lua
7
cptr.lua
@ -301,11 +301,12 @@ 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)",
|
||||
[0x74] = "tl.place(turtle, cptr)",
|
||||
[0x75] = "tl.placeup(turtle, cptr)",
|
||||
[0x76] = "tl.placedown(turtle, cptr)",
|
||||
|
||||
[0x80] = "tl.refuel(turtle, cptr, cptr.X, cptr.Y)",
|
||||
[0x81] = "tl.select(turtle, cptr, cptr.X)"
|
||||
}
|
||||
|
||||
ITABLE = {}
|
||||
|
13
forth.fth
13
forth.fth
@ -94,14 +94,15 @@ ASSEMBLER
|
||||
: DT PLX 0x68 PHX NXT ;
|
||||
: DT-UP PLX 0x69 PHX NXT ;
|
||||
: DT-DN PLX 0x6a PHX 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 ;
|
||||
: DIG 0x70 NXT ;
|
||||
: DIG-UP 0x71 NXT ;
|
||||
: DIG-DN 0x72 NXT ;
|
||||
: PLACE 0x74 NXT ;
|
||||
: PLACE-UP 0x75 NXT ;
|
||||
: PLACE-DN 0x76 NXT ;
|
||||
|
||||
: REFUEL PLY PLX 0x80 PHX NXT ;
|
||||
: SELECT
|
||||
|
||||
ENVIRONMENT
|
||||
256 CONSTANT /COUNTED-STRING
|
||||
|
File diff suppressed because one or more lines are too long
9
t2.lua
9
t2.lua
@ -217,6 +217,7 @@ minetest.register_node("turtle:turtle", {
|
||||
info.spos = vector.new(pos)
|
||||
info.dir = 0
|
||||
info.energy = 0
|
||||
info.wield_index = 1
|
||||
info.screen = screen.new()
|
||||
info.cptr = create_cptr()
|
||||
info.playernames = {}
|
||||
@ -225,6 +226,13 @@ minetest.register_node("turtle:turtle", {
|
||||
info.turtle = le
|
||||
le.turtle_id = id
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
local turtle_id = minetest.get_meta(pos):get_int("turtle_id")
|
||||
local info = turtles.get_turtle_info(turtle_id)
|
||||
local name = clicker:get_player_name()
|
||||
info.playernames[name] = true
|
||||
minetest.show_formspec(name, "turtle:" .. tostring(turtle_id), info.formspec)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("turtle:turtle2", {
|
||||
@ -233,6 +241,7 @@ minetest.register_node("turtle:turtle2", {
|
||||
drawtype = "airlike",
|
||||
walkable = false,
|
||||
pointable = false,
|
||||
sunlight_propagates = true,
|
||||
})
|
||||
|
||||
local function done_move(pos, spos, npos)
|
||||
|
Loading…
x
Reference in New Issue
Block a user