Cristiano Magro
2024-08-27 535e04d542520f58a2db8d4d7a222b73e5c96ef1
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
-- LED
-- Intended primarily as a core component for LED lamps.
 
local S = technic.getter
 
local desc = S("@1 LED", S("LV"))
local active_desc = S("@1 Active", desc)
local unpowered_desc = S("@1 Unpowered", desc)
local demand = 5
 
 
local function led_run(pos, node)
    local meta = minetest.get_meta(pos)
    local eu_input = meta:get_int("LV_EU_input")
 
    if eu_input < demand and node.name == "technic:lv_led_active" then
        technic.swap_node(pos, "technic:lv_led")
        meta:set_string("infotext", unpowered_desc)
    elseif eu_input >= demand and node.name == "technic:lv_led" then
        technic.swap_node(pos, "technic:lv_led_active")
        meta:set_string("infotext", active_desc)
    end
end
 
local common_fields = {
    drawtype = "nodebox",
    node_box = {
        type = "fixed",
        fixed = {0.5, 0.5, 0.5, -0.5, 0.3, -0.5}
    },
    tiles = {
        "technic_lv_led_top.png",
        "technic_lv_led.png",
        "technic_lv_led_side.png",
        "technic_lv_led_side2.png",
        "technic_lv_led_side2.png",
        "technic_lv_led_side2.png",
    },
 
    connect_sides = {"front", "back", "left", "right", "top", "bottom"},
    can_dig = technic.machine_can_dig,
    technic_run = led_run,
}
 
local ndef
 
ndef = {
    description = desc,
    inventory_image = "technic_lv_led_inv.png",
    sunlight_propagates = true,
    groups = {cracky = 2, technic_machine = 1, technic_lv = 1},
 
    on_construct = function(pos)
        local meta = minetest.get_meta(pos)
        meta:set_string("infotext", desc)
        meta:set_int("LV_EU_demand", demand)
    end,
}
 
for k, v in pairs(common_fields) do
    ndef[k] = v
end
 
minetest.register_node("technic:lv_led", ndef)
 
 
ndef = {
    description = active_desc,
    paramtype = "light",
    light_source = 9,
    drop = "technic:lv_led",
    groups = {cracky = 2, technic_machine = 1, technic_lv = 1, not_in_creative_inventory = 1},
    technic_on_disable = function(pos)
        technic.swap_node(pos, "technic:lv_led")
    end,
}
 
for k, v in pairs(common_fields) do
    ndef[k] = v
end
 
minetest.register_node("technic:lv_led_active", ndef)
 
 
technic.register_machine("LV", "technic:lv_led", technic.receiver)
technic.register_machine("LV", "technic:lv_led_active", technic.receiver)
 
minetest.register_craft({
    output = "technic:lv_led 2",
    recipe = {
        {"", "homedecor:plastic_sheeting", ""},
        {"homedecor:plastic_sheeting", "technic:doped_silicon_wafer", "homedecor:plastic_sheeting"},
        {"", "technic:fine_silver_wire", ""},
    }
})