Skip to content

Commit d623715

Browse files
blockhead100SmallJoker
authored andcommittedOct 20, 2022
Add LV led and lamp
1 parent 718a5be commit d623715

12 files changed

+284
-0
lines changed
 

‎modpack.conf

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
name = technic
2+
description = technic
3+
min_minetest_version = 5.0

‎technic/machines/LV/init.lua

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ dofile(path.."/extractor.lua")
2222
dofile(path.."/compressor.lua")
2323

2424
dofile(path.."/music_player.lua")
25+
-- NEW LV LAMPS
26+
dofile(path.."/led.lua")
27+
dofile(path.."/lamp.lua")

‎technic/machines/LV/lamp.lua

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
2+
-- LV Lamp
3+
-- Illuminates a 7x7x3(H) volume below itself with light bright as the sun.
4+
5+
6+
local S = technic.getter
7+
8+
local desc = S("@1 Lamp", S("LV"))
9+
local active_desc = S("@1 Active", desc)
10+
local unpowered_desc = S("@1 Unpowered", desc)
11+
local off_desc = S("@1 Off", desc)
12+
local demand = 50
13+
14+
15+
-- Invisible light source node used for illumination
16+
minetest.register_node("technic:dummy_light_source", {
17+
description = S("Dummy light source node"),
18+
inventory_image = "technic_dummy_light_source.png",
19+
wield_image = "technic_dummy_light_source.png",
20+
paramtype = "light",
21+
drawtype = "airlike",
22+
light_source = 14,
23+
sunlight_propagates = true,
24+
walkable = false,
25+
buildable_to = true,
26+
diggable = false,
27+
pointable = false,
28+
--drop = "", -- Intentionally allowed to drop itself
29+
groups = {not_in_creative_inventory = 1}
30+
})
31+
32+
33+
local function illuminate(pos, active)
34+
local pos1 = {x = pos.x - 3, y = pos.y - 1, z = pos.z - 3}
35+
local pos2 = {x = pos.x + 3, y = pos.y - 3, z = pos.z + 3}
36+
37+
local find_node = active and "air" or "technic:dummy_light_source"
38+
local set_node = {name = (active and "technic:dummy_light_source" or "air")}
39+
40+
for _,p in pairs(minetest.find_nodes_in_area(pos1, pos2, find_node)) do
41+
minetest.set_node(p, set_node)
42+
end
43+
end
44+
45+
local function lamp_run(pos, node)
46+
local meta = minetest.get_meta(pos)
47+
48+
if meta:get_int("LV_EU_demand") == 0 then
49+
return -- Lamp is turned off
50+
end
51+
52+
local eu_input = meta:get_int("LV_EU_input")
53+
54+
if node.name == "technic:lv_lamp_active" then
55+
if eu_input < demand then
56+
technic.swap_node(pos, "technic:lv_lamp")
57+
meta:set_string("infotext", unpowered_desc)
58+
illuminate(pos, false)
59+
else
60+
illuminate(pos, true)
61+
end
62+
elseif node.name == "technic:lv_lamp" then
63+
if eu_input >= demand then
64+
technic.swap_node(pos, "technic:lv_lamp_active")
65+
meta:set_string("infotext", active_desc)
66+
illuminate(pos, true)
67+
end
68+
end
69+
end
70+
71+
local function lamp_toggle(pos, node, player)
72+
if not player or minetest.is_protected(pos, player:get_player_name()) then
73+
return
74+
end
75+
local meta = minetest.get_meta(pos)
76+
if meta:get_int("LV_EU_demand") == 0 then
77+
meta:set_string("infotext", active_desc)
78+
meta:set_int("LV_EU_demand", demand)
79+
else
80+
illuminate(pos, false)
81+
technic.swap_node(pos, "technic:lv_lamp")
82+
meta:set_string("infotext", off_desc)
83+
meta:set_int("LV_EU_demand", 0)
84+
end
85+
end
86+
87+
minetest.register_node("technic:lv_lamp", {
88+
description = desc,
89+
drawtype = "nodebox",
90+
node_box = {
91+
type = "fixed",
92+
fixed = {0.5,0.5,0.5,-0.5,-0.2,-0.5}
93+
},
94+
collision_box = {
95+
type = "fixed",
96+
fixed = {0.5,0.5,0.5,-0.5,-0.2,-0.5}
97+
},
98+
selection_box = {
99+
type = "fixed",
100+
fixed = {0.5,0.5,0.5,-0.5,-0.2,-0.5}
101+
},
102+
tiles = {
103+
"technic_lv_lamp_top.png",
104+
"technic_lv_lamp_bottom.png",
105+
"technic_lv_lamp_side.png",
106+
"technic_lv_lamp_side.png",
107+
"technic_lv_lamp_side.png",
108+
"technic_lv_lamp_side.png"
109+
},
110+
groups = {cracky = 2, technic_machine = 1, technic_lv = 1},
111+
connect_sides = {"front", "back", "left", "right", "top"},
112+
can_dig = technic.machine_can_dig,
113+
technic_run = lamp_run,
114+
on_construct = function(pos)
115+
local meta = minetest.get_meta(pos)
116+
meta:set_string("infotext", desc)
117+
meta:set_int("LV_EU_demand", demand)
118+
end,
119+
on_destruct = illuminate,
120+
on_rightclick = lamp_toggle
121+
})
122+
123+
minetest.register_node("technic:lv_lamp_active", {
124+
description = active_desc,
125+
drawtype = "nodebox",
126+
node_box = {
127+
type = "fixed",
128+
fixed = {0.5, 0.5, 0.5, -0.5, -0.2, -0.5}
129+
},
130+
collision_box = {
131+
type = "fixed",
132+
fixed = {0.5, 0.5, 0.5, -0.5, -0.2, -0.5}
133+
},
134+
selection_box = {
135+
type = "fixed",
136+
fixed = {0.5, 0.5, 0.5, -0.5, -0.2, -0.5}
137+
},
138+
tiles = {
139+
"technic_lv_lamp_top.png",
140+
"technic_lv_lamp_bottom.png",
141+
"technic_lv_lamp_side.png",
142+
"technic_lv_lamp_side.png",
143+
"technic_lv_lamp_side.png",
144+
"technic_lv_lamp_side.png"
145+
},
146+
paramtype = "light",
147+
light_source = 14,
148+
drop = "technic:lv_lamp",
149+
groups = {cracky = 2, technic_machine = 1, technic_lv = 1, not_in_creative_inventory = 1},
150+
connect_sides = {"front", "back", "left", "right", "top"},
151+
can_dig = technic.machine_can_dig,
152+
technic_run = lamp_run,
153+
technic_on_disable = function(pos)
154+
illuminate(pos, false)
155+
technic.swap_node(pos, "technic:lv_lamp")
156+
end,
157+
on_destruct = illuminate,
158+
on_rightclick = lamp_toggle,
159+
})
160+
161+
technic.register_machine("LV", "technic:lv_lamp", technic.receiver)
162+
technic.register_machine("LV", "technic:lv_lamp_active", technic.receiver)
163+
164+
minetest.register_craft({
165+
output = "technic:lv_lamp",
166+
recipe = {
167+
{"default:glass", "default:glass", "default:glass"},
168+
{"technic:lv_led", "technic:lv_led", "technic:lv_led"},
169+
{"mesecons_materials:glue", "technic:lv_cable", "mesecons_materials:glue"},
170+
}
171+
})

