Builtin: few minor patches
This commit is contained in:
parent
bb25210dd0
commit
cdb68c2e0d
@ -136,7 +136,7 @@ core.register_on_prejoinplayer(function(name, ip)
|
||||
end
|
||||
|
||||
local name_lower = name:lower()
|
||||
for k in core.builtin_auth_handler.iterate() do
|
||||
for _, k in ipairs(core_auth.list_names()) do
|
||||
if k:lower() == name_lower then
|
||||
return ("\nYou can not register as \"%s\"! "..
|
||||
"Another player called \"%s\" is already registered. " ..
|
||||
|
@ -3,7 +3,7 @@
|
||||
Copyright (C) BlockMen (2013-2015)
|
||||
Copyright (C) Auke Kok <sofar@foo-projects.org> (2016)
|
||||
Copyright (C) Minetest Mods Team (2016-2019)
|
||||
Copyright (C) MultiCraft Development Team (2016-2021)
|
||||
Copyright (C) MultiCraft Development Team (2016-2022)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -90,7 +90,7 @@ function hunger.register_on_update_saturation(fun)
|
||||
end
|
||||
|
||||
function hunger.update_saturation(player, level)
|
||||
for _, callback in pairs(hunger.registered_on_update_saturations) do
|
||||
for _, callback in ipairs(hunger.registered_on_update_saturations) do
|
||||
local result = callback(player, level)
|
||||
if result then
|
||||
return result
|
||||
@ -112,9 +112,10 @@ function hunger.update_saturation(player, level)
|
||||
end
|
||||
|
||||
function hunger.change_saturation(player, change)
|
||||
if not is_player(player) or not change or change == 0 then
|
||||
if not change or change == 0 or not is_player(player) then
|
||||
return false
|
||||
end
|
||||
|
||||
local level = hunger.get_saturation(player) + change or 0
|
||||
level = max(level, 0)
|
||||
level = min(level, settings.level_max)
|
||||
@ -160,15 +161,15 @@ function hunger.register_on_poison(fun)
|
||||
end
|
||||
|
||||
function hunger.poison(player, ticks, interval)
|
||||
for _, fun in pairs(hunger.registered_on_poisons) do
|
||||
if not is_player(player) then
|
||||
return
|
||||
end
|
||||
for _, fun in ipairs(hunger.registered_on_poisons) do
|
||||
local rv = fun(player, ticks, interval)
|
||||
if rv == true then
|
||||
return
|
||||
end
|
||||
end
|
||||
if not is_player(player) then
|
||||
return
|
||||
end
|
||||
hunger.set_poisoned(player, true)
|
||||
poison_tick(player:get_player_name(), ticks, interval, 0)
|
||||
end
|
||||
@ -200,7 +201,7 @@ function hunger.register_on_exhaust_player(fun)
|
||||
end
|
||||
|
||||
function hunger.exhaust_player(player, change, cause)
|
||||
for _, callback in pairs(hunger.registered_on_exhaust_players) do
|
||||
for _, callback in ipairs(hunger.registered_on_exhaust_players) do
|
||||
local result = callback(player, change, cause)
|
||||
if result then
|
||||
return result
|
||||
@ -227,7 +228,7 @@ end
|
||||
local connected_players = core.get_connected_players
|
||||
|
||||
local function move_tick()
|
||||
for _, player in pairs(connected_players()) do
|
||||
for _, player in ipairs(connected_players()) do
|
||||
local controls = player:get_player_control()
|
||||
local is_moving = controls.up or controls.down or controls.left or controls.right
|
||||
local velocity = player:get_velocity()
|
||||
@ -246,7 +247,7 @@ end
|
||||
|
||||
local function hunger_tick()
|
||||
-- lower saturation by 1 point after settings.tick seconds
|
||||
for _, player in pairs(connected_players()) do
|
||||
for _, player in ipairs(connected_players()) do
|
||||
local saturation = hunger.get_saturation(player) or 0
|
||||
if saturation > settings.tick_min then
|
||||
hunger.update_saturation(player, saturation - 1)
|
||||
@ -256,7 +257,7 @@ end
|
||||
|
||||
local function health_tick()
|
||||
-- heal or damage player, depending on saturation
|
||||
for _, player in pairs(connected_players()) do
|
||||
for _, player in ipairs(connected_players()) do
|
||||
local air = player:get_breath() or 0
|
||||
local hp = player:get_hp() or 0
|
||||
local saturation = hunger.get_saturation(player) or 0
|
||||
|
@ -27,9 +27,11 @@ local lava_destroy = core.settings:get_bool("item_lava_destroy", true)
|
||||
local function quick_flow_logic(node, pos_testing, dir)
|
||||
local node_testing = core.get_node_or_nil(pos_testing)
|
||||
if not node_testing then return 0 end
|
||||
local liquid = core.registered_nodes[node_testing.name] and core.registered_nodes[node_testing.name].liquidtype
|
||||
|
||||
if not liquid or liquid ~= "flowing" and liquid ~= "source" then
|
||||
local node_testing_def = core.registered_nodes[node_testing.name]
|
||||
local liquid = node_testing_def and node_testing_def.liquidtype
|
||||
|
||||
if not liquid or (liquid ~= "flowing" and liquid ~= "source") then
|
||||
return 0
|
||||
end
|
||||
|
||||
@ -313,19 +315,15 @@ core.register_entity(":__builtin:item", {
|
||||
end
|
||||
end
|
||||
|
||||
local vel = self.object:get_velocity()
|
||||
local def = node and core.registered_nodes[node.name]
|
||||
local node_inside = core.get_node_or_nil(pos)
|
||||
local def_inside = node_inside and core.registered_nodes[node_inside.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
|
||||
|
||||
-- Destroy item when dropped into lava
|
||||
if lava_destroy and def_inside
|
||||
and def_inside.groups and def_inside.groups.lava then
|
||||
core.sound_play("default_cool_lava", {
|
||||
pos = pos, max_hear_distance = 10})
|
||||
self.itemstring = ""
|
||||
self.object:remove()
|
||||
core.add_particlespawner({
|
||||
amount = 3,
|
||||
@ -345,6 +343,8 @@ core.register_entity(":__builtin:item", {
|
||||
return
|
||||
end
|
||||
|
||||
local vel = self.object:get_velocity()
|
||||
|
||||
-- Moving items in the water flow (TenPlus1, MIT)
|
||||
if water_flow and def_inside and def_inside.liquidtype == "flowing" then
|
||||
local vec = quick_flow(pos, node_inside)
|
||||
@ -352,19 +352,8 @@ core.register_entity(":__builtin:item", {
|
||||
return
|
||||
end
|
||||
|
||||
-- Move item inside node to free space (TenPlus1, MIT)
|
||||
--[[if not self.stuck and def_inside and def_inside.walkable and
|
||||
not def_inside.liquid and node_inside.name ~= "air" and
|
||||
def_inside.drawtype == "normal" then
|
||||
local npos = core.find_node_near(pos, 1, "air")
|
||||
if npos then
|
||||
self.object:move_to(npos)
|
||||
else
|
||||
self.stuck = true
|
||||
end
|
||||
end]]
|
||||
|
||||
-- Slide on slippery nodes
|
||||
local def = node and core.registered_nodes[node.name]
|
||||
local keep_movement = false
|
||||
|
||||
if def then
|
||||
@ -436,9 +425,10 @@ if collection then
|
||||
if not core.is_valid_pos(ppos) then
|
||||
return
|
||||
end
|
||||
|
||||
-- Detect
|
||||
local objects = core.get_objects_inside_radius(ppos, 2)
|
||||
for _, obj in pairs(objects) do
|
||||
for _, obj in ipairs(objects) do
|
||||
local entity = obj:get_luaentity()
|
||||
if entity and entity.name == "__builtin:item" and
|
||||
not entity.collectioner and
|
||||
@ -450,30 +440,29 @@ if collection then
|
||||
-- Magnet
|
||||
obj:move_to(ppos)
|
||||
entity.collectioner = true
|
||||
|
||||
-- Collect
|
||||
if entity.collectioner == true then
|
||||
core.after(0.05, function()
|
||||
core.sound_play("item_drop_pickup", {
|
||||
pos = ppos,
|
||||
max_hear_distance = 10,
|
||||
gain = 0.2,
|
||||
pitch = random(60,100)/100
|
||||
})
|
||||
entity.itemstring = ""
|
||||
obj:remove()
|
||||
item = inv:add_item("main", item)
|
||||
if not item:is_empty() then
|
||||
core.item_drop(item, player, ppos)
|
||||
end
|
||||
end)
|
||||
end
|
||||
core.after(0.05, function()
|
||||
core.sound_play("item_drop_pickup", {
|
||||
pos = ppos,
|
||||
max_hear_distance = 10,
|
||||
gain = 0.2,
|
||||
pitch = random(60, 100) / 100
|
||||
})
|
||||
entity.itemstring = ""
|
||||
obj:remove()
|
||||
item = inv:add_item("main", item)
|
||||
if not item:is_empty() then
|
||||
core.item_drop(item, player, ppos)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
core.register_playerstep(function(dtime, playernames)
|
||||
for _, name in pairs(playernames) do
|
||||
core.register_playerstep(function(_, playernames)
|
||||
for _, name in ipairs(playernames) do
|
||||
local player = core.get_player_by_name(name)
|
||||
if player and player:is_player() and player:get_hp() > 0 then
|
||||
collect_items(player)
|
||||
|
Loading…
x
Reference in New Issue
Block a user