summaryrefslogtreecommitdiff
path: root/node_axle.lua
diff options
context:
space:
mode:
authorFaceDeer <derksenmobile@gmail.com>2017-01-08 01:23:10 -0700
committerFaceDeer <derksenmobile@gmail.com>2017-01-08 01:23:10 -0700
commitd7e5309833bc7044447982424dc8431d84d7a1a0 (patch)
treedb1081d61fd650db0593ef190b0bb32f93a19b3a /node_axle.lua
parente704249735372a3232883cc8b7f25679f4949a8d (diff)
Added a rotation controller
Well that was a lot of work. Also, switched the "waiting" timer management to the actual on_timer system - I noticed that minetest.after wasn't persisting through server shutdown and restart, that could put a controller in a "broken" state.
Diffstat (limited to 'node_axle.lua')
-rw-r--r--node_axle.lua58
1 files changed, 58 insertions, 0 deletions
diff --git a/node_axle.lua b/node_axle.lua
new file mode 100644
index 0000000..5859777
--- /dev/null
+++ b/node_axle.lua
@@ -0,0 +1,58 @@
+minetest.register_node("digtron:axle", {
+ description = "Digtron Rotation Unit",
+ groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1},
+ drop = "digtron:axel",
+ sounds = digtron.metal_sounds,
+ paramtype = "light",
+ paramtype2= "facedir",
+ is_ground_content = false,
+ -- Aims in the +Z direction by default
+ tiles = {
+ "digtron_axel_top.png",
+ "digtron_axel_top.png",
+ "digtron_axel_side.png",
+ "digtron_axel_side.png",
+ "digtron_axel_side.png",
+ "digtron_axel_side.png",
+ },
+
+ drawtype = "nodebox",
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.5, 0.3125, -0.3125, 0.5, 0.5, 0.3125}, -- Uppercap
+ {-0.5, -0.5, -0.3125, 0.5, -0.3125, 0.3125}, -- Lowercap
+ {-0.3125, 0.3125, -0.5, 0.3125, 0.5, -0.3125}, -- Uppercap_edge2
+ {-0.3125, 0.3125, 0.3125, 0.3125, 0.5, 0.5}, -- Uppercap_edge1
+ {-0.3125, -0.5, -0.5, 0.3125, -0.3125, -0.3125}, -- Lowercap_edge1
+ {-0.3125, -0.5, 0.3125, 0.3125, -0.3125, 0.5}, -- Lowercap_edge2
+ {-0.25, -0.3125, -0.25, 0.25, 0.3125, 0.25}, -- Axel
+ }
+ },
+
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ local meta = minetest.get_meta(pos)
+ if meta:get_string("waiting") == "true" then
+ -- Been too soon since last time the digtron rotated.
+ return
+ end
+ local image = digtron.get_layout_image(pos, clicker)
+ digtron.rotate_layout_image(image, node.param2)
+ if digtron.can_write_layout_image(image, clicker) then
+ digtron.write_layout_image(image)
+
+ minetest.sound_play("whirr", {gain=1.0, pos=pos})
+ meta = minetest.get_meta(pos)
+ meta:set_string("waiting", "true")
+ meta:set_string("infotext", nil)
+ minetest.get_node_timer(pos):start(digtron.cycle_time*2)
+ else
+ minetest.sound_play("buzzer", {gain=1.0, pos=pos})
+ meta:set_string("infotext", "Digtron is obstructed.")
+ end
+ end,
+
+ on_timer = function(pos, elapsed)
+ minetest.get_meta(pos):set_string("waiting", nil)
+ end,
+}) \ No newline at end of file