Signs: update and improve

This commit is contained in:
MoNTE48 2021-02-19 22:20:11 +01:00
parent da31e7c91c
commit 11bc97381f
5 changed files with 31 additions and 21 deletions

View File

@ -8,9 +8,9 @@ if translator and not minetest.is_singleplayer() then
end
end
local vadd = vector.add
local floor, pi = math.floor, math.pi
local find = string.find
local vadd = vector.add
local objects_inside_radius = minetest.get_objects_inside_radius
local b = "blank.png"
-- Cyrillic transliteration library
@ -67,10 +67,6 @@ local wrap_chars = {
}
local function generate_sign_texture(str)
if not str or str == "" then
return b
end
local row = 0
local texture = "[combine:" .. 16 * 20 .. "x100"
local result = {}
@ -221,7 +217,7 @@ local function place(itemstack, placer, pointed_thing)
end
local function destruct(pos)
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
for _, obj in pairs(objects_inside_radius(pos, 0.5)) do
local ent = obj:get_luaentity()
if ent and ent.name == "signs:sign_text" then
obj:remove()
@ -232,7 +228,7 @@ end
local function check_text(pos)
local meta = minetest.get_meta(pos)
local text = meta:get_string("sign_text")
local objects = minetest.get_objects_inside_radius(pos, 0.5)
local objects = objects_inside_radius(pos, 0.5)
if text and text ~= "" then
local count = 0
@ -266,6 +262,12 @@ local function check_text(pos)
end
end
end
-- Remove old on_construct fs
local fs = meta:get_string("formspec")
if fs and fs ~= "" then
meta:set_string("")
end
end
local function edit_text(pos, _, clicker)
@ -292,13 +294,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
local text = fields.Dtext
local pos = fields.spos
local pos = fields.spos and minetest.string_to_pos(fields.spos)
if not text or not pos then
return
end
pos = minetest.string_to_pos(fields.spos)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
@ -307,7 +308,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local p2 = node.param2
local sign_pos = sign_positions
if find(node.name, "wall") then
if node.name:find("wall") then
p2 = p2 - 2
sign_pos = wall_sign_positions
end
@ -316,7 +317,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
local sign
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
for _, obj in pairs(objects_inside_radius(pos, 0.5)) do
local ent = obj:get_luaentity()
if ent and ent.name == "signs:sign_text" then
sign = obj
@ -333,14 +334,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
-- Serialization longer values may cause a crash
-- because we are serializing the texture too
text = text:sub(1, 256)
local texture = b
if text ~= "" then
-- Serialization longer values may cause a crash
-- because we are serializing the texture too
text = text:sub(1, 256)
texture = generate_sign_texture(text)
sign:set_properties({
textures = {texture, b}
})
end
local texture = generate_sign_texture(text)
sign:set_properties({
textures = {texture, b}
})
sign:set_yaw(sign_pos[p2][2])
local meta = minetest.get_meta(pos)
@ -353,7 +358,12 @@ end)
-- Sign nodes
minetest.register_node("signs:sign", {
description = S"Sign",
tiles = {"signs_wood.png"},
tiles = {
"signs_top.png", "signs_top.png", "signs_top.png",
"signs_top.png", "signs_sign.png", "signs_sign.png"
},
inventory_image = "signs_item.png",
wield_image = "signs_item.png",
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
@ -375,7 +385,7 @@ minetest.register_node("signs:sign", {
})
minetest.register_node("signs:wall_sign", {
tiles = {"signs_wood.png"},
tiles = {"signs_wall_sign.png"},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "wallmounted",

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 966 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB