diff options
| author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2020-07-18 13:53:15 +0200 |
|---|---|---|
| committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2020-07-18 13:53:15 +0200 |
| commit | ffe3c2ae0db6fed0f2b08b71bfa69f3d3df3bb1f (patch) | |
| tree | cc7d9f74a43215c5d8e3965a2bfc2aea5867a7a0 /builtin/game | |
| parent | 45aa2516b2fc675df7049bc9ed713600c95b6423 (diff) | |
| parent | 82731d0d3d8bfe9e56f89466991f13c037f3a61e (diff) | |
| download | dragonfireclient-ffe3c2ae0db6fed0f2b08b71bfa69f3d3df3bb1f.tar.xz | |
Update to minetest 5.4.0-dev
Diffstat (limited to 'builtin/game')
| -rw-r--r-- | builtin/game/auth.lua | 3 | ||||
| -rw-r--r-- | builtin/game/chat.lua | 126 | ||||
| -rw-r--r-- | builtin/game/constants.lua | 2 | ||||
| -rw-r--r-- | builtin/game/deprecated.lua | 16 | ||||
| -rw-r--r-- | builtin/game/falling.lua | 263 | ||||
| -rw-r--r-- | builtin/game/features.lua | 1 | ||||
| -rw-r--r-- | builtin/game/item.lua | 10 | ||||
| -rw-r--r-- | builtin/game/item_entity.lua | 115 | ||||
| -rw-r--r-- | builtin/game/misc.lua | 6 | ||||
| -rw-r--r-- | builtin/game/register.lua | 2 | ||||
| -rw-r--r-- | builtin/game/statbars.lua | 40 |
11 files changed, 384 insertions, 200 deletions
diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua index 7aedfc82e..fc061666c 100644 --- a/builtin/game/auth.lua +++ b/builtin/game/auth.lua @@ -41,7 +41,6 @@ core.builtin_auth_handler = { return { password = auth_entry.password, privileges = privileges, - -- Is set to nil if unknown last_login = auth_entry.last_login, } end, @@ -53,7 +52,7 @@ core.builtin_auth_handler = { name = name, password = password, privileges = core.string_to_privs(core.settings:get("default_privs")), - last_login = os.time(), + last_login = -1, -- Defer login time calculation until record_login (called by on_joinplayer) }) end, delete_auth = function(name) diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua index fd1379162..aae811794 100644 --- a/builtin/game/chat.lua +++ b/builtin/game/chat.lua @@ -239,57 +239,76 @@ core.register_chatcommand("grantme", { end, }) +local function handle_revoke_command(caller, revokename, revokeprivstr) + local caller_privs = core.get_player_privs(caller) + if not (caller_privs.privs or caller_privs.basic_privs) then + return false, "Your privileges are insufficient." + end + + if not core.get_auth_handler().get_auth(revokename) then + return false, "Player " .. revokename .. " does not exist." + 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, "Your privileges are insufficient." + end + end + + if revokeprivstr == "all" then + revokeprivs = privs + privs = {} + else + for priv, _ in pairs(revokeprivs) do + privs[priv] = nil + end + end + + for priv, _ in pairs(revokeprivs) do + -- call the on_revoke callbacks + core.run_priv_callbacks(revokename, priv, caller, "revoke") + end + + core.set_player_privs(revokename, privs) + core.log("action", caller..' revoked (' + ..core.privs_to_string(revokeprivs, ', ') + ..') privileges from '..revokename) + if revokename ~= caller then + core.chat_send_player(revokename, caller + .. " revoked privileges from you: " + .. core.privs_to_string(revokeprivs, ' ')) + end + return true, "Privileges of " .. revokename .. ": " + .. core.privs_to_string( + core.get_player_privs(revokename), ' ') +end + core.register_chatcommand("revoke", { params = "<name> (<privilege> | all)", description = "Remove privileges from player", privs = {}, func = function(name, param) - if not core.check_player_privs(name, {privs=true}) and - not core.check_player_privs(name, {basic_privs=true}) then - return false, "Your privileges are insufficient." - end - local revoke_name, revoke_priv_str = string.match(param, "([^ ]+) (.+)") - if not revoke_name or not revoke_priv_str then + local revokename, revokeprivstr = string.match(param, "([^ ]+) (.+)") + if not revokename or not revokeprivstr then return false, "Invalid parameters (see /help revoke)" - elseif not core.get_auth_handler().get_auth(revoke_name) then - return false, "Player " .. revoke_name .. " does not exist." - end - local revoke_privs = core.string_to_privs(revoke_priv_str) - local privs = core.get_player_privs(revoke_name) - local basic_privs = - core.string_to_privs(core.settings:get("basic_privs") or "interact,shout") - for priv, _ in pairs(revoke_privs) do - if not basic_privs[priv] and - not core.check_player_privs(name, {privs=true}) then - return false, "Your privileges are insufficient." - end - end - if revoke_priv_str == "all" then - revoke_privs = privs - privs = {} - else - for priv, _ in pairs(revoke_privs) do - privs[priv] = nil - end - end - - for priv, _ in pairs(revoke_privs) do - -- call the on_revoke callbacks - core.run_priv_callbacks(revoke_name, priv, name, "revoke") end + return handle_revoke_command(name, revokename, revokeprivstr) + end, +}) - core.set_player_privs(revoke_name, privs) - core.log("action", name..' revoked (' - ..core.privs_to_string(revoke_privs, ', ') - ..') privileges from '..revoke_name) - if revoke_name ~= name then - core.chat_send_player(revoke_name, name - .. " revoked privileges from you: " - .. core.privs_to_string(revoke_privs, ' ')) +core.register_chatcommand("revokeme", { + params = "<privilege> | all", + description = "Revoke privileges from yourself", + privs = {}, + func = function(name, param) + if param == "" then + return false, "Invalid parameters (see /help revokeme)" end - return true, "Privileges of " .. revoke_name .. ": " - .. core.privs_to_string( - core.get_player_privs(revoke_name), ' ') + return handle_revoke_command(name, name, param) end, }) @@ -424,6 +443,9 @@ core.register_chatcommand("teleport", { end local teleportee = core.get_player_by_name(name) if teleportee then + if teleportee:get_attach() then + return false, "Can't teleport, you're attached to an object!" + end teleportee:set_pos(p) return true, "Teleporting to "..core.pos_to_string(p) end @@ -441,6 +463,9 @@ core.register_chatcommand("teleport", { end if teleportee and p then + if teleportee:get_attach() then + return false, "Can't teleport, you're attached to an object!" + end p = find_free_position_near(p) teleportee:set_pos(p) return true, "Teleporting to " .. target_name @@ -461,6 +486,9 @@ core.register_chatcommand("teleport", { teleportee = core.get_player_by_name(teleportee_name) end if teleportee and p.x and p.y and p.z then + if teleportee:get_attach() then + return false, "Can't teleport, player is attached to an object!" + end teleportee:set_pos(p) return true, "Teleporting " .. teleportee_name .. " to " .. core.pos_to_string(p) @@ -479,6 +507,9 @@ core.register_chatcommand("teleport", { end end if teleportee and p then + if teleportee:get_attach() then + return false, "Can't teleport, player is attached to an object!" + end p = find_free_position_near(p) teleportee:set_pos(p) return true, "Teleporting " .. teleportee_name @@ -717,8 +748,9 @@ core.register_chatcommand("spawnentity", { end end p.y = p.y + 1 - core.add_entity(p, entityname) - return true, ("%q spawned."):format(entityname) + local obj = core.add_entity(p, entityname) + local msg = obj and "%q spawned." or "%q failed to spawn." + return true, msg:format(entityname) end, }) @@ -757,7 +789,7 @@ core.register_chatcommand("rollback_check", { params = "[<range>] [<seconds>] [<limit>]", description = "Check who last touched a node or a node near it" .. " within the time specified by <seconds>. Default: range = 0," - .. " seconds = 86400 = 24h, limit = 5", + .. " seconds = 86400 = 24h, limit = 5. Set <seconds> to inf for no time limit", privs = {rollback=true}, func = function(name, param) if not core.settings:get_bool("enable_rollback_recording") then @@ -808,7 +840,7 @@ core.register_chatcommand("rollback_check", { core.register_chatcommand("rollback", { params = "(<name> [<seconds>]) | (:<actor> [<seconds>])", - description = "Revert actions of a player. Default for <seconds> is 60", + description = "Revert actions of a player. Default for <seconds> is 60. Set <seconds> to inf for no time limit", privs = {rollback=true}, func = function(name, param) if not core.settings:get_bool("enable_rollback_recording") then @@ -1036,7 +1068,7 @@ core.register_chatcommand("last-login", { param = name end local pauth = core.get_auth_handler().get_auth(param) - if pauth and pauth.last_login then + if pauth and pauth.last_login and pauth.last_login ~= -1 then -- Time in UTC, ISO 8601 format return true, "Last login time was " .. os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login) diff --git a/builtin/game/constants.lua b/builtin/game/constants.lua index 0ee2a7237..54eeea50f 100644 --- a/builtin/game/constants.lua +++ b/builtin/game/constants.lua @@ -24,7 +24,7 @@ core.MAP_BLOCKSIZE = 16 -- Default maximal HP of a player core.PLAYER_MAX_HP_DEFAULT = 20 -- Default maximal breath of a player -core.PLAYER_MAX_BREATH_DEFAULT = 11 +core.PLAYER_MAX_BREATH_DEFAULT = 10 -- light.h -- Maximum value for node 'light_source' parameter diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index 73e105eb8..20f0482eb 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -70,3 +70,19 @@ core.setting_get = setting_proxy("get") core.setting_setbool = setting_proxy("set_bool") core.setting_getbool = setting_proxy("get_bool") core.setting_save = setting_proxy("write") + +-- +-- core.register_on_auth_fail +-- + +function core.register_on_auth_fail(func) + core.log("deprecated", "core.register_on_auth_fail " .. + "is obsolete and should be replaced by " .. + "core.register_on_authplayer instead.") + + core.register_on_authplayer(function (player_name, ip, is_success) + if not is_success then + func(player_name, ip) + end + end) +end diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index ea02e3694..714506a5f 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -30,6 +30,8 @@ local facedir_to_euler = { {y = math.pi/2, x = math.pi, z = 0} } +local gravity = tonumber(core.settings:get("movement_gravity")) or 9.81 + -- -- Falling stuff -- @@ -41,12 +43,13 @@ core.register_entity(":__builtin:falling_node", { textures = {}, physical = true, is_visible = false, - collide_with_objects = false, + collide_with_objects = true, collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, }, node = {}, meta = {}, + floats = false, set_node = function(self, node, meta) self.node = node @@ -71,6 +74,11 @@ core.register_entity(":__builtin:falling_node", { return end self.meta = meta + + -- Cache whether we're supposed to float on water + self.floats = core.get_item_group(node.name, "float") ~= 0 + + -- Set entity visuals if def.drawtype == "torchlike" or def.drawtype == "signlike" then local textures if def.tiles and def.tiles[1] then @@ -101,6 +109,7 @@ core.register_entity(":__builtin:falling_node", { if core.is_colored_paramtype(def.paramtype2) then itemstring = core.itemstring_with_palette(itemstring, node.param2) end + -- FIXME: solution needed for paramtype2 == "leveled" local vsize if def.visual_scale then local s = def.visual_scale * SCALE @@ -113,6 +122,25 @@ core.register_entity(":__builtin:falling_node", { glow = def.light_source, }) end + + -- 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 + 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 + end + if box then + if def.paramtype2 == "leveled" and (self.node.level or 0) > 0 then + box[5] = -0.5 + self.node.level / 64 + end + self.object:set_properties({ + collisionbox = box + }) + end + end + -- Rotate entity if def.drawtype == "torchlike" then self.object:set_yaw(math.pi*0.25) @@ -172,6 +200,7 @@ core.register_entity(":__builtin:falling_node", { on_activate = function(self, staticdata) self.object:set_armor_groups({immortal = 1}) + self.object:set_acceleration({x = 0, y = -gravity, z = 0}) local ds = core.deserialize(staticdata) if ds and ds.node then @@ -183,85 +212,159 @@ core.register_entity(":__builtin:falling_node", { end end, - on_step = function(self, dtime) - -- Set gravity - local acceleration = self.object:get_acceleration() - if not vector.equals(acceleration, {x = 0, y = -10, z = 0}) then - self.object:set_acceleration({x = 0, y = -10, z = 0}) + try_place = function(self, bcp, bcn) + local bcd = core.registered_nodes[bcn.name] + -- Add levels if dropped on same leveled node + if bcd and bcd.paramtype2 == "leveled" and + bcn.name == self.node.name then + local addlevel = self.node.level + if (addlevel or 0) <= 0 then + addlevel = bcd.leveled + end + if core.add_node_level(bcp, addlevel) < addlevel then + return true + elseif bcd.buildable_to then + -- Node level has already reached max, don't place anything + return true + end end - -- Turn to actual node when colliding with ground, or continue to move - local pos = self.object:get_pos() - -- Position of bottom center point - local bcp = {x = pos.x, y = pos.y - 0.7, z = pos.z} - -- 'bcn' is nil for unloaded nodes - local bcn = core.get_node_or_nil(bcp) - -- Delete on contact with ignore at world edges - if bcn and bcn.name == "ignore" then - self.object:remove() - return + + -- Decide if we're replacing the node or placing on top + local np = vector.new(bcp) + if bcd and bcd.buildable_to and + (not self.floats or bcd.liquidtype == "none") then + core.remove_node(bcp) + else + np.y = np.y + 1 end - local bcd = bcn and core.registered_nodes[bcn.name] - if bcn and - (not bcd or bcd.walkable or - (core.get_item_group(self.node.name, "float") ~= 0 and - bcd.liquidtype ~= "none")) then - if bcd and bcd.leveled and - bcn.name == self.node.name then - local addlevel = self.node.level - if not addlevel or addlevel <= 0 then - addlevel = bcd.leveled + + -- Check what's here + local n2 = core.get_node(np) + local nd = core.registered_nodes[n2.name] + -- If it's not air or liquid, remove node and replace it with + -- it's drops + if n2.name ~= "air" and (not nd or nd.liquidtype == "none") then + if nd and nd.buildable_to == false then + nd.on_dig(np, n2, nil) + -- If it's still there, it might be protected + if core.get_node(np).name == n2.name then + return false end - if core.add_node_level(bcp, addlevel) == 0 then + else + core.remove_node(np) + end + end + + -- Create node + local def = core.registered_nodes[self.node.name] + if def then + core.add_node(np, self.node) + if self.meta then + core.get_meta(np):from_table(self.meta) + end + if def.sounds and def.sounds.place then + core.sound_play(def.sounds.place, {pos = np}, true) + end + end + core.check_for_falling(np) + return true + end, + + on_step = function(self, dtime, moveresult) + -- Fallback code since collision detection can't tell us + -- about liquids (which do not collide) + if self.floats then + local pos = self.object:get_pos() + + local bcp = vector.round({x = pos.x, y = pos.y - 0.7, z = pos.z}) + local bcn = core.get_node(bcp) + + local bcd = core.registered_nodes[bcn.name] + if bcd and bcd.liquidtype ~= "none" then + if self:try_place(bcp, bcn) then self.object:remove() return end - elseif bcd and bcd.buildable_to and - (core.get_item_group(self.node.name, "float") == 0 or - bcd.liquidtype == "none") then - core.remove_node(bcp) - return end - local np = {x = bcp.x, y = bcp.y + 1, z = bcp.z} - -- Check what's here - local n2 = core.get_node(np) - local nd = core.registered_nodes[n2.name] - -- If it's not air or liquid, remove node and replace it with - -- it's drops - if n2.name ~= "air" and (not nd or nd.liquidtype == "none") then - core.remove_node(np) - if nd and nd.buildable_to == false then - -- Add dropped items - local drops = core.get_node_drops(n2, "") - for _, dropped_item in pairs(drops) do - core.add_item(np, dropped_item) + end + + assert(moveresult) + if not moveresult.collides then + return -- Nothing to do :) + end + + local bcp, bcn + local player_collision + if moveresult.touching_ground then + for _, info in ipairs(moveresult.collisions) do + if info.type == "object" then + if info.axis == "y" and info.object:is_player() then + player_collision = info end - end - -- Run script hook - for _, callback in pairs(core.registered_on_dignodes) do - callback(np, n2) + elseif info.axis == "y" then + bcp = info.node_pos + bcn = core.get_node(bcp) + break end end - -- Create node and remove entity - local def = core.registered_nodes[self.node.name] - if def then - core.add_node(np, self.node) - if self.meta then - local meta = core.get_meta(np) - meta:from_table(self.meta) - end - if def.sounds and def.sounds.place then - core.sound_play(def.sounds.place, {pos = np}, true) - end + end + + if not bcp then + -- We're colliding with something, but not the ground. Irrelevant to us. + if player_collision then + -- Continue falling through players by moving a little into + -- their collision box + -- TODO: this hack could be avoided in the future if objects + -- could choose who to collide with + local vel = self.object:get_velocity() + self.object:set_velocity({ + x = vel.x, + y = player_collision.old_velocity.y, + z = vel.z + }) + self.object:set_pos(vector.add(self.object:get_pos(), + {x = 0, y = -0.5, z = 0})) end + return + elseif bcn.name == "ignore" then + -- Delete on contact with ignore at world edges self.object:remove() - core.check_for_falling(np) return end - local vel = self.object:get_velocity() - if vector.equals(vel, {x = 0, y = 0, z = 0}) then - local npos = self.object:get_pos() - self.object:set_pos(vector.round(npos)) + + local failure = false + + local pos = self.object:get_pos() + local distance = vector.apply(vector.subtract(pos, bcp), math.abs) + if distance.x >= 1 or distance.z >= 1 then + -- We're colliding with some part of a node that's sticking out + -- Since we don't want to visually teleport, drop as item + failure = true + elseif distance.y >= 2 then + -- Doors consist of a hidden top node and a bottom node that is + -- the actual door. Despite the top node being solid, the moveresult + -- almost always indicates collision with the bottom node. + -- Compensate for this by checking the top node + bcp.y = bcp.y + 1 + bcn = core.get_node(bcp) + local def = core.registered_nodes[bcn.name] + if not (def and def.walkable) then + failure = true -- This is unexpected, fail + end + end + + -- Try to actually place ourselves + if not failure then + failure = not self:try_place(bcp, bcn) + end + + if failure then + local drops = core.get_node_drops(self.node, "") + for _, item in pairs(drops) do + core.add_item(pos, item) + end end + self.object:remove() end }) @@ -270,6 +373,7 @@ local function convert_to_falling_node(pos, node) if not obj then return false end + -- remember node level, the entities' set_node() uses this node.level = core.get_node_level(pos) local meta = core.get_meta(pos) local metatable = meta and meta:to_table() or {} @@ -355,18 +459,23 @@ function core.check_single_for_falling(p) -- Only spawn falling node if node below is loaded local n_bottom = core.get_node_or_nil(p_bottom) local d_bottom = n_bottom and core.registered_nodes[n_bottom.name] - if d_bottom and - - (core.get_item_group(n.name, "float") == 0 or - d_bottom.liquidtype == "none") and - - (n.name ~= n_bottom.name or (d_bottom.leveled and - core.get_node_level(p_bottom) < - core.get_node_max_level(p_bottom))) and - - (not d_bottom.walkable or d_bottom.buildable_to) then - convert_to_falling_node(p, n) - return true + if d_bottom then + local same = n.name == n_bottom.name + -- Let leveled nodes fall if it can merge with the bottom node + if same and d_bottom.paramtype2 == "leveled" and + core.get_node_level(p_bottom) < + core.get_node_max_level(p_bottom) then + convert_to_falling_node(p, n) + return true + end + -- Otherwise only if the bottom node is considered "fall through" + if not same and + (not d_bottom.walkable or d_bottom.buildable_to) and + (core.get_item_group(n.name, "float") == 0 or + d_bottom.liquidtype == "none") then + convert_to_falling_node(p, n) + return true + end end end diff --git a/builtin/game/features.lua b/builtin/game/features.lua index 623f8183b..a15475333 100644 --- a/builtin/game/features.lua +++ b/builtin/game/features.lua @@ -16,6 +16,7 @@ core.features = { formspec_version_element = true, area_store_persistent_ids = true, pathfinder_works = true, + object_step_has_moveresult = true, } function core.has_feature(arg) diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 513c3a5e1..f680ce0d4 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -582,7 +582,7 @@ function core.node_dig(pos, node, digger) wielded = wdef.after_use(wielded, digger, node, dp) or wielded else -- Wear out tool - if not core.settings:get_bool("creative_mode") then + if not core.is_creative_enabled(diggername) 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, { @@ -675,6 +675,8 @@ end -- Item definition defaults -- +local default_stack_max = tonumber(minetest.settings:get("default_stack_max")) or 99 + core.nodedef_default = { -- Item properties type="node", @@ -684,7 +686,7 @@ core.nodedef_default = { inventory_image = "", wield_image = "", wield_scale = {x=1,y=1,z=1}, - stack_max = 99, + stack_max = default_stack_max, usable = false, liquids_pointable = false, tool_capabilities = nil, @@ -748,7 +750,7 @@ core.craftitemdef_default = { inventory_image = "", wield_image = "", wield_scale = {x=1,y=1,z=1}, - stack_max = 99, + stack_max = default_stack_max, liquids_pointable = false, tool_capabilities = nil, @@ -786,7 +788,7 @@ core.noneitemdef_default = { -- This is used for the hand and unknown items inventory_image = "", wield_image = "", wield_scale = {x=1,y=1,z=1}, - stack_max = 99, + stack_max = default_stack_max, liquids_pointable = false, tool_capabilities = nil, diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua index 1d66799f6..20dd18044 100644 --- a/builtin/game/item_entity.lua +++ b/builtin/game/item_entity.lua @@ -27,14 +27,11 @@ core.register_entity(":__builtin:item", { visual = "wielditem", visual_size = {x = 0.4, y = 0.4}, textures = {""}, - spritediv = {x = 1, y = 1}, - initial_sprite_basepos = {x = 0, y = 0}, is_visible = false, }, itemstring = "", moving_state = true, - slippery_state = false, physical_state = true, -- Item expiry age = 0, @@ -57,18 +54,15 @@ 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 coll_height = size * 0.75 local def = core.registered_nodes[itemname] - local glow = def and def.light_source + local glow = def and math.floor(def.light_source / 2 + 0.5) self.object:set_properties({ is_visible = true, visual = "wielditem", textures = {itemname}, visual_size = {x = size, y = size}, - collisionbox = {-size, -coll_height, -size, - size, coll_height, size}, - selectionbox = {-size, -size, -size, size, size, size}, + collisionbox = {-size, -size, -size, size, size, size}, automatic_rotate = math.pi * 0.5 * 0.2 / size, wield_item = self.itemstring, glow = glow, @@ -157,7 +151,7 @@ core.register_entity(":__builtin:item", { end end, - on_step = function(self, dtime) + on_step = function(self, dtime, moveresult) self.age = self.age + dtime if time_to_live > 0 and self.age > time_to_live then self.itemstring = "" @@ -178,6 +172,38 @@ core.register_entity(":__builtin:item", { return end + if self.force_out then + -- This code runs after the entity got a push from the is_stuck code. + -- It makes sure the entity is entirely outside the solid node + local c = self.object:get_properties().collisionbox + local s = self.force_out_start + local f = self.force_out + local ok = (f.x > 0 and pos.x + c[1] > s.x + 0.5) or + (f.y > 0 and pos.y + c[2] > s.y + 0.5) or + (f.z > 0 and pos.z + c[3] > s.z + 0.5) or + (f.x < 0 and pos.x + c[4] < s.x - 0.5) or + (f.z < 0 and pos.z + c[6] < s.z - 0.5) + if ok then + -- Item was successfully forced out + self.force_out = nil + self:enable_physics() + return + end + end + + if not self.physical_state then + return -- Don't do anything + end + + assert(moveresult, + "Collision info missing, this is caused by an out-of-date/buggy mod or game") + + if not moveresult.collides then + -- future TODO: items should probably decelerate in air + return + end + + -- Push item out when stuck inside solid node local is_stuck = false local snode = core.get_node_or_nil(pos) if snode then @@ -187,7 +213,6 @@ core.register_entity(":__builtin:item", { and (sdef.node_box == nil or sdef.node_box.type == "regular") end - -- Push item out when stuck inside solid node if is_stuck then local shootdir local order = { @@ -223,69 +248,49 @@ core.register_entity(":__builtin:item", { self.force_out_start = vector.round(pos) return end - elseif self.force_out then - -- This code runs after the entity got a push from the above code. - -- It makes sure the entity is entirely outside the solid node - local c = self.object:get_properties().collisionbox - local s = self.force_out_start - local f = self.force_out - local ok = (f.x > 0 and pos.x + c[1] > s.x + 0.5) or - (f.y > 0 and pos.y + c[2] > s.y + 0.5) or - (f.z > 0 and pos.z + c[3] > s.z + 0.5) or - (f.x < 0 and pos.x + c[4] < s.x - 0.5) or - (f.z < 0 and pos.z + c[6] < s.z - 0.5) - if ok then - -- Item was successfully forced out - self.force_out = nil - self:enable_physics() - end end - if not self.physical_state then - return -- Don't do anything + node = nil -- ground node we're colliding with + if moveresult.touching_ground then + for _, info in ipairs(moveresult.collisions) do + if info.axis == "y" then + node = core.get_node(info.node_pos) + break + end + end end -- Slide on slippery nodes - local vel = self.object:get_velocity() local def = node and core.registered_nodes[node.name] - local is_moving = (def and not def.walkable) or - vel.x ~= 0 or vel.y ~= 0 or vel.z ~= 0 - local is_slippery = false + local keep_movement = false - if def and def.walkable then + if def then local slippery = core.get_item_group(node.name, "slippery") - is_slippery = slippery ~= 0 - if is_slippery and (math.abs(vel.x) > 0.2 or math.abs(vel.z) > 0.2) then + local vel = self.object:get_velocity() + if slippery ~= 0 and (math.abs(vel.x) > 0.1 or math.abs(vel.z) > 0.1) then -- Horizontal deceleration - local slip_factor = 4.0 / (slippery + 4) - self.object:set_acceleration({ - x = -vel.x * slip_factor, + local factor = math.min(4 / (slippery + 4) * dtime, 1) + self.object:set_velocity({ + x = vel.x * (1 - factor), y = 0, - z = -vel.z * slip_factor + z = vel.z * (1 - factor) }) - elseif vel.y == 0 then - is_moving = false + keep_movement = true end end - if self.moving_state == is_moving and - self.slippery_state == is_slippery then - -- Do not update anything until the moving state changes - return + if not keep_movement then + self.object:set_velocity({x=0, y=0, z=0}) end - self.moving_state = is_moving - self.slippery_state = is_slippery - - if is_moving then - self.object:set_acceleration({x = 0, y = -gravity, z = 0}) - else - self.object:set_acceleration({x = 0, y = 0, z = 0}) - self.object:set_velocity({x = 0, y = 0, z = 0}) + if self.moving_state == keep_movement then + -- Do not update anything until the moving state changes + return end + self.moving_state = keep_movement - --Only collect items if not moving - if is_moving then + -- Only collect items if not moving + if self.moving_state then return end -- Collect the items around to merge with diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua index 0ed11ada0..341e613c2 100644 --- a/builtin/game/misc.lua +++ b/builtin/game/misc.lua @@ -164,6 +164,12 @@ function core.record_protection_violation(pos, name) end end +-- To be overridden by Creative mods + +local creative_mode_cache = core.settings:get_bool("creative_mode") +function core.is_creative_enabled(name) + return creative_mode_cache +end -- Checks if specified volume intersects a protected volume diff --git a/builtin/game/register.lua b/builtin/game/register.lua index eb6c2897c..1034d4f2b 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -607,9 +607,9 @@ core.registered_on_item_eats, core.register_on_item_eat = make_registration() core.registered_on_punchplayers, core.register_on_punchplayer = make_registration() core.registered_on_priv_grant, core.register_on_priv_grant = make_registration() core.registered_on_priv_revoke, core.register_on_priv_revoke = make_registration() +core.registered_on_authplayers, core.register_on_authplayer = make_registration() core.registered_can_bypass_userlimit, core.register_can_bypass_userlimit = make_registration() core.registered_on_modchannel_message, core.register_on_modchannel_message = make_registration() -core.registered_on_auth_fail, core.register_on_auth_fail = 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() diff --git a/builtin/game/statbars.lua b/builtin/game/statbars.lua index 46c947b60..d192029c5 100644 --- a/builtin/game/statbars.lua +++ b/builtin/game/statbars.lua @@ -3,22 +3,26 @@ local enable_damage = core.settings:get_bool("enable_damage") local health_bar_definition = { hud_elem_type = "statbar", - position = { x=0.5, y=1 }, + position = {x = 0.5, y = 1}, text = "heart.png", + text2 = "heart_gone.png", number = core.PLAYER_MAX_HP_DEFAULT, + item = core.PLAYER_MAX_HP_DEFAULT, direction = 0, - size = { x=24, y=24 }, - offset = { x=(-10*24)-25, y=-(48+24+16)}, + size = {x = 24, y = 24}, + offset = {x = (-10 * 24) - 25, y = -(48 + 24 + 16)}, } local breath_bar_definition = { hud_elem_type = "statbar", - position = { x=0.5, y=1 }, + position = {x = 0.5, y = 1}, text = "bubble.png", + text2 = "bubble_gone.png", number = core.PLAYER_MAX_BREATH_DEFAULT, + item = core.PLAYER_MAX_BREATH_DEFAULT * 2, direction = 0, - size = { x=24, y=24 }, - offset = {x=25,y=-(48+24+16)}, + size = {x = 24, y = 24}, + offset = {x = 25, y= -(48 + 24 + 16)}, } local hud_ids = {} @@ -26,7 +30,7 @@ local hud_ids = {} local function scaleToDefault(player, field) -- Scale "hp" or "breath" to the default dimensions local current = player["get_" .. field](player) - local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"] + local nominal = core["PLAYER_MAX_" .. field:upper() .. "_DEFAULT"] local max_display = math.max(nominal, math.max(player:get_properties()[field .. "_max"], current)) return current / max_display * nominal @@ -49,6 +53,7 @@ local function update_builtin_statbars(player) local hud = hud_ids[name] local immortal = player:get_armor_groups().immortal == 1 + if flags.healthbar and enable_damage and not immortal then local number = scaleToDefault(player, "hp") if hud.id_healthbar == nil then @@ -63,19 +68,28 @@ local function update_builtin_statbars(player) hud.id_healthbar = nil end + local show_breathbar = flags.breathbar and enable_damage and not immortal + + local breath = player:get_breath() local breath_max = player:get_properties().breath_max - if flags.breathbar and enable_damage and not immortal and - player:get_breath() < breath_max then + if show_breathbar and breath <= breath_max then local number = 2 * scaleToDefault(player, "breath") - if hud.id_breathbar == nil then + if not hud.id_breathbar and breath < breath_max then local hud_def = table.copy(breath_bar_definition) hud_def.number = number hud.id_breathbar = player:hud_add(hud_def) - else + elseif hud.id_breathbar then player:hud_change(hud.id_breathbar, "number", number) end - elseif hud.id_breathbar then - player:hud_remove(hud.id_breathbar) + 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) + if player then + player:hud_remove(breath_bar) + end + end, name, hud.id_breathbar) hud.id_breathbar = nil end end |
