firt commit
This commit is contained in:
commit
7b8d64f138
212
init.lua
Normal file
212
init.lua
Normal file
@ -0,0 +1,212 @@
|
||||
--
|
||||
-- Maker Tool used to edit infotext of certain nodes
|
||||
--
|
||||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
|
||||
-- Load support for intllib.
|
||||
local S, NS = dofile(modpath.."/intllib.lua")
|
||||
|
||||
|
||||
--
|
||||
-- Nodes Lists
|
||||
--
|
||||
-- Tool will only work on listed allowed nodes
|
||||
-- -- unless allowed nodes list is empty,
|
||||
-- it will then work on everything exept nodes listed
|
||||
-- -- in the ignored nodes list
|
||||
-- If both lists are empty it will not work at all
|
||||
|
||||
-- List of allowed node
|
||||
local allowed_nodes = {
|
||||
-- containers
|
||||
"default:chest",
|
||||
"default:chest",
|
||||
"default:chest_locked",
|
||||
"default:bookshelf",
|
||||
"vessels:shelf",
|
||||
"treasurechest:empty",
|
||||
-- doors
|
||||
"doors:door_wood",
|
||||
"doors:door_steel",
|
||||
"doors:door_glass",
|
||||
"doors:door_obsidian_glass",
|
||||
}
|
||||
|
||||
-- List of exeptions
|
||||
local ignored_nodes = {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Check if this node can be edited (function)
|
||||
local function can_edit(name,pos,meta)
|
||||
|
||||
-- Safety check
|
||||
if (not name) or (not pos) or (not meta) then
|
||||
msg =S("[%s] Maker pen was used but player name or node infos were not found.")
|
||||
minetest.log("error", msg:format(modname))
|
||||
return false
|
||||
end
|
||||
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if not node.name then
|
||||
msg =S("[%s] Maker pen was used but node name was not found.")
|
||||
minetest.log("error", msg:format(modname))
|
||||
return false
|
||||
end
|
||||
|
||||
-- Admins are allowed to edit anything, don't bother with other checks if player is admin
|
||||
local player_is_admin = minetest.check_player_privs(name, {fly=true})
|
||||
if player_is_admin then return true end
|
||||
|
||||
-- Check if node is in the list of allowed nodes
|
||||
local name_checked
|
||||
|
||||
if type(allowed_nodes) == "table" and #allowed_nodes > 0 then
|
||||
name_checked = false
|
||||
for _,v in ipairs(allowed_nodes) do
|
||||
if v == node.name then
|
||||
name_checked = true
|
||||
break
|
||||
end
|
||||
end
|
||||
-- Check if node is in the list of ignored nodes
|
||||
elseif type(ignored_nodes) == "table" and #ignored_nodes > 0 then
|
||||
name_checked = true
|
||||
for _,v in ipairs(ignored_nodes) do
|
||||
if v == node.name then
|
||||
name_checked = false
|
||||
break
|
||||
end
|
||||
end
|
||||
-- Nodes list not defined : error
|
||||
else
|
||||
msg =S("[%s] Maker pen was used by %s but nodes lists were not defined")
|
||||
minetest.log("error", msg:format(modname,name))
|
||||
return false
|
||||
end
|
||||
|
||||
if not name_checked then
|
||||
local msg = S("This node ('%s') cannot be edited with the marker pen")
|
||||
minetest.chat_send_player(name, msg:format(node.name))
|
||||
return false
|
||||
end
|
||||
|
||||
-- Return if node is owned by someone else
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
if owner and owner ~= '' and owner ~= name then
|
||||
local msg = S("%s is the owner of this node, you are not allowed to modify it")
|
||||
minetest.chat_send_player(name, msg:format(owner))
|
||||
return false
|
||||
end
|
||||
|
||||
-- Return if node is a door is owned by someone else
|
||||
local doors_owner = meta:get_string("doors_owner")
|
||||
|
||||
if doors_owner and doors_owner ~= '' and doors_owner ~= name then
|
||||
local msg = S("%s is the owner of this door, you are not allowed to modify it")
|
||||
minetest.chat_send_player(name, msg:format(doors_owner))
|
||||
return false
|
||||
end
|
||||
|
||||
-- If everything checked return true
|
||||
return true
|
||||
end
|
||||
|
||||
--
|
||||
-- What happen when tool is used
|
||||
--
|
||||
local function marker_tool_onuse(itemstack,player,pointed_thing,uses)
|
||||
|
||||
-- Return if not a node
|
||||
if pointed_thing.type~="node" then return false end
|
||||
|
||||
-- Get player name
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- Get node metadata
|
||||
local p = pointed_thing.under
|
||||
local meta = minetest.get_meta(p)
|
||||
|
||||
|
||||
-- Check if this node can be edited (function)
|
||||
if not can_edit(name,p,meta) then return end
|
||||
|
||||
-- Get node infotext
|
||||
local infotext = meta:get_string("infotext") or ""
|
||||
|
||||
-- Display formspec
|
||||
local formspec = "size[6,4]"..
|
||||
"textarea[0.3,0;6,3;infotext;;"..infotext.."]"..
|
||||
'field[0,-3;1,1;pos;;'.. minetest.pos_to_string(p)..']'..
|
||||
"button_exit[2,3.4;2,1;ok;"..S("Write").."]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img
|
||||
|
||||
minetest.show_formspec(name,modname..":marker_formspec",formspec)
|
||||
|
||||
if not minetest.settings:get_bool("creative_mode") then
|
||||
itemstack:add_wear(65535 / ((uses or 20) - 1))
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Save informations from form
|
||||
minetest.register_on_player_receive_fields(function(player, form, fields)
|
||||
-- Return if not the right form
|
||||
if form ~= modname..":marker_formspec" or not fields.infotext or not fields.pos then
|
||||
return
|
||||
end
|
||||
local pos = minetest.string_to_pos(fields.pos)
|
||||
-- Make sure node was not protected
|
||||
local name = player:get_player_name()
|
||||
if minetest.is_protected(pos, name) then
|
||||
minetest.record_protection_violation(pos, name)
|
||||
return
|
||||
end
|
||||
-- Update meta an inform log
|
||||
local meta = minetest.get_meta(pos)
|
||||
local msg = S("%s wrote '%s' at %s")
|
||||
minetest.log("action", msg:format(name,fields.infotext,fields.pos))
|
||||
meta:set_string("infotext",fields.infotext)
|
||||
end)
|
||||
|
||||
|
||||
|
||||
-- Register the tool
|
||||
minetest.register_tool(modname..":marker", {
|
||||
description = S("Marker"),
|
||||
inventory_image = "marker.png",
|
||||
-- range = 2,
|
||||
-- groups = {not_in_creative_inventory=1},
|
||||
on_use = function(itemstack, player, pointed_thing)
|
||||
marker_tool_onuse(itemstack,player,pointed_thing,20)
|
||||
return itemstack
|
||||
end,
|
||||
on_place = function(itemstack, player, pointed_thing)
|
||||
marker_tool_onuse(itemstack,player,pointed_thing,20)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
-- Recipes (only if dye mod exist)
|
||||
if minetest.get_modpath('dye') then
|
||||
minetest.register_craft({
|
||||
output = modname..":marker",
|
||||
recipe = {
|
||||
{'','dye:black'},
|
||||
{'group:stick',''},
|
||||
}
|
||||
})
|
||||
else
|
||||
minetest.register_craft({
|
||||
output = modname..":marker",
|
||||
recipe = {
|
||||
{'','default:coal_lump'},
|
||||
{'group:stick',''},
|
||||
}
|
||||
})
|
||||
end
|
44
intllib.lua
Normal file
44
intllib.lua
Normal file
@ -0,0 +1,44 @@
|
||||
-- Fallback functions for when `intllib` is not installed.
|
||||
-- Code released under Unlicense <http://unlicense.org>.
|
||||
|
||||
-- Get the latest version of this file at:
|
||||
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
|
||||
|
||||
local function format(str, ...)
|
||||
local args = { ... }
|
||||
local function repl(escape, open, num, close)
|
||||
if escape == "" then
|
||||
local replacement = tostring(args[tonumber(num)])
|
||||
if open == "" then
|
||||
replacement = replacement..close
|
||||
end
|
||||
return replacement
|
||||
else
|
||||
return "@"..open..num..close
|
||||
end
|
||||
end
|
||||
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
|
||||
end
|
||||
|
||||
local gettext, ngettext
|
||||
if minetest.get_modpath("intllib") then
|
||||
if intllib.make_gettext_pair then
|
||||
-- New method using gettext.
|
||||
gettext, ngettext = intllib.make_gettext_pair()
|
||||
else
|
||||
-- Old method using text files.
|
||||
gettext = intllib.Getter()
|
||||
end
|
||||
end
|
||||
|
||||
-- Fill in missing functions.
|
||||
|
||||
gettext = gettext or function(msgid, ...)
|
||||
return format(msgid, ...)
|
||||
end
|
||||
|
||||
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
|
||||
return format(n==1 and msgid or msgid_plural, ...)
|
||||
end
|
||||
|
||||
return gettext, ngettext
|
9
locale/fr.txt
Normal file
9
locale/fr.txt
Normal file
@ -0,0 +1,9 @@
|
||||
[%s] Maker pen was used but player name or node infos were not found. = Un feutre à été utilisé mais le nom du joueur ou les informations du bloc n'ont pas été trouvés.
|
||||
[%s] Maker pen was used but node name was not found. = Un feutre à été utilisé mais le nom du bloc n'a pas été trouvé.
|
||||
[%s] Maker pen was used by %s but nodes lists were not defined = Un feutre à été utilisé par %s mais les listes de blocs n'ont pas été définies
|
||||
This node ('%s') cannot be edited with the marker pen = Le feutre ne peut pas être utilisé sur ce bloc ('%s')
|
||||
%s is the owner of this node, you are not allowed to modify it = Ce bloc apparient à %s, vous n'êtes pas autorisé à la modifier
|
||||
%s is the owner of this door, you are not allowed to modify it = Cette porte apparient à %s, vous n'êtes pas autorisé à la modifier
|
||||
Write = Écrire
|
||||
%s wrote '%s' at %s = %s à écrit '%s' à la position %s
|
||||
Marker = Feutre
|
9
locale/template.txt
Normal file
9
locale/template.txt
Normal file
@ -0,0 +1,9 @@
|
||||
[%s] Maker pen was used but player name or node infos were not found. =
|
||||
[%s] Maker pen was used but node name was not found. =
|
||||
[%s] Maker pen was used by %s but nodes lists were not defined =
|
||||
This node ('%s') cannot be edited with the marker pen =
|
||||
%s is the owner of this node, you are not allowed to modify it =
|
||||
%s is the owner of this door, you are not allowed to modify it =
|
||||
Write =
|
||||
%s wrote '%s' at %s =
|
||||
Marker =
|
BIN
textures/marker.png
Normal file
BIN
textures/marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 299 B |
Loading…
x
Reference in New Issue
Block a user