2017-02-05 07:08:38 +01:00
|
|
|
-- internationalization boilerplate
|
2023-11-17 11:55:41 +01:00
|
|
|
local S = digtron.S
|
|
|
|
-- local MP = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
-- local S = dofile(MP.."/intllib.lua")
|
2017-02-05 07:08:38 +01:00
|
|
|
|
2017-01-08 09:23:10 +01:00
|
|
|
minetest.register_node("digtron:axle", {
|
2017-02-05 07:08:38 +01:00
|
|
|
description = S("Digtron Rotation Axle"),
|
2017-01-18 03:57:20 +01:00
|
|
|
_doc_items_longdesc = digtron.doc.axle_longdesc,
|
|
|
|
_doc_items_usagehelp = digtron.doc.axle_usagehelp,
|
2017-01-08 09:23:10 +01:00
|
|
|
groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 1},
|
2017-01-08 09:38:30 +01:00
|
|
|
drop = "digtron:axle",
|
2017-01-08 09:23:10 +01:00
|
|
|
sounds = digtron.metal_sounds,
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2= "facedir",
|
|
|
|
is_ground_content = false,
|
|
|
|
-- Aims in the +Z direction by default
|
|
|
|
tiles = {
|
2017-01-11 06:59:11 +01:00
|
|
|
"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",
|
2017-01-08 09:23:10 +01:00
|
|
|
},
|
2023-06-19 07:44:40 +02:00
|
|
|
|
2017-01-08 09:23:10 +01:00
|
|
|
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
|
2017-01-20 08:34:01 +01:00
|
|
|
{-0.25, -0.3125, -0.25, 0.25, 0.3125, 0.25}, -- Axle
|
2017-01-08 09:23:10 +01:00
|
|
|
}
|
|
|
|
},
|
2020-04-02 21:48:28 +02:00
|
|
|
|
|
|
|
|
2023-06-19 07:44:40 +02:00
|
|
|
|
|
|
|
on_rightclick = function(pos, node, clicker)
|
2017-01-08 09:23:10 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2023-06-19 07:44:40 +02:00
|
|
|
|
2020-04-02 21:48:28 +02:00
|
|
|
-- new delay code without nodetimer (lost on crating)
|
|
|
|
local now = minetest.get_gametime()
|
|
|
|
local last_time = tonumber(meta:get_string("last_time")) or 0
|
|
|
|
-- if meta:get_string("waiting") == "true" then
|
|
|
|
if last_time + digtron.config.cycle_time*2 > now then
|
2017-01-08 09:23:10 +01:00
|
|
|
-- Been too soon since last time the digtron rotated.
|
2020-04-02 21:48:28 +02:00
|
|
|
|
|
|
|
-- added for clarity
|
|
|
|
meta:set_string("infotext", S("repetition delay"))
|
|
|
|
|
2017-01-08 09:23:10 +01:00
|
|
|
return
|
|
|
|
end
|
2020-04-02 21:48:28 +02:00
|
|
|
|
2023-06-19 07:44:40 +02:00
|
|
|
local image = digtron.DigtronLayout.create(pos, clicker)
|
2019-01-13 11:02:02 +01:00
|
|
|
if image:rotate_layout_image(node.param2) == false then
|
|
|
|
-- This should be impossible, but if self-validation fails abort.
|
|
|
|
return
|
|
|
|
end
|
2017-01-12 08:50:17 +01:00
|
|
|
if image:can_write_layout_image() then
|
2018-01-07 21:38:25 +01:00
|
|
|
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")
|
2024-06-25 21:31:20 +02:00
|
|
|
meta:set_string("infotext", "")
|
2020-04-02 21:48:28 +02:00
|
|
|
-- minetest.get_node_timer(pos):start(digtron.config.cycle_time*2)
|
|
|
|
-- new delay code
|
|
|
|
meta:set_string("last_time",tostring(minetest.get_gametime()))
|
2018-01-07 21:38:25 +01:00
|
|
|
else
|
|
|
|
meta:set_string("infotext", "unrecoverable write_layout_image error")
|
|
|
|
end
|
2017-01-08 09:23:10 +01:00
|
|
|
else
|
|
|
|
minetest.sound_play("buzzer", {gain=1.0, pos=pos})
|
2017-02-05 07:08:38 +01:00
|
|
|
meta:set_string("infotext", S("Digtron is obstructed."))
|
2017-01-08 09:23:10 +01:00
|
|
|
end
|
|
|
|
end,
|
2023-06-19 07:44:40 +02:00
|
|
|
|
|
|
|
on_timer = function(pos)
|
2024-06-25 21:31:20 +02:00
|
|
|
minetest.get_meta(pos):set_string("waiting", "")
|
2017-01-08 09:23:10 +01:00
|
|
|
end,
|
|
|
|
})
|