aboutsummaryrefslogtreecommitdiff
path: root/builtin/game
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/game')
-rw-r--r--builtin/game/chat.lua22
-rw-r--r--builtin/game/deprecated.lua25
-rw-r--r--builtin/game/falling.lua52
-rw-r--r--builtin/game/features.lua2
-rw-r--r--builtin/game/item.lua16
-rw-r--r--builtin/game/item_entity.lua5
-rw-r--r--builtin/game/knockback.lua2
-rw-r--r--builtin/game/misc.lua29
-rw-r--r--builtin/game/register.lua9
-rw-r--r--builtin/game/statbars.lua4
10 files changed, 102 insertions, 64 deletions
diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua
index aae811794..945707623 100644
--- a/builtin/game/chat.lua
+++ b/builtin/game/chat.lua
@@ -58,6 +58,11 @@ core.register_on_chat_message(function(name, message)
param = param or ""
+ -- Run core.registered_on_chatcommands callbacks.
+ if core.run_callbacks(core.registered_on_chatcommands, 5, name, cmd, param) then
+ return true
+ end
+
local cmd_def = core.registered_chatcommands[cmd]
if not cmd_def then
core.chat_send_player(name, "-!- Invalid command: " .. cmd)
@@ -66,8 +71,17 @@ 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 _, result = cmd_def.func(name, param)
- if result then
+ local success, result = cmd_def.func(name, param)
+ if success == false and result == nil then
+ core.chat_send_player(name, "-!- Invalid command usage")
+ local help_def = core.registered_chatcommands["help"]
+ if help_def then
+ local _, helpmsg = help_def.func(name, cmd)
+ if helpmsg then
+ core.chat_send_player(name, helpmsg)
+ end
+ end
+ elseif result then
core.chat_send_player(name, result)
end
else
@@ -1070,10 +1084,10 @@ core.register_chatcommand("last-login", {
local pauth = core.get_auth_handler().get_auth(param)
if pauth and pauth.last_login and pauth.last_login ~= -1 then
-- Time in UTC, ISO 8601 format
- return true, "Last login time was " ..
+ return true, param.."'s last login time was " ..
os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login)
end
- return false, "Last login time is unknown"
+ return false, param.."'s last login time is unknown"
end,
})
diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua
index 20f0482eb..c5c7848f5 100644
--- a/builtin/game/deprecated.lua
+++ b/builtin/game/deprecated.lua
@@ -1,29 +1,6 @@
-- Minetest: builtin/deprecated.lua
--
--- Default material types
---
-local function digprop_err()
- core.log("deprecated", "The core.digprop_* functions are obsolete and need to be replaced by item groups.")
-end
-
-core.digprop_constanttime = digprop_err
-core.digprop_stonelike = digprop_err
-core.digprop_dirtlike = digprop_err
-core.digprop_gravellike = digprop_err
-core.digprop_woodlike = digprop_err
-core.digprop_leaveslike = digprop_err
-core.digprop_glasslike = digprop_err
-
-function core.node_metadata_inventory_move_allow_all()
- core.log("deprecated", "core.node_metadata_inventory_move_allow_all is obsolete and does nothing.")
-end
-
-function core.add_to_creative_inventory(itemstring)
- core.log("deprecated", "core.add_to_creative_inventory is obsolete and does nothing.")
-end
-
---
-- EnvRef
--
core.env = {}
@@ -77,7 +54,7 @@ core.setting_save = setting_proxy("write")
function core.register_on_auth_fail(func)
core.log("deprecated", "core.register_on_auth_fail " ..
- "is obsolete and should be replaced by " ..
+ "is deprecated and should be replaced by " ..
"core.register_on_authplayer instead.")
core.register_on_authplayer(function (player_name, ip, is_success)
diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua
index 714506a5f..057d0d0ed 100644
--- a/builtin/game/falling.lua
+++ b/builtin/game/falling.lua
@@ -52,6 +52,7 @@ core.register_entity(":__builtin:falling_node", {
floats = false,
set_node = function(self, node, meta)
+ node.param2 = node.param2 or 0
self.node = node
meta = meta or {}
if type(meta.to_table) == "function" then
@@ -83,6 +84,9 @@ 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
@@ -126,7 +130,7 @@ core.register_entity(":__builtin:falling_node", {
-- Set collision box (certain nodeboxes only for now)
local nb_types = {fixed=true, leveled=true, connected=true}
if def.drawtype == "nodebox" and def.node_box and
- nb_types[def.node_box.type] then
+ nb_types[def.node_box.type] and def.node_box.fixed then
local box = table.copy(def.node_box.fixed)
if type(box[1]) == "table" then
box = #box == 1 and box[1] or nil -- We can only use a single box
@@ -143,9 +147,13 @@ core.register_entity(":__builtin:falling_node", {
-- Rotate entity
if def.drawtype == "torchlike" then
- self.object:set_yaw(math.pi*0.25)
- elseif (node.param2 ~= 0 and (def.wield_image == ""
- or def.wield_image == nil))
+ if def.paramtype2 == "wallmounted" then
+ self.object:set_yaw(math.pi*0.25)
+ else
+ self.object:set_yaw(-math.pi*0.25)
+ end
+ 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"
or def.drawtype == "mesh"
or def.drawtype == "normal"
@@ -160,16 +168,30 @@ core.register_entity(":__builtin:falling_node", {
elseif (def.paramtype2 == "wallmounted" or def.paramtype2 == "colorwallmounted") then
local rot = node.param2 % 8
local pitch, yaw, roll = 0, 0, 0
- if rot == 1 then
- pitch, yaw = math.pi, math.pi
- elseif rot == 2 then
- pitch, yaw = math.pi/2, math.pi/2
- elseif rot == 3 then
- pitch, yaw = math.pi/2, -math.pi/2
- elseif rot == 4 then
- pitch, yaw = math.pi/2, math.pi
- elseif rot == 5 then
- pitch, yaw = math.pi/2, 0
+ if def.drawtype == "nodebox" or def.drawtype == "mesh" then
+ if rot == 0 then
+ pitch, yaw = math.pi/2, 0
+ elseif rot == 1 then
+ pitch, yaw = -math.pi/2, math.pi
+ elseif rot == 2 then
+ pitch, yaw = 0, math.pi/2
+ elseif rot == 3 then
+ pitch, yaw = 0, -math.pi/2
+ elseif rot == 4 then
+ pitch, yaw = 0, math.pi
+ end
+ else
+ if rot == 1 then
+ pitch, yaw = math.pi, math.pi
+ elseif rot == 2 then
+ pitch, yaw = math.pi/2, math.pi/2
+ elseif rot == 3 then
+ pitch, yaw = math.pi/2, -math.pi/2
+ elseif rot == 4 then
+ pitch, yaw = math.pi/2, math.pi
+ elseif rot == 5 then
+ pitch, yaw = math.pi/2, 0
+ end
end
if def.drawtype == "signlike" then
pitch = pitch - math.pi/2
@@ -178,7 +200,7 @@ core.register_entity(":__builtin:falling_node", {
elseif rot == 1 then
yaw = yaw - math.pi/2
end
- elseif def.drawtype == "mesh" or def.drawtype == "normal" then
+ elseif def.drawtype == "mesh" or def.drawtype == "normal" or def.drawtype == "nodebox" then
if rot >= 0 and rot <= 1 then
roll = roll + math.pi
else
diff --git a/builtin/game/features.lua b/builtin/game/features.lua
index a15475333..36ff1f0b0 100644
--- a/builtin/game/features.lua
+++ b/builtin/game/features.lua
@@ -17,6 +17,8 @@ core.features = {
area_store_persistent_ids = true,
pathfinder_works = true,
object_step_has_moveresult = true,
+ direct_velocity_on_players = true,
+ use_texture_alpha_string_modes = true,
}
function core.has_feature(arg)
diff --git a/builtin/game/item.lua b/builtin/game/item.lua
index f680ce0d4..b68177c22 100644
--- a/builtin/game/item.lua
+++ b/builtin/game/item.lua
@@ -551,12 +551,13 @@ function core.node_dig(pos, node, digger)
local diggername = user_name(digger)
local log = make_log(diggername)
local def = core.registered_nodes[node.name]
+ -- Copy pos because the callback could modify it
if def and (not def.diggable or
- (def.can_dig and not def.can_dig(pos, digger))) then
+ (def.can_dig and not def.can_dig(vector.new(pos), digger))) then
log("info", diggername .. " tried to dig "
.. node.name .. " which is not diggable "
.. core.pos_to_string(pos))
- return
+ return false
end
if core.is_protected(pos, diggername) then
@@ -565,7 +566,7 @@ function core.node_dig(pos, node, digger)
.. " at protected position "
.. core.pos_to_string(pos))
core.record_protection_violation(pos, diggername)
- return
+ return false
end
log('action', diggername .. " digs "
@@ -648,6 +649,8 @@ function core.node_dig(pos, node, digger)
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
callback(pos_copy, node_copy, digger)
end
+
+ return true
end
function core.itemstring_with_palette(item, palette_index)
@@ -675,7 +678,7 @@ end
-- Item definition defaults
--
-local default_stack_max = tonumber(minetest.settings:get("default_stack_max")) or 99
+local default_stack_max = tonumber(core.settings:get("default_stack_max")) or 99
core.nodedef_default = {
-- Item properties
@@ -704,10 +707,6 @@ core.nodedef_default = {
on_receive_fields = nil,
- on_metadata_inventory_move = core.node_metadata_inventory_move_allow_all,
- on_metadata_inventory_offer = core.node_metadata_inventory_offer_allow_all,
- on_metadata_inventory_take = core.node_metadata_inventory_take_allow_all,
-
-- Node properties
drawtype = "normal",
visual_scale = 1.0,
@@ -718,7 +717,6 @@ core.nodedef_default = {
-- {name="", backface_culling=true},
-- {name="", backface_culling=true},
--},
- alpha = 255,
post_effect_color = {a=0, r=0, g=0, b=0},
paramtype = "none",
paramtype2 = "none",
diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua
index 20dd18044..9b1b23bfd 100644
--- a/builtin/game/item_entity.lua
+++ b/builtin/game/item_entity.lua
@@ -54,8 +54,9 @@ core.register_entity(":__builtin:item", {
local max_count = stack:get_stack_max()
local count = math.min(stack:get_count(), max_count)
local size = 0.2 + 0.1 * (count / max_count) ^ (1 / 3)
- local def = core.registered_nodes[itemname]
- local glow = def and math.floor(def.light_source / 2 + 0.5)
+ local def = core.registered_items[itemname]
+ local glow = def and def.light_source and
+ math.floor(def.light_source / 2 + 0.5)
self.object:set_properties({
is_visible = true,
diff --git a/builtin/game/knockback.lua b/builtin/game/knockback.lua
index b5c4cbc5a..a937aa186 100644
--- a/builtin/game/knockback.lua
+++ b/builtin/game/knockback.lua
@@ -42,5 +42,5 @@ core.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool
return -- barely noticeable, so don't even send
end
- player:add_player_velocity(kdir)
+ player:add_velocity(kdir)
end)
diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua
index 341e613c2..b8c5e16a9 100644
--- a/builtin/game/misc.lua
+++ b/builtin/game/misc.lua
@@ -151,6 +151,12 @@ function core.setting_get_pos(name)
end
+-- See l_env.cpp for the other functions
+function core.get_artificial_light(param1)
+ return math.floor(param1 / 16)
+end
+
+
-- To be overriden by protection mods
function core.is_protected(pos, name)
@@ -260,3 +266,26 @@ end
function core.cancel_shutdown_requests()
core.request_shutdown("", false, -1)
end
+
+
+-- Callback handling for dynamic_add_media
+
+local dynamic_add_media_raw = core.dynamic_add_media_raw
+core.dynamic_add_media_raw = nil
+function core.dynamic_add_media(filepath, callback)
+ local ret = dynamic_add_media_raw(filepath)
+ if ret == false then
+ return ret
+ end
+ if callback == nil then
+ core.log("deprecated", "Calling minetest.dynamic_add_media without "..
+ "a callback is deprecated and will stop working in future versions.")
+ else
+ -- At the moment async loading is not actually implemented, so we
+ -- immediately call the callback ourselves
+ for _, name in ipairs(ret) do
+ callback(name)
+ end
+ end
+ return true
+end
diff --git a/builtin/game/register.lua b/builtin/game/register.lua
index 1034d4f2b..1cff85813 100644
--- a/builtin/game/register.lua
+++ b/builtin/game/register.lua
@@ -320,13 +320,6 @@ for name in pairs(forbidden_item_names) do
register_alias_raw(name, "")
end
-
--- Obsolete:
--- Aliases for core.register_alias (how ironic...)
--- core.alias_node = core.register_alias
--- core.alias_tool = core.register_alias
--- core.alias_craftitem = core.register_alias
-
--
-- Built-in node definitions. Also defined in C.
--
@@ -584,6 +577,7 @@ core.unregister_biome = make_wrap_deregistration(core.register_biome,
core.clear_registered_biomes, core.registered_biomes)
core.registered_on_chat_messages, core.register_on_chat_message = make_registration()
+core.registered_on_chatcommands, core.register_on_chatcommand = make_registration()
core.registered_globalsteps, core.register_globalstep = make_registration()
core.registered_playerevents, core.register_playerevent = make_registration()
core.registered_on_mods_loaded, core.register_on_mods_loaded = make_registration()
@@ -612,6 +606,7 @@ core.registered_can_bypass_userlimit, core.register_can_bypass_userlimit = make_
core.registered_on_modchannel_message, core.register_on_modchannel_message = make_registration()
core.registered_on_player_inventory_actions, core.register_on_player_inventory_action = make_registration()
core.registered_allow_player_inventory_actions, core.register_allow_player_inventory_action = make_registration()
+core.registered_on_rightclickplayers, core.register_on_rightclickplayer = make_registration()
--
-- Compatibility for on_mapgen_init()
diff --git a/builtin/game/statbars.lua b/builtin/game/statbars.lua
index d192029c5..db5087a16 100644
--- a/builtin/game/statbars.lua
+++ b/builtin/game/statbars.lua
@@ -84,8 +84,8 @@ local function update_builtin_statbars(player)
end
if hud.id_breathbar and (not show_breathbar or breath == breath_max) then
- minetest.after(1, function(player_name, breath_bar)
- local player = minetest.get_player_by_name(player_name)
+ core.after(1, function(player_name, breath_bar)
+ local player = core.get_player_by_name(player_name)
if player then
player:hud_remove(breath_bar)
end