‎technic/machines/LV/led.lua

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
-- LED
2+
-- Intended primarily as a core component for LED lamps.
3+
4+
local S = technic.getter
5+
6+
local desc = S("@1 LED", S("LV"))
7+
local active_desc = S("@1 Active", desc)
8+
local unpowered_desc = S("@1 Unpowered", desc)
9+
local demand = 5
10+
11+
12+
local function led_run(pos, node)
13+
local meta = minetest.get_meta(pos)
14+
local eu_input = meta:get_int("LV_EU_input")
15+
16+
if eu_input < demand and node.name == "technic:lv_led_active" then
17+
technic.swap_node(pos, "technic:lv_led")
18+
meta:set_string("infotext", unpowered_desc)
19+
elseif eu_input >= demand and node.name == "technic:lv_led" then
20+
technic.swap_node(pos, "technic:lv_led_active")
21+
meta:set_string("infotext", active_desc)
22+
end
23+
end
24+
25+
minetest.register_node("technic:lv_led", {
26+
description = desc,
27+
drawtype = "nodebox",
28+
node_box = {
29+
type = "fixed",
30+
fixed = {0.5, 0.5, 0.5, -0.5, 0.3, -0.5}
31+
},
32+
collision_box = {
33+
type = "fixed",
34+
fixed = {0.5, 0.5, 0.5, -0.5, 0.3, -0.5}
35+
},
36+
selection_box = {
37+
type = "fixed",
38+
fixed = {0.5, 0.5, 0.5, -0.5, 0.3, -0.5}
39+
},
40+
tiles = {
41+
"technic_lv_led_top.png",
42+
"technic_lv_led.png",
43+
"technic_lv_led_side.png",
44+
"technic_lv_led_side2.png",
45+
"technic_lv_led_side2.png",
46+
"technic_lv_led_side2.png",
47+
},
48+
inventory_image = "technic_lv_led_inv.png",
49+
sunlight_propagates = true,
50+
groups = {cracky = 2, technic_machine = 1, technic_lv = 1},
51+
connect_sides = {"front", "back", "left", "right", "top", "bottom"},
52+
can_dig = technic.machine_can_dig,
53+
technic_run = led_run,
54+
on_construct = function(pos)
55+
local meta = minetest.get_meta(pos)
56+
meta:set_string("infotext", desc)
57+
meta:set_int("LV_EU_demand", demand)
58+
end,
59+
})
60+
61+
minetest.register_node("technic:lv_led_active", {
62+
description = active_desc,
63+
drawtype = "nodebox",
64+
node_box = {
65+
type = "fixed",
66+
fixed = {0.5, 0.5, 0.5, -0.5, 0.3, -0.5}
67+
},
68+
collision_box = {
69+
type = "fixed",
70+
fixed = {0.5, 0.5, 0.5, -0.5, 0.3, -0.5}
71+
},
72+
selection_box = {
73+
type = "fixed",
74+
fixed = {0.5, 0.5, 0.5, -0.5, 0.3, -0.5}
75+
},
76+
tiles = {
77+
"technic_lv_led_top.png",
78+
"technic_lv_led.png",
79+
"technic_lv_led_side.png",
80+
"technic_lv_led_side2.png",
81+
"technic_lv_led_side2.png",
82+
"technic_lv_led_side2.png",
83+
},
84+
inventory_image = "technic_lv_led_inv.png",
85+
paramtype = "light",
86+
light_source = 9,
87+
drop = "technic:lv_led",
88+
sunlight_propagates = true,
89+
groups = {cracky = 2, technic_machine = 1, technic_lv = 1, not_in_creative_inventory = 1},
90+
connect_sides = {"front", "back", "left", "right", "top", "bottom"},
91+
can_dig = technic.machine_can_dig,
92+
technic_run = led_run,
93+
technic_on_disable = function(pos)
94+
technic.swap_node(pos, "technic:lv_led")
95+
end,
96+
})
97+
98+
technic.register_machine("LV", "technic:lv_led", technic.receiver)
99+
technic.register_machine("LV", "technic:lv_led_active", technic.receiver)
100+
101+
minetest.register_craft({
102+
output = "technic:lv_led 2",
103+
recipe = {
104+
{"", "homedecor:plastic_sheeting", ""},
105+
{"homedecor:plastic_sheeting", "technic:doped_silicon_wafer", "homedecor:plastic_sheeting"},
106+
{"", "technic:fine_silver_wire", ""},
107+
}
108+
})
995 Bytes
Loading
1014 Bytes
Loading
466 Bytes
Loading

‎technic/textures/technic_lv_led.png

738 Bytes
Loading
429 Bytes
Loading
245 Bytes
Loading
253 Bytes
Loading
466 Bytes
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.