aboutsummaryrefslogtreecommitdiff
path: root/builtin/game
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/game')
-rw-r--r--builtin/game/chat.lua115
-rw-r--r--builtin/game/falling.lua25
-rw-r--r--builtin/game/features.lua1
-rw-r--r--builtin/game/item.lua15
-rw-r--r--builtin/game/privileges.lua8
5 files changed, 113 insertions, 51 deletions
diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua
index bf2d7851e..0bd12c25f 100644
--- a/builtin/game/chat.lua
+++ b/builtin/game/chat.lua
@@ -75,9 +75,9 @@ core.register_on_chat_message(function(name, message)
local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
if has_privs then
core.set_last_run_mod(cmd_def.mod_origin)
- local t_before = minetest.get_us_time()
+ local t_before = core.get_us_time()
local success, result = cmd_def.func(name, param)
- local delay = (minetest.get_us_time() - t_before) / 1000000
+ local delay = (core.get_us_time() - t_before) / 1000000
if success == false and result == nil then
core.chat_send_player(name, "-!- "..S("Invalid command usage."))
local help_def = core.registered_chatcommands["help"]
@@ -91,11 +91,12 @@ core.register_on_chat_message(function(name, message)
if delay > msg_time_threshold then
-- Show how much time it took to execute the command
if result then
- result = result ..
- minetest.colorize("#f3d2ff", " (%.5g s)"):format(delay)
+ result = result .. core.colorize("#f3d2ff", S(" (@1 s)",
+ string.format("%.5f", delay)))
else
- result = minetest.colorize("#f3d2ff",
- "Command execution took %.5f s"):format(delay)
+ result = core.colorize("#f3d2ff", S(
+ "Command execution took @1 s",
+ string.format("%.5f", delay)))
end
end
if result then
@@ -166,6 +167,18 @@ core.register_chatcommand("admin", {
end,
})
+local function privileges_of(name, privs)
+ if not privs then
+ privs = core.get_player_privs(name)
+ end
+ local privstr = core.privs_to_string(privs, ", ")
+ if privstr == "" then
+ return S("@1 does not have any privileges.", name)
+ else
+ return S("Privileges of @1: @2", name, privstr)
+ end
+end
+
core.register_chatcommand("privs", {
params = S("[<name>]"),
description = S("Show privileges of yourself or another player"),
@@ -175,9 +188,7 @@ core.register_chatcommand("privs", {
if not core.player_exists(name) then
return false, S("Player @1 does not exist.", name)
end
- return true, S("Privileges of @1: @2", name,
- core.privs_to_string(
- core.get_player_privs(name), ", "))
+ return true, privileges_of(name)
end,
})
@@ -226,7 +237,10 @@ local function handle_grant_command(caller, grantname, grantprivstr)
core.string_to_privs(core.settings:get("basic_privs") or "interact,shout")
for priv, _ in pairs(grantprivs) do
if not basic_privs[priv] and not caller_privs.privs then
- return false, S("Your privileges are insufficient.")
+ return false, S("Your privileges are insufficient. "..
+ "'@1' only allows you to grant: @2",
+ "basic_privs",
+ core.privs_to_string(basic_privs, ', '))
end
if not core.registered_privileges[priv] then
privs_unknown = privs_unknown .. S("Unknown privilege: @1", priv) .. "\n"
@@ -245,15 +259,13 @@ local function handle_grant_command(caller, grantname, grantprivstr)
if grantname ~= caller then
core.chat_send_player(grantname,
S("@1 granted you privileges: @2", caller,
- core.privs_to_string(grantprivs, ' ')))
+ core.privs_to_string(grantprivs, ', ')))
end
- return true, S("Privileges of @1: @2", grantname,
- core.privs_to_string(
- core.get_player_privs(grantname), ' '))
+ return true, privileges_of(grantname)
end
core.register_chatcommand("grant", {
- params = S("<name> (<privilege> | all)"),
+ params = S("<name> (<privilege> [, <privilege2> [<...>]] | all)"),
description = S("Give privileges to player"),
func = function(name, param)
local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
@@ -265,7 +277,7 @@ core.register_chatcommand("grant", {
})
core.register_chatcommand("grantme", {
- params = S("<privilege> | all"),
+ params = S("<privilege> [, <privilege2> [<...>]] | all"),
description = S("Grant privileges to yourself"),
func = function(name, param)
if param == "" then
@@ -285,16 +297,13 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
return false, S("Player @1 does not exist.", revokename)
end
- local revokeprivs = core.string_to_privs(revokeprivstr)
local privs = core.get_player_privs(revokename)
- local basic_privs =
- core.string_to_privs(core.settings:get("basic_privs") or "interact,shout")
- for priv, _ in pairs(revokeprivs) do
- if not basic_privs[priv] and not caller_privs.privs then
- return false, S("Your privileges are insufficient.")
- end
- end
+ local revokeprivs = core.string_to_privs(revokeprivstr)
+ local is_singleplayer = core.is_singleplayer()
+ local is_admin = not is_singleplayer
+ and revokename == core.settings:get("name")
+ and revokename ~= ""
if revokeprivstr == "all" then
revokeprivs = privs
privs = {}
@@ -304,27 +313,73 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
end
end
+ local privs_unknown = ""
+ local basic_privs =
+ core.string_to_privs(core.settings:get("basic_privs") or "interact,shout")
+ local irrevokable = {}
+ local has_irrevokable_priv = false
+ for priv, _ in pairs(revokeprivs) do
+ if not basic_privs[priv] and not caller_privs.privs then
+ return false, S("Your privileges are insufficient. "..
+ "'@1' only allows you to revoke: @2",
+ "basic_privs",
+ core.privs_to_string(basic_privs, ', '))
+ end
+ local def = core.registered_privileges[priv]
+ if not def then
+ privs_unknown = privs_unknown .. S("Unknown privilege: @1", priv) .. "\n"
+ elseif is_singleplayer and def.give_to_singleplayer then
+ irrevokable[priv] = true
+ elseif is_admin and def.give_to_admin then
+ irrevokable[priv] = true
+ end
+ end
+ for priv, _ in pairs(irrevokable) do
+ revokeprivs[priv] = nil
+ has_irrevokable_priv = true
+ end
+ if privs_unknown ~= "" then
+ return false, privs_unknown
+ end
+ if has_irrevokable_priv then
+ if is_singleplayer then
+ core.chat_send_player(caller,
+ S("Note: Cannot revoke in singleplayer: @1",
+ core.privs_to_string(irrevokable, ', ')))
+ elseif is_admin then
+ core.chat_send_player(caller,
+ S("Note: Cannot revoke from admin: @1",
+ core.privs_to_string(irrevokable, ', ')))
+ end
+ end
+
+ local revokecount = 0
for priv, _ in pairs(revokeprivs) do
-- call the on_revoke callbacks
core.run_priv_callbacks(revokename, priv, caller, "revoke")
+ revokecount = revokecount + 1
end
core.set_player_privs(revokename, privs)
+ local new_privs = core.get_player_privs(revokename)
+
+ if revokecount == 0 then
+ return false, S("No privileges were revoked.")
+ end
+
core.log("action", caller..' revoked ('
..core.privs_to_string(revokeprivs, ', ')
..') privileges from '..revokename)
if revokename ~= caller then
core.chat_send_player(revokename,
S("@1 revoked privileges from you: @2", caller,
- core.privs_to_string(revokeprivs, ' ')))
+ core.privs_to_string(revokeprivs, ', ')))
end
- return true, S("Privileges of @1: @2", revokename,
- core.privs_to_string(
- core.get_player_privs(revokename), ' '))
+ return true, privileges_of(revokename, new_privs)
end
core.register_chatcommand("revoke", {
- params = S("<name> (<privilege> | all)"),
+ params = S("<name> (<privilege> [, <privilege2> [<...>]] | all)"),
description = S("Remove privileges from player"),
privs = {},
func = function(name, param)
@@ -337,7 +392,7 @@ core.register_chatcommand("revoke", {
})
core.register_chatcommand("revokeme", {
- params = S("<privilege> | all"),
+ params = S("<privilege> [, <privilege2> [<...>]] | all"),
description = S("Revoke privileges from yourself"),
privs = {},
func = function(name, param)
diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua
index 057d0d0ed..2cc0d8fac 100644
--- a/builtin/game/falling.lua
+++ b/builtin/game/falling.lua
@@ -84,9 +84,6 @@ core.register_entity(":__builtin:falling_node", {
local textures
if def.tiles and def.tiles[1] then
local tile = def.tiles[1]
- if def.drawtype == "torchlike" and def.paramtype2 ~= "wallmounted" then
- tile = def.tiles[2] or def.tiles[1]
- end
if type(tile) == "table" then
tile = tile.name
end
@@ -147,11 +144,7 @@ core.register_entity(":__builtin:falling_node", {
-- Rotate entity
if def.drawtype == "torchlike" then
- if def.paramtype2 == "wallmounted" then
- self.object:set_yaw(math.pi*0.25)
- else
- self.object:set_yaw(-math.pi*0.25)
- end
+ self.object:set_yaw(math.pi*0.25)
elseif ((node.param2 ~= 0 or def.drawtype == "nodebox" or def.drawtype == "mesh")
and (def.wield_image == "" or def.wield_image == nil))
or def.drawtype == "signlike"
@@ -165,8 +158,12 @@ core.register_entity(":__builtin:falling_node", {
if euler then
self.object:set_rotation(euler)
end
- elseif (def.paramtype2 == "wallmounted" or def.paramtype2 == "colorwallmounted") then
+ elseif (def.paramtype2 == "wallmounted" or def.paramtype2 == "colorwallmounted" or def.drawtype == "signlike") then
local rot = node.param2 % 8
+ if (def.drawtype == "signlike" and def.paramtype2 ~= "wallmounted" and def.paramtype2 ~= "colorwallmounted") then
+ -- Change rotation to "floor" by default for non-wallmounted paramtype2
+ rot = 1
+ end
local pitch, yaw, roll = 0, 0, 0
if def.drawtype == "nodebox" or def.drawtype == "mesh" then
if rot == 0 then
@@ -208,6 +205,14 @@ core.register_entity(":__builtin:falling_node", {
end
end
self.object:set_rotation({x=pitch, y=yaw, z=roll})
+ elseif (def.drawtype == "mesh" and def.paramtype2 == "degrotate") then
+ local p2 = (node.param2 - (def.place_param2 or 0)) % 240
+ local yaw = (p2 / 240) * (math.pi * 2)
+ self.object:set_yaw(yaw)
+ elseif (def.drawtype == "mesh" and def.paramtype2 == "colordegrotate") then
+ local p2 = (node.param2 % 32 - (def.place_param2 or 0) % 32) % 24
+ local yaw = (p2 / 24) * (math.pi * 2)
+ self.object:set_yaw(yaw)
end
end
end,
@@ -407,7 +412,7 @@ local function convert_to_falling_node(pos, node)
obj:get_luaentity():set_node(node, metatable)
core.remove_node(pos)
- return true
+ return true, obj
end
function core.spawn_falling_node(pos)
diff --git a/builtin/game/features.lua b/builtin/game/features.lua
index 36ff1f0b0..8f0604448 100644
--- a/builtin/game/features.lua
+++ b/builtin/game/features.lua
@@ -19,6 +19,7 @@ core.features = {
object_step_has_moveresult = true,
direct_velocity_on_players = true,
use_texture_alpha_string_modes = true,
+ degrotate_240_steps = true,
}
function core.has_feature(arg)
diff --git a/builtin/game/item.lua b/builtin/game/item.lua
index dc0247e5f..c4d93abd6 100644
--- a/builtin/game/item.lua
+++ b/builtin/game/item.lua
@@ -15,15 +15,6 @@ end
-- Item definition helpers
--
-function core.inventorycube(img1, img2, img3)
- img2 = img2 or img1
- img3 = img3 or img1
- return "[inventorycube"
- .. "{" .. img1:gsub("%^", "&")
- .. "{" .. img2:gsub("%^", "&")
- .. "{" .. img3:gsub("%^", "&")
-end
-
function core.dir_to_facedir(dir, is6d)
--account for y if requested
if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
@@ -144,7 +135,7 @@ end
function core.is_colored_paramtype(ptype)
return (ptype == "color") or (ptype == "colorfacedir") or
- (ptype == "colorwallmounted")
+ (ptype == "colorwallmounted") or (ptype == "colordegrotate")
end
function core.strip_param2_color(param2, paramtype2)
@@ -155,6 +146,8 @@ function core.strip_param2_color(param2, paramtype2)
param2 = math.floor(param2 / 32) * 32
elseif paramtype2 == "colorwallmounted" then
param2 = math.floor(param2 / 8) * 8
+ elseif paramtype2 == "colordegrotate" then
+ param2 = math.floor(param2 / 32) * 32
end
-- paramtype2 == "color" requires no modification.
return param2
@@ -332,6 +325,8 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
color_divisor = 8
elseif def.paramtype2 == "colorfacedir" then
color_divisor = 32
+ elseif def.paramtype2 == "colordegrotate" then
+ color_divisor = 32
end
if color_divisor then
local color = math.floor(metatable.palette_index / color_divisor)
diff --git a/builtin/game/privileges.lua b/builtin/game/privileges.lua
index aee32a34e..1d3efb525 100644
--- a/builtin/game/privileges.lua
+++ b/builtin/game/privileges.lua
@@ -32,7 +32,13 @@ end
core.register_privilege("interact", S("Can interact with things and modify the world"))
core.register_privilege("shout", S("Can speak in chat"))
-core.register_privilege("basic_privs", S("Can modify 'shout' and 'interact' privileges"))
+
+local basic_privs =
+ core.string_to_privs((core.settings:get("basic_privs") or "shout,interact"))
+local basic_privs_desc = S("Can modify basic privileges (@1)",
+ core.privs_to_string(basic_privs, ', '))
+core.register_privilege("basic_privs", basic_privs_desc)
+
core.register_privilege("privs", S("Can modify privileges"))
core.register_privilege("teleport", {