1
0
mirror of https://github.com/mt-mods/signs_lib.git synced 2024-12-26 01:00:17 +01:00

Add glow feature to signs, with three brightness levels

This commit is contained in:
tenplus1 2021-05-27 17:33:20 +00:00 committed by Vanessa Dannenberg
parent b0fac5ef9f
commit 16b9251511
2 changed files with 41 additions and 4 deletions

41
api.lua
View File

@ -4,6 +4,8 @@ local S = signs_lib.gettext
local function get_sign_formspec() end local function get_sign_formspec() end
signs_lib.glow_item = "basic_materials:energy_crystal_simple"
signs_lib.lbm_restore_nodes = {} signs_lib.lbm_restore_nodes = {}
signs_lib.old_fenceposts = {} signs_lib.old_fenceposts = {}
signs_lib.old_fenceposts_replacement_signs = {} signs_lib.old_fenceposts_replacement_signs = {}
@ -180,7 +182,7 @@ function signs_lib.delete_objects(pos)
end end
end end
function signs_lib.spawn_entity(pos, texture) function signs_lib.spawn_entity(pos, texture, glow)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local def = minetest.registered_items[node.name] local def = minetest.registered_items[node.name]
if not def or not def.entity_info then return end if not def or not def.entity_info then return end
@ -229,6 +231,10 @@ function signs_lib.spawn_entity(pos, texture)
end end
end end
if glow ~= "" then
obj:set_properties({glow = tonumber(glow * 5))
end
if yaw then if yaw then
obj:set_rotation({x = pitch, y = yaw, z=0}) obj:set_rotation({x = pitch, y = yaw, z=0})
@ -247,14 +253,15 @@ function signs_lib.spawn_entity(pos, texture)
end end
end end
function signs_lib.set_obj_text(pos, text) function signs_lib.set_obj_text(pos, text, glow)
local split = signs_lib.split_lines_and_words local split = signs_lib.split_lines_and_words
local text_ansi = Utf8ToAnsi(text) local text_ansi = Utf8ToAnsi(text)
local n = minetest.registered_nodes[minetest.get_node(pos).name] local n = minetest.registered_nodes[minetest.get_node(pos).name]
signs_lib.delete_objects(pos) signs_lib.delete_objects(pos)
-- only create sign entity for actual text -- only create sign entity for actual text
if text_ansi and text_ansi ~= "" then if text_ansi and text_ansi ~= "" then
signs_lib.spawn_entity(pos, signs_lib.make_sign_texture(split(text_ansi), pos) ) signs_lib.spawn_entity(pos,
signs_lib.make_sign_texture(split(text_ansi), pos), glow)
end end
end end
@ -707,6 +714,12 @@ function signs_lib.rightclick_sign(pos, node, player, itemstack, pointed_thing)
end end
function signs_lib.destruct_sign(pos) function signs_lib.destruct_sign(pos)
local meta = minetest.get_meta(pos)
local glow = meta:get_string("glow")
if glow ~= "" then
local num = tonumber(glow)
minetest.add_item(pos, ItemStack(signs_lib.glow_item .. " " .. num))
end
signs_lib.delete_objects(pos) signs_lib.delete_objects(pos)
end end
@ -720,6 +733,24 @@ local function make_infotext(text)
return table.concat(lines2, "\n") return table.concat(lines2, "\n")
end end
function signs_lib.glow(pos, node, puncher)
local tool = puncher:get_wielded_item()
if tool:get_name() == signs_lib.glow_item then
local meta = minetest.get_meta(pos)
local glow = tonumber(meta:get_string("glow"))
if not glow then
glow = 1
elseif glow < 3 then
glow = glow + 1
else
return -- already at brightest level
end
tool:take_item()
puncher:set_wielded_item(tool)
meta:set_string("glow", glow)
end
end
function signs_lib.update_sign(pos, fields) function signs_lib.update_sign(pos, fields)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -737,7 +768,9 @@ function signs_lib.update_sign(pos, fields)
meta:set_string("text", text) meta:set_string("text", text)
meta:set_string("infotext", ownstr..make_infotext(text).." ") meta:set_string("infotext", ownstr..make_infotext(text).." ")
signs_lib.set_obj_text(pos, text)
local glow = meta:get_string("glow")
signs_lib.set_obj_text(pos, text, glow)
end end
function signs_lib.can_modify(pos, player) function signs_lib.can_modify(pos, player)

View File

@ -16,6 +16,10 @@ signs_lib.register_sign("default:sign_wall_wood", {
allow_onpole_horizontal = true, allow_onpole_horizontal = true,
allow_yard = true, allow_yard = true,
use_texture_alpha = "clip", use_texture_alpha = "clip",
on_punch = function(pos, node, puncher, pointed_thing)
signs_lib.glow(pos, node, puncher)
return signs_lib.update_sign
end
}) })
signs_lib.register_sign("default:sign_wall_steel", { signs_lib.register_sign("default:sign_wall_steel", {