1
0
mirror of https://github.com/mt-mods/basic_signs.git synced 2024-12-25 02:10:28 +01:00
basic_signs/init.lua

178 lines
6.7 KiB
Lua
Raw Permalink Normal View History

2019-09-11 17:57:40 +02:00
-- Basic wall/yard/metal signs
-- these were originally part of signs_lib
basic_signs = {}
basic_signs.path = minetest.get_modpath(minetest.get_current_modname())
dofile(basic_signs.path .. "/crafting.lua")
local S, NS = dofile(basic_signs.path .. "/intllib.lua")
basic_signs.gettext = S
function basic_signs.check_for_floor(pointed_thing)
if pointed_thing.above.x == pointed_thing.under.x
and pointed_thing.above.z == pointed_thing.under.z
and pointed_thing.above.y > pointed_thing.under.y then
return true
end
end
function basic_signs.determine_sign_type(pos, placer, itemstack, pointed_thing, widefont)
2019-09-11 17:57:40 +02:00
local playername = placer:get_player_name()
local pt_name = minetest.get_node(pointed_thing.under).name
local node = minetest.get_node(pos) -- since we're in after-place, this will be the wall sign itself
local widefont = widefont or ""
2019-09-11 17:57:40 +02:00
if minetest.is_protected(pointed_thing.under, playername) then
minetest.record_protection_violation(pointed_thing.under, playername)
return itemstack
end
local newparam2 = minetest.dir_to_facedir(placer:get_look_dir())
2019-09-11 17:57:40 +02:00
if minetest.registered_nodes[pt_name] and
minetest.registered_nodes[pt_name].on_rightclick and
not placer:get_player_control().sneak then
return minetest.registered_nodes[pt_name].on_rightclick(pos, node, placer, itemstack, pointed_thing)
elseif signs_lib.check_for_pole(pos, pointed_thing) then
minetest.swap_node(pos, {name = "default:sign_wall_wood"..widefont.."_onpole", param2 = node.param2})
elseif signs_lib.check_for_ceiling(pointed_thing) then
minetest.swap_node(pos, {name = "default:sign_wall_wood"..widefont.."_hanging", param2 = newparam2})
elseif basic_signs.check_for_floor(pointed_thing) then
minetest.swap_node(pos, {name = "basic_signs:yard_sign"..widefont, param2 = newparam2})
2019-09-11 17:57:40 +02:00
end
signs_lib.update_sign(pos)
2019-09-11 17:57:40 +02:00
if not creative.is_enabled_for(playername) then
itemstack:take_item()
end
return itemstack
end
local def
minetest.override_item("default:sign_wall_wood", {
after_place_node = basic_signs.determine_sign_type
})
2019-09-11 17:57:40 +02:00
def = table.copy(minetest.registered_items["default:sign_wall_wood"])
def.description = "Wooden wall sign (wide font)"
def.inventory_image = def.inventory_image.."^signs_lib_wide_font_overlay_inv.png"
def.wield_image = def.wield_image.."^signs_lib_wide_font_overlay_inv.png"
def.horiz_scaling = signs_lib.standard_hscale / 2
def.after_place_node = function(pos, placer, itemstack, pointed_thing)
basic_signs.determine_sign_type(pos, placer, itemstack, pointed_thing, "_widefont")
end
signs_lib.register_sign("default:sign_wall_wood_widefont", def)
def = table.copy(minetest.registered_items["default:sign_wall_steel"])
def.description = "Steel wall sign (wide font)"
def.inventory_image = def.inventory_image.."^signs_lib_wide_font_overlay_inv.png"
def.wield_image = def.wield_image.."^signs_lib_wide_font_overlay_inv.png"
def.horiz_scaling = signs_lib.standard_hscale / 2
signs_lib.register_sign("default:sign_wall_steel_widefont", def)
signs_lib.register_sign("basic_signs:sign_wall_locked", {
description = S("Locked Sign"),
tiles = {
"basic_signs_sign_wall_locked.png",
"signs_lib_sign_wall_steel_edges.png",
},
inventory_image = "basic_signs_sign_wall_locked_inv.png",
locked = true,
entity_info = "standard",
allow_hanging = true
})
2019-09-11 17:57:40 +02:00
minetest.register_alias("locked_sign:sign_wall_locked", "basic_signs:sign_wall_locked")
2019-09-11 17:57:40 +02:00
def = table.copy(minetest.registered_items["basic_signs:sign_wall_locked"])
def.description = S("Locked Sign (wide font)")
def.inventory_image = def.inventory_image.."^signs_lib_wide_font_overlay_inv.png"
def.wield_image = def.wield_image.."^signs_lib_wide_font_overlay_inv.png"
def.horiz_scaling = signs_lib.standard_hscale / 2
signs_lib.register_sign("basic_signs:sign_wall_locked_widefont", def)
-- array : color, translated color, default text color
2019-09-11 17:57:40 +02:00
local sign_colors = {
{"green", S("green"), "f"},
{"yellow", S("yellow"), "0"},
{"red", S("red"), "f"},
{"white_red", S("white_red"), "4"},
{"white_black", S("white_black"), "0"},
{"orange", S("orange"), "0"},
{"blue", S("blue"), "f"},
{"brown", S("brown"), "f"},
}
2019-09-11 17:57:40 +02:00
local cbox = signs_lib.make_selection_boxes(35, 25, true, 0, 0, 0, true)
2019-09-11 17:57:40 +02:00
for i, color in ipairs(sign_colors) do
signs_lib.register_sign("basic_signs:sign_wall_steel_"..color[1], {
description = S("Sign (@1, steel)", color[2]),
paramtype2 = "facedir",
2019-09-11 17:57:40 +02:00
selection_box = cbox,
mesh = "signs_lib_standard_wall_sign_facedir.obj",
2019-09-11 17:57:40 +02:00
tiles = {
"basic_signs_steel_"..color[1]..".png",
2019-09-11 17:57:40 +02:00
"signs_lib_sign_wall_steel_edges.png",
},
inventory_image = "basic_signs_steel_"..color[1].."_inv.png",
groups = signs_lib.standard_steel_groups,
sounds = signs_lib.standard_steel_sign_sounds,
default_color = color[3],
2019-09-11 17:57:40 +02:00
entity_info = {
mesh = "signs_lib_standard_wall_sign_entity.obj",
yaw = signs_lib.standard_yaw
2019-09-11 17:57:40 +02:00
},
allow_hanging = true
2019-09-11 17:57:40 +02:00
})
def = table.copy(minetest.registered_items["basic_signs:sign_wall_steel_"..color[1]])
def.description = S("Sign (@1, steel, wide font)", color[2])
def.horiz_scaling = signs_lib.standard_hscale / 2
def.inventory_image = def.inventory_image.."^signs_lib_wide_font_overlay_inv.png"
def.wield_image = def.wield_image.."^signs_lib_wide_font_overlay_inv.png"
signs_lib.register_sign("basic_signs:sign_wall_steel_widefont_"..color[1], def)
table.insert(signs_lib.lbm_restore_nodes, "signs:sign_wall_"..color[1])
minetest.register_alias("signs:sign_wall_"..color[1], "basic_signs:sign_wall_steel_"..color[1])
2019-09-11 17:57:40 +02:00
end
local wgroups = table.copy(signs_lib.standard_wood_groups)
wgroups.not_in_creative_inventory = 1
signs_lib.register_sign("basic_signs:yard_sign", {
2019-09-11 17:57:40 +02:00
description = "Wooden yard sign",
paramtype2 = "facedir",
selection_box = signs_lib.make_selection_boxes(35, 34.5, false, 0, -1.25, -19.69, true),
2019-09-11 17:57:40 +02:00
mesh = "basic_signs_yard_sign.obj",
tiles = {
"signs_lib_sign_wall_wooden.png",
"signs_lib_sign_wall_wooden_edges.png",
"default_wood.png"
},
inventory_image = "default_sign_wood.png",
entity_info = {
mesh = "basic_signs_yard_sign_entity.obj",
yaw = signs_lib.standard_yaw
},
groups = wgroups,
drop = "default:sign_wall_wood",
allow_onpole = false
2019-09-11 17:57:40 +02:00
})
def = table.copy(minetest.registered_items["basic_signs:yard_sign"])
def.description = "Wooden yard sign (wide font)"
def.inventory_image = def.inventory_image.."^signs_lib_wide_font_overlay_inv.png"
def.wield_image = def.wield_image.."^signs_lib_wide_font_overlay_inv.png"
def.wield_image = def.wield_image.."^signs_lib_wide_font_overlay_inv.png"
def.horiz_scaling = signs_lib.standard_hscale / 2
def.groups = wgroups
minetest.register_node("basic_signs:yard_sign_widefont", def)
table.insert(signs_lib.lbm_restore_nodes, "signs:sign_yard")
minetest.register_alias("signs:sign_yard", "basic_signs:yard_sign")