Add privilege for rotating nodes (disabled by default)

master
Rogier 2015-02-26 00:29:21 +01:00
parent f8af1eea5d
commit 4d71fb9942
4 changed files with 35 additions and 4 deletions

View File

@ -1,3 +1,5 @@
v1.2
Added an option for a rotation privilege. Off by default
v1.1
Dependency on default is now optional
Provide an API for other mods to define their own wrenches

View File

@ -65,7 +65,7 @@ The wrench has three major modes of operation:
.. image:: images/wrench_positioning_absolute_cube.png
.. image:: images/wrench_positioning_absolute_cube_2.png
2) Positioning mode (relative)
3) Positioning mode (relative)
In this mode, when punching a node, the node is rotated to a preconfigured
orientation with respect to the punched side and the player. I.e. if the wrench
is configured by right-clicking a specific side of a node, then when another
@ -173,6 +173,12 @@ A rotation-mode wrench can also be crafted to a relative positioning mode wrench
which can be crafted to an absolute positioning mode wrench, which can be crafted
back to a rotation-mode wrench.
Privilege
---------
Optionally, the use of the wrench can be made subject to a privilege, named 'twist'.
This privilege is not enabled by default.
API
---
@ -279,8 +285,8 @@ intendend to be able to run on Windows (or anywhere else than on my system,
for that matter :-) - although you are welcome to try).
Other notes
-----------
Notes
-----
The operation of the wrench has been optimized: all required information is precomputed
at startup. Actual operation of a wrench basically requires just a few table lookups.

View File

@ -24,6 +24,11 @@ local default_wrenches = {
local mod_name = "rotate"
local privilege_name
-- Privilege associated with the wrench.
-- privilege checking is disabled if set to nil (or false)
--privilege_name = "twist"
-- Choose recipe.
-- Options:
-- "beak_north" -- may conflict with another wrench (technic ?)
@ -63,6 +68,7 @@ module.api_config = {
alt_recipe = alt_recipe,
wrench_orientation_indicator = wrench_orientation_indicator,
wrench_uses_steel = wrench_uses_steel,
privilege_name = privilege_name,
}
module.wrenches_config = {
default_wrenches = default_wrenches,

View File

@ -475,6 +475,17 @@ local function creative_mode(player)
minetest.get_player_privs(player:get_player_name()).creative
end
local function register_rotation_privilege()
if module.api_config.privilege_name ~= nil then
minetest.register_privilege(module.api_config.privilege_name, "Can rotate nodes using the node rotation wrench")
end
end
local function has_rotation_privilege(player)
return module.api_config.privilege_name == nil
or minetest.get_player_privs(player:get_player_name())[module.api_config.privilege_name]
end
-- Check whether this is the same node as previously rotated
-- (if so, return true, else false)
-- and remember this node for the next time.
@ -553,6 +564,10 @@ local function wrench_handler(itemstack, player, pointed_thing, mode, material,
minetest.record_protection_violation(pos, player:get_player_name())
return
end
if not has_rotation_privilege(player) then
minetest.chat_send_player(player:get_player_name(),"You are not allowed to rotate nodes")
return
end
local node = minetest.get_node(pos)
local ndef = minetest.registered_nodes[node.name]
@ -809,7 +824,7 @@ local function register_crafting_helper()
end
end
end
if known_wrenches[itemstack:get_name()] ~= nil then
if known_wrenches[ingredient:get_name()] ~= nil then
itemstack:set_wear(ingredient:get_wear())
end
end
@ -902,7 +917,9 @@ module.api = {
wrench_uses_steel = module.wrenches_config.wrench_uses_steel,
}
compute_wrench_orientation_codes()
precompute_clockwise_rotations()
register_rotation_privilege()
register_crafting_helper()