reuse period/offset markers for intermittent diggers

This commit is contained in:
FaceDeer 2017-09-19 23:25:11 -06:00
parent 3bc0eb82fa
commit 04228904f5
3 changed files with 35 additions and 28 deletions

@ -123,33 +123,7 @@ minetest.register_node("digtron:builder", {
end end
if fields.set then if fields.set then
local buildpos = digtron.find_new_pos(pos, minetest.get_node(pos).param2) digtron.show_offset_markers(pos, offset, period)
local x_pos = math.floor((buildpos.x+offset)/period)*period - offset
minetest.add_entity({x=x_pos, y=buildpos.y, z=buildpos.z}, "digtron:marker")
if x_pos >= buildpos.x then
minetest.add_entity({x=x_pos - period, y=buildpos.y, z=buildpos.z}, "digtron:marker")
end
if x_pos <= buildpos.x then
minetest.add_entity({x=x_pos + period, y=buildpos.y, z=buildpos.z}, "digtron:marker")
end
local y_pos = math.floor((buildpos.y+offset)/period)*period - offset
minetest.add_entity({x=buildpos.x, y=y_pos, z=buildpos.z}, "digtron:marker_vertical")
if y_pos >= buildpos.y then
minetest.add_entity({x=buildpos.x, y=y_pos - period, z=buildpos.z}, "digtron:marker_vertical")
end
if y_pos <= buildpos.y then
minetest.add_entity({x=buildpos.x, y=y_pos + period, z=buildpos.z}, "digtron:marker_vertical")
end
local z_pos = math.floor((buildpos.z+offset)/period)*period - offset
minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker"):setyaw(1.5708)
if z_pos >= buildpos.z then
minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker"):setyaw(1.5708)
end
if z_pos <= buildpos.z then
minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker"):setyaw(1.5708)
end
elseif fields.read then elseif fields.read then
local facing = minetest.get_node(pos).param2 local facing = minetest.get_node(pos).param2

@ -33,7 +33,7 @@ local intermittent_formspec =
"tooltip[period;" .. S("Digger will dig once every n steps.\nThese steps are globally aligned, all diggers with\nthe same period and offset will dig on the same location.") .. "]" .. "tooltip[period;" .. S("Digger will dig once every n steps.\nThese steps are globally aligned, all diggers with\nthe same period and offset will dig on the same location.") .. "]" ..
"field[1.5,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" .. "field[1.5,0.8;1,0.1;offset;" .. S("Offset") .. ";${offset}]" ..
"tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a digger with period 2 and offset 0 digs\nevery even-numbered block and one with period 2 and\noffset 1 digs every odd-numbered block.") .. "]" .. "tooltip[offset;" .. S("Offsets the start of periodicity counting by this amount.\nFor example, a digger with period 2 and offset 0 digs\nevery even-numbered block and one with period 2 and\noffset 1 digs every odd-numbered block.") .. "]" ..
"button_exit[2.2,0.5;1,0.1;set;" .. S("Save") .. "]" .. "button_exit[2.2,0.5;1,0.1;set;" .. S("Save &\nShow") .. "]" ..
"tooltip[set;" .. S("Saves settings") .. "]" "tooltip[set;" .. S("Saves settings") .. "]"
if minetest.get_modpath("doc") then if minetest.get_modpath("doc") then
@ -65,6 +65,9 @@ local intermittent_on_receive_fields = function(pos, formname, fields, sender)
local node_name = minetest.get_node(pos).name local node_name = minetest.get_node(pos).name
minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", node_name, true) minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", node_name, true)
end end
if fields.set then
digtron.show_offset_markers(pos, offset, period)
end
end, end,
-- Digs out nodes that are "in front" of the digger head. -- Digs out nodes that are "in front" of the digger head.

@ -241,3 +241,33 @@ digtron.is_soft_material = function(target)
end end
return false return false
end end
digtron.show_offset_markers = function(pos, offset, period)
local buildpos = digtron.find_new_pos(pos, minetest.get_node(pos).param2)
local x_pos = math.floor((buildpos.x+offset)/period)*period - offset
minetest.add_entity({x=x_pos, y=buildpos.y, z=buildpos.z}, "digtron:marker")
if x_pos >= buildpos.x then
minetest.add_entity({x=x_pos - period, y=buildpos.y, z=buildpos.z}, "digtron:marker")
end
if x_pos <= buildpos.x then
minetest.add_entity({x=x_pos + period, y=buildpos.y, z=buildpos.z}, "digtron:marker")
end
local y_pos = math.floor((buildpos.y+offset)/period)*period - offset
minetest.add_entity({x=buildpos.x, y=y_pos, z=buildpos.z}, "digtron:marker_vertical")
if y_pos >= buildpos.y then
minetest.add_entity({x=buildpos.x, y=y_pos - period, z=buildpos.z}, "digtron:marker_vertical")
end
if y_pos <= buildpos.y then
minetest.add_entity({x=buildpos.x, y=y_pos + period, z=buildpos.z}, "digtron:marker_vertical")
end
local z_pos = math.floor((buildpos.z+offset)/period)*period - offset
minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos}, "digtron:marker"):setyaw(1.5708)
if z_pos >= buildpos.z then
minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos - period}, "digtron:marker"):setyaw(1.5708)
end
if z_pos <= buildpos.z then
minetest.add_entity({x=buildpos.x, y=buildpos.y, z=z_pos + period}, "digtron:marker"):setyaw(1.5708)
end
end