aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/chatcommands.lua32
-rw-r--r--builtin/deprecated.lua22
-rw-r--r--builtin/falling.lua28
-rw-r--r--builtin/item.lua22
-rw-r--r--builtin/item_entity.lua4
-rw-r--r--builtin/misc.lua2
6 files changed, 66 insertions, 44 deletions
diff --git a/builtin/chatcommands.lua b/builtin/chatcommands.lua
index f548fb01d..6a3b29e7c 100644
--- a/builtin/chatcommands.lua
+++ b/builtin/chatcommands.lua
@@ -261,7 +261,7 @@ minetest.register_chatcommand("teleport", {
}
for _, d in ipairs(tries) do
local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
- local n = minetest.env:get_node(p)
+ local n = minetest.get_node(p)
if not minetest.registered_nodes[n.name].walkable then
return p, true
end
@@ -272,7 +272,7 @@ minetest.register_chatcommand("teleport", {
local teleportee = nil
local p = {}
p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
- teleportee = minetest.env:get_player_by_name(name)
+ teleportee = minetest.get_player_by_name(name)
if teleportee and p.x and p.y and p.z then
minetest.chat_send_player(name, "Teleporting to ("..p.x..", "..p.y..", "..p.z..")")
teleportee:setpos(p)
@@ -283,9 +283,9 @@ minetest.register_chatcommand("teleport", {
local p = nil
local target_name = nil
target_name = string.match(param, "^([^ ]+)$")
- teleportee = minetest.env:get_player_by_name(name)
+ teleportee = minetest.get_player_by_name(name)
if target_name then
- local target = minetest.env:get_player_by_name(target_name)
+ local target = minetest.get_player_by_name(target_name)
if target then
p = target:getpos()
end
@@ -303,7 +303,7 @@ minetest.register_chatcommand("teleport", {
local teleportee_name = nil
teleportee_name, p.x, p.y, p.z = string.match(param, "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
if teleportee_name then
- teleportee = minetest.env:get_player_by_name(teleportee_name)
+ teleportee = minetest.get_player_by_name(teleportee_name)
end
if teleportee and p.x and p.y and p.z then
minetest.chat_send_player(name, "Teleporting "..teleportee_name.." to ("..p.x..", "..p.y..", "..p.z..")")
@@ -317,10 +317,10 @@ minetest.register_chatcommand("teleport", {
local target_name = nil
teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
if teleportee_name then
- teleportee = minetest.env:get_player_by_name(teleportee_name)
+ teleportee = minetest.get_player_by_name(teleportee_name)
end
if target_name then
- local target = minetest.env:get_player_by_name(target_name)
+ local target = minetest.get_player_by_name(target_name)
if target then
p = target:getpos()
end
@@ -402,7 +402,7 @@ local function handle_give_command(cmd, giver, receiver, stackstring)
minetest.chat_send_player(giver, 'error: cannot give an unknown item')
return
end
- local receiverref = minetest.env:get_player_by_name(receiver)
+ local receiverref = minetest.get_player_by_name(receiver)
if receiverref == nil then
minetest.chat_send_player(giver, receiver..' is not a known player')
return
@@ -466,14 +466,14 @@ minetest.register_chatcommand("spawnentity", {
return
end
print('/spawnentity invoked, entityname="'..entityname..'"')
- local player = minetest.env:get_player_by_name(name)
+ local player = minetest.get_player_by_name(name)
if player == nil then
print("Unable to spawn entity, player is nil")
return true -- Handled chat message
end
local p = player:getpos()
p.y = p.y + 1
- minetest.env:add_entity(p, entityname)
+ minetest.add_entity(p, entityname)
minetest.chat_send_player(name, '"'..entityname
..'" spawned.');
end,
@@ -483,7 +483,7 @@ minetest.register_chatcommand("pulverize", {
description = "delete item in hand",
privs = {},
func = function(name, param)
- local player = minetest.env:get_player_by_name(name)
+ local player = minetest.get_player_by_name(name)
if player == nil then
print("Unable to pulverize, player is nil")
return true -- Handled chat message
@@ -533,7 +533,7 @@ minetest.register_chatcommand("rollback_check", {
if act_p.x ~= pos.x or act_p.y ~= pos.y or act_p.z ~= pos.z then
nodedesc = minetest.pos_to_string(act_p)
end
- local nodename = minetest.env:get_node(act_p).name
+ local nodename = minetest.get_node(act_p).name
minetest.chat_send_player(name, "Last actor on "..nodedesc..
" was "..actor..", "..dump(act_seconds)..
"s ago (node is now "..nodename..")")
@@ -598,7 +598,7 @@ minetest.register_chatcommand("time", {
if newtime == nil then
minetest.chat_send_player(name, "Invalid time")
else
- minetest.env:set_timeofday((newtime % 24000) / 24000)
+ minetest.set_timeofday((newtime % 24000) / 24000)
minetest.chat_send_player(name, "Time of day changed.")
minetest.log("action", name .. " sets time " .. newtime)
end
@@ -625,7 +625,7 @@ minetest.register_chatcommand("ban", {
minetest.chat_send_player(name, "Ban list: " .. minetest.get_ban_list())
return
end
- if not minetest.env:get_player_by_name(param) then
+ if not minetest.get_player_by_name(param) then
minetest.chat_send_player(name, "No such player")
return
end
@@ -660,7 +660,7 @@ minetest.register_chatcommand("clearobjects", {
func = function(name, param)
minetest.log("action", name .. " clears all objects")
minetest.chat_send_all("Clearing all objects. This may take long. You may experience a timeout. (by " .. name .. ")")
- minetest.env:clear_objects()
+ minetest.clear_objects()
minetest.log("action", "object clearing done")
minetest.chat_send_all("*** Cleared all objects.")
end,
@@ -673,7 +673,7 @@ minetest.register_chatcommand("msg", {
func = function(name, param)
local found, _, sendto, message = param:find("^([^%s]+)%s(.+)$")
if found then
- if minetest.env:get_player_by_name(sendto) then
+ if minetest.get_player_by_name(sendto) then
minetest.log("action", "PM from "..name.." to "..sendto..": "..message)
minetest.chat_send_player(sendto, "PM from "..name..": "..message, false)
minetest.chat_send_player(name, "Message sent")
diff --git a/builtin/deprecated.lua b/builtin/deprecated.lua
index 405ce3b09..23ab38675 100644
--- a/builtin/deprecated.lua
+++ b/builtin/deprecated.lua
@@ -24,3 +24,25 @@ minetest.add_to_creative_inventory = function(itemstring)
minetest.log('info', "WARNING: minetest.add_to_creative_inventory: This function is deprecated and does nothing.")
end
+--
+-- EnvRef
+--
+minetest.env = {}
+local envref_deprecation_message_printed = false
+setmetatable(minetest.env, {
+ __index = function(table, key)
+ if not envref_deprecation_message_printed then
+ minetest.log("info", "WARNING: minetest.env:[...] is deprecated and should be replaced with minetest.[...]")
+ envref_deprecation_message_printed = true
+ end
+ local func = minetest[key]
+ if type(func) == "function" then
+ rawset(table, key, function(self, ...)
+ return func(unpack({...}))
+ end)
+ else
+ rawset(table, key, nil)
+ end
+ return rawget(table, key)
+ end
+})
diff --git a/builtin/falling.lua b/builtin/falling.lua
index f6491991b..5ee693298 100644
--- a/builtin/falling.lua
+++ b/builtin/falling.lua
@@ -53,27 +53,27 @@ minetest.register_entity("__builtin:falling_node", {
-- Turn to actual sand when collides to ground or just move
local pos = self.object:getpos()
local bcp = {x=pos.x, y=pos.y-0.7, z=pos.z} -- Position of bottom center point
- local bcn = minetest.env:get_node(bcp)
+ local bcn = minetest.get_node(bcp)
-- Note: walkable is in the node definition, not in item groups
if minetest.registered_nodes[bcn.name] and
minetest.registered_nodes[bcn.name].walkable then
if minetest.registered_nodes[bcn.name].buildable_to then
- minetest.env:remove_node(bcp)
+ minetest.remove_node(bcp)
return
end
local np = {x=bcp.x, y=bcp.y+1, z=bcp.z}
-- Check what's here
- local n2 = minetest.env:get_node(np)
+ local n2 = minetest.get_node(np)
-- If it's not air or liquid, remove node and replace it with
-- it's drops
if n2.name ~= "air" and (not minetest.registered_nodes[n2.name] or
minetest.registered_nodes[n2.name].liquidtype == "none") then
local drops = minetest.get_node_drops(n2.name, "")
- minetest.env:remove_node(np)
+ minetest.remove_node(np)
-- Add dropped items
local _, dropped_item
for _, dropped_item in ipairs(drops) do
- minetest.env:add_item(np, dropped_item)
+ minetest.add_item(np, dropped_item)
end
-- Run script hook
local _, callback
@@ -82,7 +82,7 @@ minetest.register_entity("__builtin:falling_node", {
end
end
-- Create node and remove entity
- minetest.env:add_node(np, {name=self.nodename})
+ minetest.add_node(np, {name=self.nodename})
self.object:remove()
nodeupdate(np)
else
@@ -92,20 +92,20 @@ minetest.register_entity("__builtin:falling_node", {
})
function spawn_falling_node(p, nodename)
- obj = minetest.env:add_entity(p, "__builtin:falling_node")
+ obj = minetest.add_entity(p, "__builtin:falling_node")
obj:get_luaentity():set_node(nodename)
end
function drop_attached_node(p)
- local nn = minetest.env:get_node(p).name
- minetest.env:remove_node(p)
+ local nn = minetest.get_node(p).name
+ minetest.remove_node(p)
for _,item in ipairs(minetest.get_node_drops(nn, "")) do
local pos = {
x = p.x + math.random()/2 - 0.25,
y = p.y + math.random()/2 - 0.25,
z = p.z + math.random()/2 - 0.25,
}
- minetest.env:add_item(pos, item)
+ minetest.add_item(pos, item)
end
end
@@ -130,7 +130,7 @@ function check_attached_node(p, n)
d.y = -1
end
local p2 = {x=p.x+d.x, y=p.y+d.y, z=p.z+d.z}
- local nn = minetest.env:get_node(p2).name
+ local nn = minetest.get_node(p2).name
local def2 = minetest.registered_nodes[nn]
if def2 and not def2.walkable then
return false
@@ -143,10 +143,10 @@ end
--
function nodeupdate_single(p, delay)
- n = minetest.env:get_node(p)
+ n = minetest.get_node(p)
if minetest.get_node_group(n.name, "falling_node") ~= 0 then
p_bottom = {x=p.x, y=p.y-1, z=p.z}
- n_bottom = minetest.env:get_node(p_bottom)
+ n_bottom = minetest.get_node(p_bottom)
-- Note: walkable is in the node definition, not in item groups
if minetest.registered_nodes[n_bottom.name] and
(not minetest.registered_nodes[n_bottom.name].walkable or
@@ -154,7 +154,7 @@ function nodeupdate_single(p, delay)
if delay then
minetest.after(0.1, nodeupdate_single, {x=p.x, y=p.y, z=p.z}, false)
else
- minetest.env:remove_node(p)
+ minetest.remove_node(p)
spawn_falling_node(p, n.name)
nodeupdate(p)
end
diff --git a/builtin/item.lua b/builtin/item.lua
index 51a17106a..85b4cc0e4 100644
--- a/builtin/item.lua
+++ b/builtin/item.lua
@@ -129,9 +129,9 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
end
local under = pointed_thing.under
- local oldnode_under = minetest.env:get_node_or_nil(under)
+ local oldnode_under = minetest.get_node_or_nil(under)
local above = pointed_thing.above
- local oldnode_above = minetest.env:get_node_or_nil(above)
+ local oldnode_above = minetest.get_node_or_nil(above)
if not oldnode_under or not oldnode_above then
minetest.log("info", placer:get_player_name() .. " tried to place"
@@ -163,7 +163,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
minetest.log("action", placer:get_player_name() .. " places node "
.. def.name .. " at " .. minetest.pos_to_string(place_to))
- local oldnode = minetest.env:get_node(place_to)
+ local oldnode = minetest.get_node(place_to)
local newnode = {name = def.name, param1 = 0, param2 = 0}
-- Calculate direction for wall mounted stuff like torches and signs
@@ -197,7 +197,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
end
-- Add node and update
- minetest.env:add_node(place_to, newnode)
+ minetest.add_node(place_to, newnode)
local take_item = true
@@ -232,7 +232,7 @@ function minetest.item_place_object(itemstack, placer, pointed_thing)
local pos = minetest.get_pointed_thing_position(pointed_thing, true)
if pos ~= nil then
local item = itemstack:take_item()
- minetest.env:add_item(pos, item)
+ minetest.add_item(pos, item)
end
return itemstack
end
@@ -241,7 +241,7 @@ function minetest.item_place(itemstack, placer, pointed_thing)
-- Call on_rightclick if the pointed node defines it
if pointed_thing.type == "node" and placer and
not placer:get_player_control().sneak then
- local n = minetest.env:get_node(pointed_thing.under)
+ local n = minetest.get_node(pointed_thing.under)
local nn = n.name
if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then
return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n, placer, itemstack) or itemstack
@@ -258,7 +258,7 @@ function minetest.item_drop(itemstack, dropper, pos)
if dropper.get_player_name then
local v = dropper:get_look_dir()
local p = {x=pos.x+v.x, y=pos.y+1.5+v.y, z=pos.z+v.z}
- local obj = minetest.env:add_item(p, itemstack)
+ local obj = minetest.add_item(p, itemstack)
if obj then
v.x = v.x*2
v.y = v.y*2 + 1
@@ -266,7 +266,7 @@ function minetest.item_drop(itemstack, dropper, pos)
obj:setvelocity(v)
end
else
- minetest.env:add_item(pos, itemstack)
+ minetest.add_item(pos, itemstack)
end
return ItemStack("")
end
@@ -304,7 +304,7 @@ function minetest.handle_node_drops(pos, drops, digger)
y = pos.y + math.random()/2-0.25,
z = pos.z + math.random()/2-0.25,
}
- minetest.env:add_item(p, left)
+ minetest.add_item(p, left)
end
end
end
@@ -340,11 +340,11 @@ function minetest.node_dig(pos, node, digger)
local oldmetadata = nil
if def.after_dig_node then
- oldmetadata = minetest.env:get_meta(pos):to_table()
+ oldmetadata = minetest.get_meta(pos):to_table()
end
-- Remove node and update
- minetest.env:remove_node(pos)
+ minetest.remove_node(pos)
-- Run callback
if def.after_dig_node then
diff --git a/builtin/item_entity.lua b/builtin/item_entity.lua
index 50ce7eafe..c682db2fa 100644
--- a/builtin/item_entity.lua
+++ b/builtin/item_entity.lua
@@ -3,7 +3,7 @@
function minetest.spawn_item(pos, item)
-- Take item in any format
local stack = ItemStack(item)
- local obj = minetest.env:add_entity(pos, "__builtin:item")
+ local obj = minetest.add_entity(pos, "__builtin:item")
obj:get_luaentity():set_item(stack:to_string())
return obj
end
@@ -83,7 +83,7 @@ minetest.register_entity("__builtin:item", {
on_step = function(self, dtime)
local p = self.object:getpos()
p.y = p.y - 0.3
- local nn = minetest.env:get_node(p).name
+ local nn = minetest.get_node(p).name
-- If node is not registered or node is walkably solid and resting on nodebox
local v = self.object:getvelocity()
if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and v.y == 0 then
diff --git a/builtin/misc.lua b/builtin/misc.lua
index 8308b3d6b..f4e7dbca6 100644
--- a/builtin/misc.lua
+++ b/builtin/misc.lua
@@ -43,7 +43,7 @@ end
function minetest.get_connected_players()
-- This could be optimized a bit, but leave that for later
local list = {}
- for _, obj in pairs(minetest.env:get_objects_inside_radius({x=0,y=0,z=0}, 1000000)) do
+ for _, obj in pairs(minetest.get_objects_inside_radius({x=0,y=0,z=0}, 1000000)) do
if obj:is_player() then
table.insert(list, obj)
end