1
0
Fork 0

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
1 changed files with 1579 additions and 1481 deletions

View File

@ -7,7 +7,6 @@
--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 table = table -- copied from the original signs init file.
if DEBUG then
minetest.log("action", "[mcl_signs] Signs API Loading")
@ -30,6 +29,9 @@ local NUMBER_OF_LINES = 4
local LINE_HEIGHT = 14
local CHAR_WIDTH = 5
-- -----------------------
-- CACHE LOCAL COPIES
local table = table
local string = string
-- CACHE NODE_SOUNDS
local node_sounds
@ -161,10 +163,21 @@ mcl_signs.wall_standard = {
stack_max = 16,
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)
local above = pointed_thing.above
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
local node_under = minetest.get_node(under)
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.
on_punch = function(pos, node, puncher)
mcl_signs:update_sign(pos)
if DISINTEGRATE then
mcl_signs:destruct_sign(pos)
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
end,
on_rotate = function(pos, node, user, mode)
@ -297,6 +311,11 @@ mcl_signs.wall_standard = {
return
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 iname = item:get_name()
@ -372,11 +391,18 @@ mcl_signs.standing_standard = {
mcl_signs:destruct_sign(pos)
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.
on_punch = function(pos, node, puncher)
mcl_signs:update_sign(pos)
if DISINTEGRATE then
mcl_signs:destruct_sign(pos)
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
end,
on_rotate = function(pos, node, user, mode)
@ -401,6 +427,11 @@ mcl_signs.standing_standard = {
return
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 iname = item:get_name()
@ -499,7 +530,7 @@ function mcl_signs.make_lbm()
name = "mcl_signs:respawn_entities",
label = "Respawn sign text entities",
run_at_every_load = true,
nodenames = registered_sign_nodenames ,
nodenames = registered_sign_nodenames,
action = function(pos, node)
mcl_signs:update_sign(pos)
end,
@ -559,6 +590,11 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
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)
-- Only build when it's legal
@ -572,16 +608,21 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
local sign_info
local nodeitem = ItemStack(itemstack)
local yaw = 0
-- Ceiling
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
-- Floor
elseif wdir == 1 then
-- Standing sign
-- 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)
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
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)
-- debug step
@ -676,7 +717,7 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
return true
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)
-- debug step
if DEBUG then
@ -696,7 +737,7 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
mcl_signs:update_sign(pos, nil, nil, true)
return true
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)
-- 45°
@ -712,7 +753,7 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
mcl_signs:update_sign(pos, nil, nil, true)
return true
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)
-- 67.5°
@ -729,7 +770,7 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
mcl_signs:update_sign(pos, nil, nil, true)
return true
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)
-- register Doc entry
@ -742,9 +783,9 @@ function mcl_signs.register_sign (modname, color, _name, ttsign)
end
--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_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_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_sign67_5" .. _name, 3 })
end
--- 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.wield_image ="("..wield_image.."^[multiply:" .. color .. ")"
new_sign.tiles = { "("..tiles.."^[multiply:" .. color .. ")" }
new_sign.inventory_image = "("..inventory_image.."^[multiply:" .. color .. ")"
new_sign.wield_image = "(" .. wield_image .. "^[multiply:" .. color .. ")"
new_sign.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" }
new_sign.inventory_image = "(" .. inventory_image .. "^[multiply:" .. color .. ")"
new_sign.description = S(ttsign)
-- currently have to do this, because of how the base node placement works.
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
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
local dir = vector.subtract(under, above)
-- 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)
return itemstack
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)
-- standing sign base.
local new_sign_standing = {}
new_sign_standing = table.copy(mcl_signs.standing_standard)
new_sign_standing.drop = "mcl_signs:wall_sign" .. _name
new_sign_standing.wield_image ="("..wield_image.."^[multiply:" .. color .. ")"
new_sign_standing.tiles = { "("..tiles.."^[multiply:" .. color .. ")" }
new_sign_standing.inventory_image = "("..inventory_image.."^[multiply:" .. color .. ")"
new_sign_standing.wield_image = "(" .. wield_image .. "^[multiply:" .. color .. ")"
new_sign_standing.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" }
new_sign_standing.inventory_image = "(" .. inventory_image .. "^[multiply:" .. color .. ")"
new_sign_standing.on_rotate = function(pos, node, user, mode)
if mode == screwdriver.ROTATE_FACE then
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)
return true
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)
-- 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)
return true
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)
-- 45°
@ -935,7 +981,7 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
mcl_signs:update_sign(pos, nil, nil, true)
return true
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)
-- 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)
return true
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)
-- register Doc entry
@ -965,9 +1011,9 @@ function mcl_signs.register_sign_custom (modname, _name, tiles, color, inventory
end
--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_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_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_sign67_5" .. _name, 3 })
end
@ -1017,6 +1063,11 @@ function mcl_signs.reregister_sign (modname, color, _name, ttsign)
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)
-- Only build when it's legal
@ -1198,9 +1249,9 @@ function mcl_signs.reregister_sign (modname, color, _name, ttsign)
end
--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_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_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_sign67_5" .. _name, 3 })
end
--- 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.wield_image ="("..wield_image.."^[multiply:" .. color .. ")"
new_sign.tiles = { "("..tiles.."^[multiply:" .. color .. ")" }
new_sign.inventory_image = "("..inventory_image.."^[multiply:" .. color .. ")"
new_sign.wield_image = "(" .. wield_image .. "^[multiply:" .. color .. ")"
new_sign.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" }
new_sign.inventory_image = "(" .. inventory_image .. "^[multiply:" .. color .. ")"
new_sign.description = S(ttsign)
-- currently have to do this, because of how the base node placement works.
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
local timer = minetest.get_node_timer(pos)
if timer:is_started() == false then
timer:start(40.0)
end
local dir = vector.subtract(under, above)
-- 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 = {}
new_sign_standing = table.copy(mcl_signs.standing_standard)
new_sign_standing.drop = "mcl_signs:wall_sign" .. _name
new_sign_standing.wield_image ="("..wield_image.."^[multiply:" .. color .. ")"
new_sign_standing.tiles = { "("..tiles.."^[multiply:" .. color .. ")" }
new_sign_standing.inventory_image = "("..inventory_image.."^[multiply:" .. color .. ")"
new_sign_standing.wield_image = "(" .. wield_image .. "^[multiply:" .. color .. ")"
new_sign_standing.tiles = { "(" .. tiles .. "^[multiply:" .. color .. ")" }
new_sign_standing.inventory_image = "(" .. inventory_image .. "^[multiply:" .. color .. ")"
new_sign_standing.on_rotate = function(pos, node, user, mode)
if mode == screwdriver.ROTATE_FACE then
node.name = "mcl_signs:standing_sign22_5" .. _name
@ -1421,9 +1477,9 @@ function mcl_signs.reregister_sign_custom (modname, _name, tiles, color, invento
end
--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_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_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_sign67_5" .. _name, 3 })
end
@ -1450,7 +1506,7 @@ function mcl_signs.register_sign_craft(modname, wood_item_string, _name)
minetest.register_craft({
type = "fuel",
recipe = "mcl_signs:wall_sign" .. _name,
recipe = ":mcl_signs:wall_sign" .. _name,
burntime = 10,
})
@ -1462,7 +1518,7 @@ function mcl_signs.register_sign_craft(modname, wood_item_string, _name)
-- register crafts (actual recipe)
if minetest.get_modpath(modname) then
local itemstring = "mcl_signs:wall_sign"
local itemstring = ":mcl_signs:wall_sign"
minetest.register_craft({
output = itemstring .. _name .. " 3",
@ -1473,7 +1529,49 @@ function mcl_signs.register_sign_craft(modname, wood_item_string, _name)
},
})
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
-- 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)
if DEBUG then
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
-- save sign metadata.