summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFaceDeer <derksenmobile@gmail.com>2017-09-19 23:25:11 -0600
committerFaceDeer <derksenmobile@gmail.com>2017-09-19 23:25:11 -0600
commit04228904f52214d508831b8df28adcab28e88ae8 (patch)
tree2075b3cdd8de0bdf18ee8ad3e1dc389cbe34bef8
parent3bc0eb82fa4796c32b6800e5833953262f8e0b0c (diff)
reuse period/offset markers for intermittent diggers
-rw-r--r--nodes/node_builders.lua28
-rw-r--r--nodes/node_diggers.lua5
-rw-r--r--util.lua30
3 files changed, 35 insertions, 28 deletions
diff --git a/nodes/node_builders.lua b/nodes/node_builders.lua
index fac1d4b..bfd7c00 100644
--- a/nodes/node_builders.lua
+++ b/nodes/node_builders.lua
@@ -123,33 +123,7 @@ minetest.register_node("digtron:builder", {
end
if fields.set then
- 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
+ digtron.show_offset_markers(pos, offset, period)
elseif fields.read then
local facing = minetest.get_node(pos).param2
diff --git a/nodes/node_diggers.lua b/nodes/node_diggers.lua
index 78d5200..bf48f71 100644
--- a/nodes/node_diggers.lua
+++ b/nodes/node_diggers.lua
@@ -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.") .. "]" ..
"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.") .. "]" ..
- "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") .. "]"
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
minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", node_name, true)
end
+ if fields.set then
+ digtron.show_offset_markers(pos, offset, period)
+ end
end,
-- Digs out nodes that are "in front" of the digger head.
diff --git a/util.lua b/util.lua
index 3f1d732..63903b1 100644
--- a/util.lua
+++ b/util.lua
@@ -240,4 +240,34 @@ digtron.is_soft_material = function(target)
return true
end
return false
+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 \ No newline at end of file