More code cleanup, extra checks to hopefully actually fix the bug

This commit is contained in:
GreenXenith 2018-11-26 11:34:12 -08:00
parent e8c4549c5a
commit 551835dd27

65
lcd.lua
View File

@ -129,34 +129,41 @@ local clearscreen = function(pos)
end end
local set_texture = function(ent) local set_texture = function(ent)
local meta = minetest.get_meta(ent.object:getpos()) local meta = minetest.get_meta(ent.object:get_pos())
local text = meta:get_string("text") local text = meta:get_string("text")
ent.object:set_properties({textures={generate_texture(create_lines(text))}}) ent.object:set_properties({
textures = {
generate_texture(create_lines(text))
}
})
end end
local prepare_writing = function(pos) local prepare_writing = function(pos)
local existing local lcd_entity
local objects = minetest.get_objects_inside_radius(pos, 0.5) local objects = minetest.get_objects_inside_radius(pos, 0.5)
for _, o in ipairs(objects) do for _, o in ipairs(objects) do
local o_entity = o:get_luaentity() local o_entity = o:get_luaentity()
if o_entity and o_entity.name == "digilines_lcd:text" then if o_entity and o_entity.name == "digilines_lcd:text" then
existing = o_entity if not lcd_entity then
break lcd_entity = o_entity
end
end
if not existing then
local lcd_info = lcds[minetest.get_node(pos).param2]
if lcd_info == nil then return end
local text = minetest.add_entity(
{x = pos.x + lcd_info.delta.x,
y = pos.y + lcd_info.delta.y,
z = pos.z + lcd_info.delta.z}, "digilines_lcd:text")
text:setyaw(lcd_info.yaw or 0)
return text
else else
set_texture(existing) -- Remove extras, if any
o:remove()
end end
end end
end
if not lcd_entity then
local lcd_info = lcds[minetest.get_node(pos).param2]
if not lcd_info then
return
end
local text = minetest.add_entity(vector.add(pos, lcd_info.delta), "digilines_lcd:text")
text:set_yaw(lcd_info.yaw or 0)
return text
end
set_texture(lcd_entity)
end
local on_digiline_receive = function(pos, _, channel, msg) local on_digiline_receive = function(pos, _, channel, msg)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -183,14 +190,13 @@ minetest.register_node("digilines:lcd", {
inventory_image = "lcd_lcd.png", inventory_image = "lcd_lcd.png",
wield_image = "lcd_lcd.png", wield_image = "lcd_lcd.png",
tiles = {"lcd_anyside.png"}, tiles = {"lcd_anyside.png"},
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
light_source = 6,
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
node_box = lcd_box, node_box = lcd_box,
selection_box = lcd_box, selection_box = lcd_box,
groups = {choppy = 3, dig_immediate = 2}, groups = {choppy = 3, dig_immediate = 2},
after_place_node = function (pos) after_place_node = function (pos)
local param2 = minetest.get_node(pos).param2 local param2 = minetest.get_node(pos).param2
if param2 == 0 or param2 == 1 then if param2 == 0 or param2 == 1 then
@ -198,15 +204,8 @@ minetest.register_node("digilines:lcd", {
end end
prepare_writing(pos) prepare_writing(pos)
end, end,
on_construct = reset_meta,
on_construct = function(pos) on_destruct = clearscreen,
reset_meta(pos)
end,
on_destruct = function(pos)
clearscreen(pos)
end,
on_receive_fields = function(pos, _, fields, sender) on_receive_fields = function(pos, _, fields, sender)
local name = sender:get_player_name() local name = sender:get_player_name()
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
@ -217,16 +216,12 @@ minetest.register_node("digilines:lcd", {
minetest.get_meta(pos):set_string("channel", fields.channel) minetest.get_meta(pos):set_string("channel", fields.channel)
end end
end, end,
digiline = {
digiline =
{
receptor = {}, receptor = {},
effector = { effector = {
action = on_digiline_receive action = on_digiline_receive
}, },
}, },
light_source = 6,
}) })
minetest.register_lbm({ minetest.register_lbm({
@ -234,9 +229,7 @@ minetest.register_lbm({
name = "digilines:replace_text", name = "digilines:replace_text",
nodenames = {"digilines:lcd"}, nodenames = {"digilines:lcd"},
run_at_every_load = true, run_at_every_load = true,
action = function(pos) action = prepare_writing,
prepare_writing(pos)
end,
}) })
minetest.register_entity(":digilines_lcd:text", { minetest.register_entity(":digilines_lcd:text", {