homedecor_modpack/lavalamp/init.lua
wsor4035 546cd7110f
make homedecor game agnostic (#28)
* make materials.lua with hades, minetest game, farlands items

* make textures file for central handling

* make mods game agnostic

* take out the trash

* handle multiple seats in sofas

* add github luacheck workflow and various luacheck fixes

* add fluxionary scope creep

* fix devtest breaking right to a name policy

Co-authored-by: wsor4035 <24964441+wsor4035@users.noreply.github.com>
Co-authored-by: SFENCE <sfence.software@gmail.com>
2022-05-03 15:21:14 -04:00

152 lines
3.6 KiB
Lua

local S = minetest.get_translator("lavalamp")
lavalamp = {}
minetest.register_node("lavalamp:lavalamp", {
description = S("Lava Lamp/Light"),
drawtype = "mesh",
mesh = "lavalamp.obj",
tiles = {
{ name = "lavalamp_metal.png", color = "white" },
{ name = "lavalamp_lamp_liquid.png", color = "white" },
},
overlay_tiles = {
"",
{
name="lavalamp_lamp_anim.png",
animation={
type="vertical_frames",
aspect_w=40,
aspect_h=40,
length=6.0,
},
},
},
use_texture_alpha = "blend",
inventory_image = "lavalamp_lamp_inv.png",
paramtype = "light",
paramtype2 = "color",
palette = "unifieddyes_palette_extended.png",
sunlight_propagates = true,
walkable = false,
light_source = 14,
selection_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25,0.5, 0.25 },
},
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, ud_param2_colorable = 1},
_sound_def = {
key = "node_sound_glass_defaults",
},
on_construct = unifieddyes.on_construct,
on_dig = unifieddyes.on_dig,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
node.name = "lavalamp:lavalamp_off"
minetest.swap_node(pos, node)
return itemstack
end
})
minetest.register_node("lavalamp:lavalamp_off", {
description = S("Lava Lamp/Light (off)"),
drawtype = "mesh",
mesh = "lavalamp.obj",
tiles = {
{ name = "lavalamp_metal.png", color = 0xffffffff },
"lavalamp_lamp_off.png",
},
paramtype = "light",
paramtype2 = "color",
palette = "unifieddyes_palette_extended.png",
sunlight_propagates = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25,0.5, 0.25 },
},
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, not_in_creative_inventory=1},
_sound_def = {
key = "node_sound_glass_defaults",
},
on_construct = unifieddyes.on_construct,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
node.name = "lavalamp:lavalamp"
minetest.swap_node(pos, node)
return itemstack
end,
drop = {
items = {
{items = {"lavalamp:lavalamp"}, inherit_color = true },
}
}
})
minetest.register_craft({
output = "lavalamp:lavalamp",
recipe = {
{"", homedecor.materials.wool_white, "", },
{"", homedecor.materials.water_bucket, "", },
{"", homedecor.materials.wool_black, "", }
}
})
unifieddyes.register_color_craft({
output = "lavalamp:lavalamp",
palette = "extended",
type = "shapeless",
neutral_node = "lavalamp:lavalamp",
recipe = {
"NEUTRAL_NODE",
"MAIN_DYE"
}
})
-- convert to param2 coloring
local colors = {
"red",
"orange",
"yellow",
"green",
"blue",
"violet"
}
lavalamp.old_static_nodes = {}
for _, color in ipairs(colors) do
table.insert(lavalamp.old_static_nodes, "lavalamp:"..color)
table.insert(lavalamp.old_static_nodes, "lavalamp:"..color.."_off")
end
minetest.register_lbm({
name = "lavalamp:convert",
label = "Convert lava lamps to use param2 color",
run_at_every_load = false,
nodenames = lavalamp.old_static_nodes,
action = function(pos, node)
local name = node.name
local color
if string.find(name, "red") then
color = "red"
elseif string.find(name, "orange") then
color = "orange"
elseif string.find(name, "yellow") then
color = "yellow"
elseif string.find(name, "green") then
color = "green"
elseif string.find(name, "blue") then
color = "blue"
elseif string.find(name, "violet") then
color = "violet"
end
local paletteidx, _ = unifieddyes.getpaletteidx("unifieddyes:"..color, "extended")
minetest.set_node(pos, { name = "lavalamp:lavalamp", param2 = paletteidx })
local meta = minetest.get_meta(pos)
meta:set_string("dye", "unifieddyes:"..color)
end
})