fix signs to reset after /clearobjects

Additionally, added in the register_hanging_sing_craft() for future use.
This commit is contained in:
Michieal 2022-11-07 17:16:07 +00:00 committed by cora
parent 10a3a022b6
commit e67c6e1ada

View File

@ -7,7 +7,6 @@
--local logging = minetest.settings:get_bool("mcl_logging_mcl_signs",true) --local logging = minetest.settings:get_bool("mcl_logging_mcl_signs",true)
local DEBUG = minetest.settings:get_bool("mcl_logging_mcl_signs", false) -- special debug setting. local DEBUG = minetest.settings:get_bool("mcl_logging_mcl_signs", false) -- special debug setting.
local table = table -- copied from the original signs init file.
if DEBUG then if DEBUG then
minetest.log("action", "[mcl_signs] Signs API Loading") minetest.log("action", "[mcl_signs] Signs API Loading")
@ -30,6 +29,9 @@ local NUMBER_OF_LINES = 4
local LINE_HEIGHT = 14 local LINE_HEIGHT = 14
local CHAR_WIDTH = 5 local CHAR_WIDTH = 5
-- ----------------------- -- -----------------------
-- CACHE LOCAL COPIES
local table = table
local string = string
-- CACHE NODE_SOUNDS -- CACHE NODE_SOUNDS
local node_sounds local node_sounds
@ -161,10 +163,21 @@ mcl_signs.wall_standard = {
stack_max = 16, stack_max = 16,
sounds = node_sounds, sounds = node_sounds,
on_timer = function(pos)
-- fix for /ClearObjects
mcl_signs:update_sign(pos)
minetest.get_node_timer(pos):start(40.0)
end,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local above = pointed_thing.above local above = pointed_thing.above
local under = pointed_thing.under local under = pointed_thing.under
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
-- Use pointed node's on_rightclick function first, if present -- Use pointed node's on_rightclick function first, if present
local node_under = minetest.get_node(under) local node_under = minetest.get_node(under)
if placer and not placer:get_player_control().sneak then if placer and not placer:get_player_control().sneak then
@ -272,8 +285,9 @@ mcl_signs.wall_standard = {
-- Not Useless Code. force updates the sign. -- Not Useless Code. force updates the sign.
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
mcl_signs:update_sign(pos) mcl_signs:update_sign(pos)
if DISINTEGRATE then local timer = minetest.get_node_timer(pos)
mcl_signs:destruct_sign(pos) if timer:is_started() == false then
timer:start(40.0)
end end
end, end,
on_rotate = function(pos, node, user, mode) on_rotate = function(pos, node, user, mode)
@ -297,6 +311,11 @@ mcl_signs.wall_standard = {
return return
end end
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
local iname = item:get_name() local iname = item:get_name()
@ -372,11 +391,18 @@ mcl_signs.standing_standard = {
mcl_signs:destruct_sign(pos) mcl_signs:destruct_sign(pos)
end, end,
on_timer = function(pos)
-- fix for /ClearObjects
mcl_signs:update_sign(pos)
minetest.get_node_timer(pos):start(40.0)
end,
-- Not Useless Code. this force updates the sign. -- Not Useless Code. this force updates the sign.
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
mcl_signs:update_sign(pos) mcl_signs:update_sign(pos)
if DISINTEGRATE then local timer = minetest.get_node_timer(pos)
mcl_signs:destruct_sign(pos) if timer:is_started() == false then
timer:start(40.0)
end end
end, end,
on_rotate = function(pos, node, user, mode) on_rotate = function(pos, node, user, mode)
@ -401,6 +427,11 @@ mcl_signs.standing_standard = {
return return
end end
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
local iname = item:get_name() local iname = item:get_name()
@ -499,7 +530,7 @@ function mcl_signs.make_lbm()
name = "mcl_signs:respawn_entities", name = "mcl_signs:respawn_entities",
label = "Respawn sign text entities", label = "Respawn sign text entities",
run_at_every_load = true, run_at_every_load = true,
nodenames = registered_sign_nodenames , nodenames = registered_sign_nodenames,
action = function(pos, node) action = function(pos, node)
mcl_signs:update_sign(pos) mcl_signs:update_sign(pos)
end, end,
@ -559,6 +590,11 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
end end
end end
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
local dir = vector.subtract(under, above) local dir = vector.subtract(under, above)
-- Only build when it's legal -- Only build when it's legal
@ -572,16 +608,21 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
local sign_info local sign_info
local nodeitem = ItemStack(itemstack) local nodeitem = ItemStack(itemstack)
local yaw = 0
-- Ceiling -- Ceiling
if wdir == 0 then if wdir == 0 then
--how would you add sign to ceiling? --how would you add sign to ceiling? simple - hanging sign.
-- add code for placement underneath a node.
return itemstack return itemstack
-- Floor -- Floor
elseif wdir == 1 then elseif wdir == 1 then
-- Standing sign -- Standing sign
-- Determine the sign rotation based on player's yaw -- Determine the sign rotation based on player's yaw
local yaw = pi * 2 - placer:get_look_horizontal() yaw = pi * 2 - placer:get_look_horizontal()
-- Select one of 16 possible rotations (0-15) -- Select one of 16 possible rotations (0-15)
local rotation_level = mcl_signs:round((yaw / (pi * 2)) * 16) local rotation_level = mcl_signs:round((yaw / (pi * 2)) * 16)
@ -648,7 +689,7 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
return itemstack return itemstack
end end
minetest.register_node("mcl_signs:wall_sign" .. _name, new_sign) minetest.register_node(":mcl_signs:wall_sign" .. _name, new_sign)
update_sign_registry("wall", "mcl_signs:wall_sign" .. _name) update_sign_registry("wall", "mcl_signs:wall_sign" .. _name)
-- debug step -- debug step
@ -676,7 +717,7 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
return true return true
end, end,
minetest.register_node("mcl_signs:standing_sign" .. _name, new_sign_standing) minetest.register_node(":mcl_signs:standing_sign" .. _name, new_sign_standing)
update_sign_registry("standing", "mcl_signs:standing_sign" .. _name) update_sign_registry("standing", "mcl_signs:standing_sign" .. _name)
-- debug step -- debug step
if DEBUG then if DEBUG then
@ -696,7 +737,7 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
mcl_signs:update_sign(pos, nil, nil, true) mcl_signs:update_sign(pos, nil, nil, true)
return true return true
end end
minetest.register_node("mcl_signs:standing_sign22_5" .. _name, ssign22_5d) minetest.register_node(":mcl_signs:standing_sign22_5" .. _name, ssign22_5d)
update_sign_registry("standing", "mcl_signs:standing_sign22_5" .. _name) update_sign_registry("standing", "mcl_signs:standing_sign22_5" .. _name)
-- 45° -- 45°
@ -712,7 +753,7 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
mcl_signs:update_sign(pos, nil, nil, true) mcl_signs:update_sign(pos, nil, nil, true)
return true return true
end end
minetest.register_node("mcl_signs:standing_sign45" .. _name, ssign45d) minetest.register_node(":mcl_signs:standing_sign45" .. _name, ssign45d)
update_sign_registry("standing", "mcl_signs:standing_sign45" .. _name) update_sign_registry("standing", "mcl_signs:standing_sign45" .. _name)
-- 67.5° -- 67.5°
@ -729,7 +770,7 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
mcl_signs:update_sign(pos, nil, nil, true) mcl_signs:update_sign(pos, nil, nil, true)
return true return true
end end
minetest.register_node("mcl_signs:standing_sign67_5" .. _name, ssign67_5d) minetest.register_node(":mcl_signs:standing_sign67_5" .. _name, ssign67_5d)
update_sign_registry("standing", "mcl_signs:standing_sign67_5" .. _name) update_sign_registry("standing", "mcl_signs:standing_sign67_5" .. _name)
-- register Doc entry -- register Doc entry
@ -742,9 +783,9 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
end end
--register standing sign's rotation_levels --register standing sign's rotation_levels
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign22_5" .. _name , 1}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign22_5" .. _name, 1 })
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign45" .. _name , 2}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign45" .. _name, 2 })
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign67_5" .. _name , 3}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign67_5" .. _name, 3 })
end end
--- The same as register_sign, except caller defines the textures. Note, there is a greyscale version of the sign, --- The same as register_sign, except caller defines the textures. Note, there is a greyscale version of the sign,
@ -782,9 +823,9 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
new_sign = table.copy(mcl_signs.wall_standard) new_sign = table.copy(mcl_signs.wall_standard)
new_sign.wield_image ="("..wield_image.."^[multiply:" .. color .. ")" new_sign.wield_image = "(" .. wield_image .. "^[multiply:" .. color .. ")"
new_sign.tiles = { "("..tiles.."^[multiply:" .. color .. ")" } new_sign.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" }
new_sign.inventory_image = "("..inventory_image.."^[multiply:" .. color .. ")" new_sign.inventory_image = "(" .. inventory_image .. "^[multiply:" .. color .. ")"
new_sign.description = S(ttsign) new_sign.description = S(ttsign)
-- currently have to do this, because of how the base node placement works. -- currently have to do this, because of how the base node placement works.
new_sign.on_place = function(itemstack, placer, pointed_thing) new_sign.on_place = function(itemstack, placer, pointed_thing)
@ -799,6 +840,11 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
end end
end end
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
local dir = vector.subtract(under, above) local dir = vector.subtract(under, above)
-- Only build when it's legal -- Only build when it's legal
@ -883,16 +929,16 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
mcl_signs:show_formspec(placer, place_pos) mcl_signs:show_formspec(placer, place_pos)
return itemstack return itemstack
end end
minetest.register_node("mcl_signs:wall_sign" .. _name, new_sign) minetest.register_node(":mcl_signs:wall_sign" .. _name, new_sign)
update_sign_registry("wall", "mcl_signs:wall_sign" .. _name) update_sign_registry("wall", "mcl_signs:wall_sign" .. _name)
-- standing sign base. -- standing sign base.
local new_sign_standing = {} local new_sign_standing = {}
new_sign_standing = table.copy(mcl_signs.standing_standard) new_sign_standing = table.copy(mcl_signs.standing_standard)
new_sign_standing.drop = "mcl_signs:wall_sign" .. _name new_sign_standing.drop = "mcl_signs:wall_sign" .. _name
new_sign_standing.wield_image ="("..wield_image.."^[multiply:" .. color .. ")" new_sign_standing.wield_image = "(" .. wield_image .. "^[multiply:" .. color .. ")"
new_sign_standing.tiles = { "("..tiles.."^[multiply:" .. color .. ")" } new_sign_standing.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" }
new_sign_standing.inventory_image = "("..inventory_image.."^[multiply:" .. color .. ")" new_sign_standing.inventory_image = "(" .. inventory_image .. "^[multiply:" .. color .. ")"
new_sign_standing.on_rotate = function(pos, node, user, mode) new_sign_standing.on_rotate = function(pos, node, user, mode)
if mode == screwdriver.ROTATE_FACE then if mode == screwdriver.ROTATE_FACE then
node.name = "mcl_signs:standing_sign22_5" .. _name node.name = "mcl_signs:standing_sign22_5" .. _name
@ -903,7 +949,7 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
mcl_signs:update_sign(pos, nil, nil, true) mcl_signs:update_sign(pos, nil, nil, true)
return true return true
end, end,
minetest.register_node("mcl_signs:standing_sign" .. _name, new_sign_standing) minetest.register_node(":mcl_signs:standing_sign" .. _name, new_sign_standing)
update_sign_registry("standing", "mcl_signs:standing_sign" .. _name) update_sign_registry("standing", "mcl_signs:standing_sign" .. _name)
-- 22.5° -- 22.5°
@ -919,7 +965,7 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
mcl_signs:update_sign(pos, nil, nil, true) mcl_signs:update_sign(pos, nil, nil, true)
return true return true
end end
minetest.register_node("mcl_signs:standing_sign22_5" .. _name, ssign22_5d) minetest.register_node(":mcl_signs:standing_sign22_5" .. _name, ssign22_5d)
update_sign_registry("standing", "mcl_signs:standing_sign22_5" .. _name) update_sign_registry("standing", "mcl_signs:standing_sign22_5" .. _name)
-- 45° -- 45°
@ -935,7 +981,7 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
mcl_signs:update_sign(pos, nil, nil, true) mcl_signs:update_sign(pos, nil, nil, true)
return true return true
end end
minetest.register_node("mcl_signs:standing_sign45" .. _name, ssign45d) minetest.register_node(":mcl_signs:standing_sign45" .. _name, ssign45d)
update_sign_registry("standing", "mcl_signs:standing_sign45" .. _name) update_sign_registry("standing", "mcl_signs:standing_sign45" .. _name)
-- 67.5° -- 67.5°
@ -952,7 +998,7 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
mcl_signs:update_sign(pos, nil, nil, true) mcl_signs:update_sign(pos, nil, nil, true)
return true return true
end end
minetest.register_node("mcl_signs:standing_sign67_5" .. _name, ssign67_5d) minetest.register_node(":mcl_signs:standing_sign67_5" .. _name, ssign67_5d)
update_sign_registry("standing", "mcl_signs:standing_sign67_5" .. _name) update_sign_registry("standing", "mcl_signs:standing_sign67_5" .. _name)
-- register Doc entry -- register Doc entry
@ -965,9 +1011,9 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
end end
--register standing sign's rotation_levels --register standing sign's rotation_levels
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign22_5" .. _name , 1}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign22_5" .. _name, 1 })
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign45" .. _name , 2}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign45" .. _name, 2 })
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign67_5" .. _name , 3}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign67_5" .. _name, 3 })
end end
@ -1017,6 +1063,11 @@ function mcl_signs.reregister_sign (modname, color, _name, ttsign)
end end
end end
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
local dir = vector.subtract(under, above) local dir = vector.subtract(under, above)
-- Only build when it's legal -- Only build when it's legal
@ -1198,9 +1249,9 @@ function mcl_signs.reregister_sign (modname, color, _name, ttsign)
end end
--register standing sign's rotation_levels --register standing sign's rotation_levels
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign22_5" .. _name , 1}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign22_5" .. _name, 1 })
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign45" .. _name , 2}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign45" .. _name, 2 })
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign67_5" .. _name , 3}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign67_5" .. _name, 3 })
end end
--- The same as reregister_sign, except caller defines the textures. Note, there is a greyscale version of the sign, --- The same as reregister_sign, except caller defines the textures. Note, there is a greyscale version of the sign,
@ -1238,9 +1289,9 @@ function mcl_signs.reregister_sign_custom (modname, _name, tiles, color, invento
new_sign = table.copy(mcl_signs.wall_standard) new_sign = table.copy(mcl_signs.wall_standard)
new_sign.wield_image ="("..wield_image.."^[multiply:" .. color .. ")" new_sign.wield_image = "(" .. wield_image .. "^[multiply:" .. color .. ")"
new_sign.tiles = { "("..tiles.."^[multiply:" .. color .. ")" } new_sign.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" }
new_sign.inventory_image = "("..inventory_image.."^[multiply:" .. color .. ")" new_sign.inventory_image = "(" .. inventory_image .. "^[multiply:" .. color .. ")"
new_sign.description = S(ttsign) new_sign.description = S(ttsign)
-- currently have to do this, because of how the base node placement works. -- currently have to do this, because of how the base node placement works.
new_sign.on_place = function(itemstack, placer, pointed_thing) new_sign.on_place = function(itemstack, placer, pointed_thing)
@ -1255,6 +1306,11 @@ function mcl_signs.reregister_sign_custom (modname, _name, tiles, color, invento
end end
end end
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
local dir = vector.subtract(under, above) local dir = vector.subtract(under, above)
-- Only build when it's legal -- Only build when it's legal
@ -1346,9 +1402,9 @@ function mcl_signs.reregister_sign_custom (modname, _name, tiles, color, invento
local new_sign_standing = {} local new_sign_standing = {}
new_sign_standing = table.copy(mcl_signs.standing_standard) new_sign_standing = table.copy(mcl_signs.standing_standard)
new_sign_standing.drop = "mcl_signs:wall_sign" .. _name new_sign_standing.drop = "mcl_signs:wall_sign" .. _name
new_sign_standing.wield_image ="("..wield_image.."^[multiply:" .. color .. ")" new_sign_standing.wield_image = "(" .. wield_image .. "^[multiply:" .. color .. ")"
new_sign_standing.tiles = { "("..tiles.."^[multiply:" .. color .. ")" } new_sign_standing.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" }
new_sign_standing.inventory_image = "("..inventory_image.."^[multiply:" .. color .. ")" new_sign_standing.inventory_image = "(" .. inventory_image .. "^[multiply:" .. color .. ")"
new_sign_standing.on_rotate = function(pos, node, user, mode) new_sign_standing.on_rotate = function(pos, node, user, mode)
if mode == screwdriver.ROTATE_FACE then if mode == screwdriver.ROTATE_FACE then
node.name = "mcl_signs:standing_sign22_5" .. _name node.name = "mcl_signs:standing_sign22_5" .. _name
@ -1421,9 +1477,9 @@ function mcl_signs.reregister_sign_custom (modname, _name, tiles, color, invento
end end
--register standing sign's rotation_levels --register standing sign's rotation_levels
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign22_5" .. _name , 1}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign22_5" .. _name, 1 })
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign45" .. _name , 2}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign45" .. _name, 2 })
table.insert(mcl_signs.standing_rotation_levels, {"mcl_signs:standing_sign67_5" .. _name , 3}) table.insert(mcl_signs.standing_rotation_levels, { "mcl_signs:standing_sign67_5" .. _name, 3 })
end end
@ -1450,7 +1506,7 @@ function mcl_signs.register_sign_craft(modname, wood_item_string, _name)
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "mcl_signs:wall_sign" .. _name, recipe = ":mcl_signs:wall_sign" .. _name,
burntime = 10, burntime = 10,
}) })
@ -1462,7 +1518,7 @@ function mcl_signs.register_sign_craft(modname, wood_item_string, _name)
-- register crafts (actual recipe) -- register crafts (actual recipe)
if minetest.get_modpath(modname) then if minetest.get_modpath(modname) then
local itemstring = "mcl_signs:wall_sign" local itemstring = ":mcl_signs:wall_sign"
minetest.register_craft({ minetest.register_craft({
output = itemstring .. _name .. " 3", output = itemstring .. _name .. " 3",
@ -1473,7 +1529,49 @@ function mcl_signs.register_sign_craft(modname, wood_item_string, _name)
}, },
}) })
end end
end
function mcl_signs.register_hanging_sign_craft(modname, wood_item_string, _name)
local mod_name_pass = false
if modname ~= "" and modname ~= "false" then
if minetest.get_modpath(modname) then
mod_name_pass = true
end
if mod_name_pass == false then
return
end
end
minetest.register_craft({
type = "fuel",
recipe = ":mcl_signs:wall_sign" .. _name,
burntime = 10,
})
-- debug step
if DEBUG then
minetest.log("action", "[mcl_signs] Register Sign Crafts: \n" .. modname .. "\n" .. wood_item_string .. "\n" .. _name)
end
-- register crafts (actual recipe)
if minetest.get_modpath(modname) then
local itemstring = ":mcl_signs:hanging_sign"
local quantity = "6"
local bamboo = string.find(wood_item_string, "bamboo")
if bamboo then
quantity = "2"
end
minetest.register_craft({
output = itemstring .. _name .. " " .. quantity,
recipe = {
{ "mcl_lanterns:chain", "", "mcl_lanterns:chain" },
{ wood_item_string, wood_item_string, wood_item_string },
{ wood_item_string, wood_item_string, wood_item_string },
},
})
end
end end
-- Helper functions -- Helper functions
@ -1899,7 +1997,7 @@ function mcl_signs:update_sign(pos, fields, sender, force_remove, text_color)
text_entity:set_yaw(sign_info.yaw) text_entity:set_yaw(sign_info.yaw)
if DEBUG then if DEBUG then
minetest.log("verbose", "[mcl_signs] Update_Sign: After texture recreation.") minetest.log("verbose", "[mcl_signs] Update_Sign: After texture recreation.")
minetest.log("action","[mcl_signs] Update_Sign: " .. npos_name .. "\nPlaced position:" .. dump(pos) .. "\nSign_info: " .. dump(sign_info)) minetest.log("action", "[mcl_signs] Update_Sign: " .. npos_name .. "\nPlaced position:" .. dump(pos) .. "\nSign_info: " .. dump(sign_info))
end end
-- save sign metadata. -- save sign metadata.