Various small improvements (#7)

* Crafting recipe for item is now shapeless
* Item now uses right click to open in MineClone (otherwise still left click)
* Added `personal_log_teleport` privilege (and `personal_log_teleport_privilege` setting to enable), in case you only want people to teleport to places they've already been to and saved in the log, and not use `/teleport`
* Replaced `priviledge` with `privilege` everywhere it's misspelled
* Tested in both MineClone and Minetest Game
This commit is contained in:
ThePython 2023-04-11 10:29:08 -07:00 committed by GitHub
parent ad6c6b1138
commit 994c1a263d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 18 deletions

View File

@ -18,6 +18,8 @@ local ccompass_recalibration_allowed = minetest.settings:get_bool("ccompass_reca
local ccompass_restrict_target = minetest.settings:get_bool("ccompass_restrict_target", false)
local ccompass_description_prefix = "^Compass to "
local personal_log_teleport_privilege = minetest.settings:get_bool("personal_log_teleport_privilege", false)
local S = minetest.get_translator(modname)
local categories = {
@ -52,6 +54,26 @@ if mcl_formspec_modpath then
mcl_formspec_itemslot = mcl_formspec.get_itemslot_bg
end
if personal_log_teleport_privilege then
minetest.register_privilege("personal_log_teleport", {
description =S("Allows the player to teleport using the personal log"),
give_to_singleplayer = false,
give_to_admin = true,
})
privs = {personal_log_teleport=true}
end
local function can_teleport(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, "teleport") then
return true
elseif personal_log_teleport_privilege and minetest.check_player_privs(player_name, "personal_log_teleport") then
return true
else
return false
end
end
--------------------------------------------------------
-- Data store
@ -530,8 +552,7 @@ local function make_personal_log_formspec(player)
.."button[4.5,0;2,0.5;move_up;"..S("Move Up").."]"
.."button[4.5,0.75;2,0.5;move_down;"..S("Move Down").."]"
.."button[7,0;2,0.5;delete;"..S("Delete") .."]"
if category_index == LOCATION_CATEGORY and minetest.check_player_privs(player_name, "teleport") then
if category_index == LOCATION_CATEGORY and can_teleport(player) then
formspec[#formspec+1] = "button[7,0.75;2,0.5;teleport;"..S("Teleport") .."]"
end
@ -634,7 +655,7 @@ local function on_player_receive_fields(player, fields, update_callback)
if fields.teleport
and category == LOCATION_CATEGORY
and valid_entry_selected
and minetest.check_player_privs(player_name, "teleport") then
and (can_teleport(player)) then
local pos_string = modstore:get_string(player_name .. "_category_" .. category .. "_entry_" .. entry_selected .. "_topic")
local pos = minetest.string_to_pos(pos_string)
if pos then
@ -742,20 +763,41 @@ local craftable_setting = minetest.settings:get_bool("personal_log_craftable_ite
if craftable_setting or not (unified_inventory_modpath or sfinv_modpath or sfinv_buttons_modpath) then
minetest.register_craftitem("personal_log:book", {
description = S("Personal Log"),
inventory_image = "personal_log_open_book.png",
groups = {book = 1, flammable = 3},
on_use = function(itemstack, user, pointed_thing)
local name = user:get_player_name()
minetest.show_formspec(name,"personal_log:root", make_personal_log_formspec(user))
end,
})
local attributes = {
description = S("Personal Log"),
inventory_image = "personal_log_open_book.png",
groups = {book = 1, flammable = 3},
}
minetest.register_craft({
output = "personal_log:book",
recipe = {{book_unwritten, book_unwritten}}
})
if mcl_formspec_modpath then
attributes.on_secondary_use = function(itemstack, user, pointed_thing)
local name = user:get_player_name()
minetest.show_formspec(name,"personal_log:root", make_personal_log_formspec(user))
end
attributes.on_place = function(itemstack, user, pointed_thing)
if not user:get_player_control().sneak then
local new_stack = mcl_util.call_on_rightclick(itemstack, user, pointed_thing)
if new_stack then
return new_stack
end
end
local name = user:get_player_name()
minetest.show_formspec(name,"personal_log:root", make_personal_log_formspec(user))
end
else
attributes.on_use = function(itemstack, user, pointed_thing)
local name = user:get_player_name()
minetest.show_formspec(name,"personal_log:root", make_personal_log_formspec(user))
end
end
minetest.register_craftitem("personal_log:book", attributes)
minetest.register_craft({
output = "personal_log:book",
type = "shapeless",
recipe = {book_unwritten, book_unwritten}
})
end
@ -763,7 +805,8 @@ end
-- Chat command
local chat_command = minetest.settings:get_bool("personal_log_chat_command", false)
local chat_command_priv = minetest.settings:get_bool("personal_log_chat_command_priviledge", false)
local chat_command_priv = minetest.settings:get_bool("personal_log_chat_command_privilege", false)
or minetest.settings:get_bool("personal_log_chat_command_priviledge", false) -- backwards compat
if chat_command then
@ -818,3 +861,4 @@ end
personal_log.add_general_entry = function(player_name, content, general_topic)
add_entry_for_player(player_name, GENERAL_CATEGORY, content, general_topic)
end

View File

@ -1,4 +1,7 @@
personal_log_inventory_button (Access via a button in SFInv/Unified Inventory) bool true
personal_log_craftable_item (Access via a craftable item) bool false
personal_log_chat_command (Allow the /log chat command to open the log) bool false
personal_log_chat_command_priviledge (The personal_log privilege is required to access the log via chat command) bool false
personal_log_chat_command_privilege (The personal_log privilege is required to access the log via chat command) bool false
# True if the "personal_log_teleport" privilege is required to teleport, if false, the "teleport" privilege is used instead.
personal_log_teleport_privilege (Add personal_log_teleport privilege) bool false