summaryrefslogtreecommitdiff
path: root/nodes/node_axle.lua
blob: bdfaf7640f740d0a80784f3c8832fc129ab65b49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")

minetest.register_node("digtron:axle", {
	description = S("Digtron Rotation Axle"),
	_doc_items_longdesc = digtron.doc.axle_longdesc,
    _doc_items_usagehelp = digtron.doc.axle_usagehelp,
	groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1},
	drop = "digtron:axle",
	sounds = digtron.metal_sounds,
	paramtype = "light",
	paramtype2= "facedir",
	is_ground_content = false,
	-- Aims in the +Z direction by default
	tiles = {
		"digtron_plate.png^digtron_axel_top.png",
		"digtron_plate.png^digtron_axel_top.png",
		"digtron_plate.png^digtron_axel_side.png",
		"digtron_plate.png^digtron_axel_side.png",
		"digtron_plate.png^digtron_axel_side.png",
		"digtron_plate.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}, -- Axle
		}
	},
	
	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 = DigtronLayout.create(pos, clicker)
		image:rotate_layout_image(node.param2)
		if image:can_write_layout_image() then
			if image:write_layout_image(clicker) then
				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.config.cycle_time*2)
			else
				meta:set_string("infotext", "unrecoverable write_layout_image error")
			end
		else
			minetest.sound_play("buzzer", {gain=1.0, pos=pos})
			meta:set_string("infotext", S("Digtron is obstructed."))
		end
	end,
	
	on_timer = function(pos, elapsed)
		minetest.get_meta(pos):set_string("waiting", nil)
	end,
})