summaryrefslogtreecommitdiff
path: root/builtin/game
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/game')
-rw-r--r--builtin/game/chat.lua17
-rw-r--r--builtin/game/deprecated.lua2
-rw-r--r--builtin/game/falling.lua140
-rw-r--r--builtin/game/features.lua1
-rw-r--r--builtin/game/item.lua52
-rw-r--r--builtin/game/item_entity.lua3
-rw-r--r--builtin/game/misc.lua16
-rw-r--r--builtin/game/register.lua8
8 files changed, 188 insertions, 51 deletions
diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua
index d0d456a46..fd1379162 100644
--- a/builtin/game/chat.lua
+++ b/builtin/game/chat.lua
@@ -115,6 +115,7 @@ core.register_chatcommand("me", {
privs = {shout=true},
func = function(name, param)
core.chat_send_all("* " .. name .. " " .. param)
+ return true
end,
})
@@ -141,7 +142,7 @@ core.register_chatcommand("privs", {
end
return true, "Privileges of " .. name .. ": "
.. core.privs_to_string(
- core.get_player_privs(name), ' ')
+ core.get_player_privs(name), ", ")
end,
})
@@ -919,12 +920,13 @@ core.register_chatcommand("shutdown", {
core.chat_send_all("*** Server shutting down (operator request).")
end
core.request_shutdown(message:trim(), core.is_yes(reconnect), delay)
+ return true
end,
})
core.register_chatcommand("ban", {
- params = "[<name> | <IP_address>]",
- description = "Ban player or show ban list",
+ params = "[<name>]",
+ description = "Ban the IP of a player or show the ban list",
privs = {ban=true},
func = function(name, param)
if param == "" then
@@ -936,7 +938,7 @@ core.register_chatcommand("ban", {
end
end
if not core.get_player_by_name(param) then
- return false, "No such player."
+ return false, "Player is not online."
end
if not core.ban_player(param) then
return false, "Failed to ban player."
@@ -949,7 +951,7 @@ core.register_chatcommand("ban", {
core.register_chatcommand("unban", {
params = "<name> | <IP_address>",
- description = "Remove player ban",
+ description = "Remove IP ban belonging to a player/IP",
privs = {ban=true},
func = function(name, param)
if not core.unban_player_or_ip(param) then
@@ -995,12 +997,13 @@ core.register_chatcommand("clearobjects", {
core.log("action", name .. " clears all objects ("
.. options.mode .. " mode).")
- core.chat_send_all("Clearing all objects. This may take long."
- .. " You may experience a timeout. (by "
+ core.chat_send_all("Clearing all objects. This may take a long time."
+ .. " You may experience a timeout. (by "
.. name .. ")")
core.clear_objects(options)
core.log("action", "Object clearing done.")
core.chat_send_all("*** Cleared all objects.")
+ return true
end,
})
diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua
index 1a9a96f2a..73e105eb8 100644
--- a/builtin/game/deprecated.lua
+++ b/builtin/game/deprecated.lua
@@ -20,7 +20,7 @@ function core.node_metadata_inventory_move_allow_all()
end
function core.add_to_creative_inventory(itemstring)
- core.log("deprecated", "core.add_to_creative_inventory: This function is deprecated and does nothing.")
+ core.log("deprecated", "core.add_to_creative_inventory is obsolete and does nothing.")
end
--
diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua
index 950d6b56f..ea02e3694 100644
--- a/builtin/game/falling.lua
+++ b/builtin/game/falling.lua
@@ -1,6 +1,34 @@
-- Minetest: builtin/item.lua
local builtin_shared = ...
+local SCALE = 0.667
+
+local facedir_to_euler = {
+ {y = 0, x = 0, z = 0},
+ {y = -math.pi/2, x = 0, z = 0},
+ {y = math.pi, x = 0, z = 0},
+ {y = math.pi/2, x = 0, z = 0},
+ {y = math.pi/2, x = -math.pi/2, z = math.pi/2},
+ {y = math.pi/2, x = math.pi, z = math.pi/2},
+ {y = math.pi/2, x = math.pi/2, z = math.pi/2},
+ {y = math.pi/2, x = 0, z = math.pi/2},
+ {y = -math.pi/2, x = math.pi/2, z = math.pi/2},
+ {y = -math.pi/2, x = 0, z = math.pi/2},
+ {y = -math.pi/2, x = -math.pi/2, z = math.pi/2},
+ {y = -math.pi/2, x = math.pi, z = math.pi/2},
+ {y = 0, x = 0, z = math.pi/2},
+ {y = 0, x = -math.pi/2, z = math.pi/2},
+ {y = 0, x = math.pi, z = math.pi/2},
+ {y = 0, x = math.pi/2, z = math.pi/2},
+ {y = math.pi, x = math.pi, z = math.pi/2},
+ {y = math.pi, x = math.pi/2, z = math.pi/2},
+ {y = math.pi, x = 0, z = math.pi/2},
+ {y = math.pi, x = -math.pi/2, z = math.pi/2},
+ {y = math.pi, x = math.pi, z = 0},
+ {y = -math.pi/2, x = math.pi, z = 0},
+ {y = 0, x = math.pi, z = 0},
+ {y = math.pi/2, x = math.pi, z = 0}
+}
--
-- Falling stuff
@@ -8,8 +36,8 @@ local builtin_shared = ...
core.register_entity(":__builtin:falling_node", {
initial_properties = {
- visual = "wielditem",
- visual_size = {x = 0.667, y = 0.667},
+ visual = "item",
+ visual_size = {x = SCALE, y = SCALE, z = SCALE},
textures = {},
physical = true,
is_visible = false,
@@ -33,11 +61,105 @@ core.register_entity(":__builtin:falling_node", {
end
end
end
+ local def = core.registered_nodes[node.name]
+ if not def then
+ -- Don't allow unknown nodes to fall
+ core.log("info",
+ "Unknown falling node removed at "..
+ core.pos_to_string(self.object:get_pos()))
+ self.object:remove()
+ return
+ end
self.meta = meta
- self.object:set_properties({
- is_visible = true,
- textures = {node.name},
- })
+ if def.drawtype == "torchlike" or def.drawtype == "signlike" then
+ local textures
+ if def.tiles and def.tiles[1] then
+ local tile = def.tiles[1]
+ if type(tile) == "table" then
+ tile = tile.name
+ end
+ if def.drawtype == "torchlike" then
+ textures = { "("..tile..")^[transformFX", tile }
+ else
+ textures = { tile, "("..tile..")^[transformFX" }
+ end
+ end
+ local vsize
+ if def.visual_scale then
+ local s = def.visual_scale
+ vsize = {x = s, y = s, z = s}
+ end
+ self.object:set_properties({
+ is_visible = true,
+ visual = "upright_sprite",
+ visual_size = vsize,
+ textures = textures,
+ glow = def.light_source,
+ })
+ elseif def.drawtype ~= "airlike" then
+ local itemstring = node.name
+ if core.is_colored_paramtype(def.paramtype2) then
+ itemstring = core.itemstring_with_palette(itemstring, node.param2)
+ end
+ local vsize
+ if def.visual_scale then
+ local s = def.visual_scale * SCALE
+ vsize = {x = s, y = s, z = s}
+ end
+ self.object:set_properties({
+ is_visible = true,
+ wield_item = itemstring,
+ visual_size = vsize,
+ glow = def.light_source,
+ })
+ end
+ -- 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))
+ or def.drawtype == "signlike"
+ or def.drawtype == "mesh"
+ or def.drawtype == "normal"
+ or def.drawtype == "nodebox" then
+ if (def.paramtype2 == "facedir" or def.paramtype2 == "colorfacedir") then
+ local fdir = node.param2 % 32
+ -- Get rotation from a precalculated lookup table
+ local euler = facedir_to_euler[fdir + 1]
+ if euler then
+ self.object:set_rotation(euler)
+ end
+ 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
+ end
+ if def.drawtype == "signlike" then
+ pitch = pitch - math.pi/2
+ if rot == 0 then
+ yaw = yaw + math.pi/2
+ elseif rot == 1 then
+ yaw = yaw - math.pi/2
+ end
+ elseif def.drawtype == "mesh" or def.drawtype == "normal" then
+ if rot >= 0 and rot <= 1 then
+ roll = roll + math.pi
+ else
+ yaw = yaw + math.pi
+ end
+ end
+ self.object:set_rotation({x=pitch, y=yaw, z=roll})
+ end
+ end
end,
get_staticdata = function(self)
@@ -128,7 +250,7 @@ core.register_entity(":__builtin:falling_node", {
meta:from_table(self.meta)
end
if def.sounds and def.sounds.place then
- core.sound_play(def.sounds.place, {pos = np})
+ core.sound_play(def.sounds.place, {pos = np}, true)
end
end
self.object:remove()
@@ -154,7 +276,7 @@ local function convert_to_falling_node(pos, node)
local def = core.registered_nodes[node.name]
if def and def.sounds and def.sounds.fall then
- core.sound_play(def.sounds.fall, {pos = pos})
+ core.sound_play(def.sounds.fall, {pos = pos}, true)
end
obj:get_luaentity():set_node(node, metatable)
@@ -187,7 +309,7 @@ local function drop_attached_node(p)
def.preserve_metadata(pos_copy, node_copy, oldmeta, drops)
end
if def and def.sounds and def.sounds.fall then
- core.sound_play(def.sounds.fall, {pos = p})
+ core.sound_play(def.sounds.fall, {pos = p}, true)
end
core.remove_node(p)
for _, item in pairs(drops) do
diff --git a/builtin/game/features.lua b/builtin/game/features.lua
index 0af0dc1da..623f8183b 100644
--- a/builtin/game/features.lua
+++ b/builtin/game/features.lua
@@ -15,6 +15,7 @@ core.features = {
httpfetch_binary_data = true,
formspec_version_element = true,
area_store_persistent_ids = true,
+ pathfinder_works = true,
}
function core.has_feature(arg)
diff --git a/builtin/game/item.lua b/builtin/game/item.lua
index 4054949f1..513c3a5e1 100644
--- a/builtin/game/item.lua
+++ b/builtin/game/item.lua
@@ -259,7 +259,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
prevent_after_place)
local def = itemstack:get_definition()
if def.type ~= "node" or pointed_thing.type ~= "node" then
- return itemstack, false
+ return itemstack, nil
end
local under = pointed_thing.under
@@ -272,7 +272,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
if not oldnode_under or not oldnode_above then
log("info", playername .. " tried to place"
.. " node in unloaded position " .. core.pos_to_string(above))
- return itemstack, false
+ return itemstack, nil
end
local olddef_under = core.registered_nodes[oldnode_under.name]
@@ -284,7 +284,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
log("info", playername .. " tried to place"
.. " node in invalid position " .. core.pos_to_string(above)
.. ", replacing " .. oldnode_above.name)
- return itemstack, false
+ return itemstack, nil
end
-- Place above pointed node
@@ -302,12 +302,9 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
.. " at protected position "
.. core.pos_to_string(place_to))
core.record_protection_violation(place_to, playername)
- return itemstack
+ return itemstack, nil
end
- log("action", playername .. " places node "
- .. def.name .. " at " .. core.pos_to_string(place_to))
-
local oldnode = core.get_node(place_to)
local newnode = {name = def.name, param1 = 0, param2 = param2 or 0}
@@ -333,7 +330,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
z = above.z - placer_pos.z
}
newnode.param2 = core.dir_to_facedir(dir)
- log("action", "facedir: " .. newnode.param2)
+ log("info", "facedir: " .. newnode.param2)
end
end
@@ -361,12 +358,23 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
not builtin_shared.check_attached_node(place_to, newnode) then
log("action", "attached node " .. def.name ..
" can not be placed at " .. core.pos_to_string(place_to))
- return itemstack, false
+ return itemstack, nil
end
+ log("action", playername .. " places node "
+ .. def.name .. " at " .. core.pos_to_string(place_to))
+
-- Add node and update
core.add_node(place_to, newnode)
+ -- Play sound if it was done by a player
+ if playername ~= "" and def.sounds and def.sounds.place then
+ core.sound_play(def.sounds.place, {
+ pos = place_to,
+ exclude_player = playername,
+ }, true)
+ end
+
local take_item = true
-- Run callback
@@ -395,9 +403,10 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
if take_item then
itemstack:take_item()
end
- return itemstack, true
+ return itemstack, place_to
end
+-- deprecated, item_place does not call this
function core.item_place_object(itemstack, placer, pointed_thing)
local pos = core.get_pointed_thing_position(pointed_thing, true)
if pos ~= nil then
@@ -415,14 +424,15 @@ function core.item_place(itemstack, placer, pointed_thing, param2)
local nn = n.name
if core.registered_nodes[nn] and core.registered_nodes[nn].on_rightclick then
return core.registered_nodes[nn].on_rightclick(pointed_thing.under, n,
- placer, itemstack, pointed_thing) or itemstack, false
+ placer, itemstack, pointed_thing) or itemstack, nil
end
end
+ -- Place if node, otherwise do nothing
if itemstack:get_definition().type == "node" then
return core.item_place_node(itemstack, placer, pointed_thing, param2)
end
- return itemstack
+ return itemstack, nil
end
function core.item_secondary_use(itemstack, placer)
@@ -465,7 +475,10 @@ function core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed
user:set_hp(user:get_hp() + hp_change)
if def and def.sound and def.sound.eat then
- minetest.sound_play(def.sound.eat, { pos = user:get_pos(), max_hear_distance = 16 })
+ core.sound_play(def.sound.eat, {
+ pos = user:get_pos(),
+ max_hear_distance = 16
+ }, true)
end
if replace_with_item then
@@ -572,7 +585,10 @@ function core.node_dig(pos, node, digger)
if not core.settings:get_bool("creative_mode") then
wielded:add_wear(dp.wear)
if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then
- core.sound_play(wdef.sound.breaks, {pos = pos, gain = 0.5})
+ core.sound_play(wdef.sound.breaks, {
+ pos = pos,
+ gain = 0.5
+ }, true)
end
end
end
@@ -604,6 +620,14 @@ function core.node_dig(pos, node, digger)
-- Remove node and update
core.remove_node(pos)
+ -- Play sound if it was done by a player
+ if diggername ~= "" and def and def.sounds and def.sounds.dug then
+ core.sound_play(def.sounds.dug, {
+ pos = pos,
+ exclude_player = diggername,
+ }, true)
+ end
+
-- Run callback
if def and def.after_dig_node then
-- Copy pos and node because callback can modify them
diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua
index 87fec93ea..968daac97 100644
--- a/builtin/game/item_entity.lua
+++ b/builtin/game/item_entity.lua
@@ -58,6 +58,8 @@ core.register_entity(":__builtin:item", {
local count = math.min(stack:get_count(), max_count)
local size = 0.2 + 0.1 * (count / max_count) ^ (1 / 3)
local coll_height = size * 0.75
+ local def = core.registered_nodes[itemname]
+ local glow = def and math.floor(def.light_source / 2 + 0.5)
self.object:set_properties({
is_visible = true,
@@ -69,6 +71,7 @@ core.register_entity(":__builtin:item", {
selectionbox = {-size, -size, -size, size, size, size},
automatic_rotate = math.pi * 0.5 * 0.2 / size,
wield_item = self.itemstring,
+ glow = glow,
})
end,
diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua
index 02c36ccb1..0ed11ada0 100644
--- a/builtin/game/misc.lua
+++ b/builtin/game/misc.lua
@@ -40,9 +40,6 @@ function core.check_player_privs(name, ...)
end
-local player_list = {}
-
-
function core.send_join_message(player_name)
if not core.is_singleplayer() then
core.chat_send_all("*** " .. player_name .. " joined the game.")
@@ -61,7 +58,6 @@ end
core.register_on_joinplayer(function(player)
local player_name = player:get_player_name()
- player_list[player_name] = player
if not core.is_singleplayer() then
local status = core.get_server_status(player_name, true)
if status and status ~= "" then
@@ -74,22 +70,10 @@ end)
core.register_on_leaveplayer(function(player, timed_out)
local player_name = player:get_player_name()
- player_list[player_name] = nil
core.send_leave_message(player_name, timed_out)
end)
-function core.get_connected_players()
- local temp_table = {}
- for index, value in pairs(player_list) do
- if value:is_player_connected() then
- temp_table[#temp_table + 1] = value
- end
- end
- return temp_table
-end
-
-
function core.is_player(player)
-- a table being a player is also supported because it quacks sufficiently
-- like a player if it has the is_player function
diff --git a/builtin/game/register.lua b/builtin/game/register.lua
index bfad6845c..eb6c2897c 100644
--- a/builtin/game/register.lua
+++ b/builtin/game/register.lua
@@ -321,11 +321,11 @@ for name in pairs(forbidden_item_names) do
end
--- Deprecated:
+-- 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
+-- 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.