forked from VoxeLibre/VoxeLibre
Compare commits
6 Commits
master
...
player-glo
Author | SHA1 | Date |
---|---|---|
|
de91552337 | |
|
753cdb09d7 | |
|
a1f56c4190 | |
|
fbc613d726 | |
|
bace4f5f20 | |
|
c7a144aa10 |
|
@ -44,32 +44,32 @@ minetest.register_on_leaveplayer(function(player)
|
||||||
controls.players[name] = nil
|
controls.players[name] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
mcl_util.register_player_globalstep({
|
||||||
for _, player in pairs(get_connected_players()) do
|
execute = function(player, dtime)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local player_controls = player:get_player_control()
|
local player_controls = player:get_player_control()
|
||||||
if controls.players[player_name] then
|
if controls.players[player_name] then
|
||||||
for cname, cbool in pairs(player_controls) do
|
for cname, cbool in pairs(player_controls) do
|
||||||
if known_controls[cname] == true then
|
if known_controls[cname] == true then
|
||||||
--Press a key
|
--Press a key
|
||||||
if cbool==true and controls.players[player_name][cname][1]==false then
|
if cbool==true and controls.players[player_name][cname][1]==false then
|
||||||
for _, func in pairs(controls.registered_on_press) do
|
for _, func in pairs(controls.registered_on_press) do
|
||||||
func(player, cname)
|
func(player, cname)
|
||||||
|
end
|
||||||
|
controls.players[player_name][cname] = {true, clock()}
|
||||||
|
elseif cbool==true and controls.players[player_name][cname][1]==true then
|
||||||
|
for _, func in pairs(controls.registered_on_hold) do
|
||||||
|
func(player, cname, clock()-controls.players[player_name][cname][2])
|
||||||
|
end
|
||||||
|
--Release a key
|
||||||
|
elseif cbool==false and controls.players[player_name][cname][1]==true then
|
||||||
|
for _, func in pairs(controls.registered_on_release) do
|
||||||
|
func(player, cname, clock()-controls.players[player_name][cname][2])
|
||||||
|
end
|
||||||
|
controls.players[player_name][cname] = {false}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
controls.players[player_name][cname] = {true, clock()}
|
|
||||||
elseif cbool==true and controls.players[player_name][cname][1]==true then
|
|
||||||
for _, func in pairs(controls.registered_on_hold) do
|
|
||||||
func(player, cname, clock()-controls.players[player_name][cname][2])
|
|
||||||
end
|
|
||||||
--Release a key
|
|
||||||
elseif cbool==false and controls.players[player_name][cname][1]==true then
|
|
||||||
for _, func in pairs(controls.registered_on_release) do
|
|
||||||
func(player, cname, clock()-controls.players[player_name][cname][2])
|
|
||||||
end
|
|
||||||
controls.players[player_name][cname] = {false}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
end
|
})
|
||||||
end
|
|
||||||
end)
|
|
|
@ -1,4 +1,5 @@
|
||||||
name = controls
|
name = controls
|
||||||
author = Arcelmi
|
author = Arcelmi
|
||||||
|
depends = mcl_util
|
||||||
description = Controls framework by Arcelmi
|
description = Controls framework by Arcelmi
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
# mcl_util
|
||||||
|
|
||||||
|
Provide utility functions for mcl2
|
||||||
|
|
||||||
|
## mcl_util.register_player_globalstep(def)
|
||||||
|
Used to register a player globalstep.
|
||||||
|
Use this insteed of global step if you need to execute action on all players to avoid calling the same functions multiple time.
|
||||||
|
|
||||||
|
```
|
||||||
|
mcl_util.register_player_globalstep({
|
||||||
|
can_execute = function(dtime)
|
||||||
|
return true --return false if you want to skip "execute" function
|
||||||
|
end,
|
||||||
|
execute = function(player, dtime)
|
||||||
|
--do some cool stuff
|
||||||
|
--will be executed for every player at each server step
|
||||||
|
end,
|
||||||
|
after_execute = function(dtime)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## mcl_util.registered_player_globalstep
|
||||||
|
Table containing all registered player globalstep.
|
|
@ -1,3 +1,5 @@
|
||||||
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||||
|
|
||||||
mcl_util = {}
|
mcl_util = {}
|
||||||
|
|
||||||
-- Based on minetest.rotate_and_place
|
-- Based on minetest.rotate_and_place
|
||||||
|
@ -418,3 +420,5 @@ function mcl_util.get_color(colorstr)
|
||||||
return colorstr, hex
|
return colorstr, hex
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dofile(modpath.."/playerstep.lua")
|
|
@ -0,0 +1,25 @@
|
||||||
|
local get_connected_players = minetest.get_connected_players
|
||||||
|
|
||||||
|
mcl_util.registered_player_globalstep = {}
|
||||||
|
local registered_player_globalstep = mcl_util.registered_player_globalstep
|
||||||
|
|
||||||
|
function mcl_util.register_player_globalstep(def)
|
||||||
|
if not def.can_execute then def.can_execute = function() return true end end
|
||||||
|
table.insert(mcl_util.registered_player_globalstep, {can_execute=def.can_execute, func=def.execute})
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_mods_loaded(function()
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
local players = get_connected_players()
|
||||||
|
for i = 1, #registered_player_globalstep do
|
||||||
|
if registered_player_globalstep[i].can_execute and registered_player_globalstep[i].can_execute(dtime) then
|
||||||
|
for p = 1, #players do
|
||||||
|
registered_player_globalstep[i].func(players[p], dtime)
|
||||||
|
end
|
||||||
|
if registered_player_globalstep[i].after_execute then
|
||||||
|
registered_player_globalstep[i].after_execute(dtime)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
|
@ -52,3 +52,33 @@ minetest.register_globalstep(function(dtime)
|
||||||
timer = 0
|
timer = 0
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--[[mcl_util.register_player_globalstep({
|
||||||
|
can_execute = function(dtime)
|
||||||
|
timer = timer + dtime;
|
||||||
|
if timer >= 0.3 then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
execute = function(player, dtime)
|
||||||
|
local pp = player:get_pos()
|
||||||
|
pp.y = ceil(pp.y)
|
||||||
|
local loc = vector_add(pp, {x=0,y=-1,z=0})
|
||||||
|
if loc ~= nil then
|
||||||
|
local nodeiamon = get_node(loc)
|
||||||
|
if nodeiamon ~= nil then
|
||||||
|
if on_walk[nodeiamon.name] then
|
||||||
|
on_walk[nodeiamon.name](loc, nodeiamon, player)
|
||||||
|
end
|
||||||
|
for i = 1, #registered_globals do
|
||||||
|
registered_globals[i](loc, nodeiamon, player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
after_execute = function(dtime)
|
||||||
|
timer = 0
|
||||||
|
end,
|
||||||
|
})]]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
name = walkover
|
name = walkover
|
||||||
author = lordfingle
|
author = lordfingle
|
||||||
|
depends = mcl_util
|
||||||
description = Some mode developers have shown an interest in having an `on_walk_over` event. This is useful for pressure-plates and the like.
|
description = Some mode developers have shown an interest in having an `on_walk_over` event. This is useful for pressure-plates and the like.
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ local is_in_void = mcl_worlds.is_in_void
|
||||||
local get_spawn_pos = mcl_spawn.get_player_spawn_pos
|
local get_spawn_pos = mcl_spawn.get_player_spawn_pos
|
||||||
local death_msg = mcl_death_messages.player_damage
|
local death_msg = mcl_death_messages.player_damage
|
||||||
local send_chat = minetest.chat_send_player
|
local send_chat = minetest.chat_send_player
|
||||||
local get_connected = minetest.get_connected_players
|
|
||||||
|
|
||||||
local voidtimer = 0
|
local voidtimer = 0
|
||||||
local VOID_DAMAGE_FREQ = 0.5
|
local VOID_DAMAGE_FREQ = 0.5
|
||||||
|
@ -54,37 +53,37 @@ minetest.register_on_mods_loaded(function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Hurt players or teleport them back to spawn if they are too deep in the void
|
-- Hurt players or teleport them back to spawn if they are too deep in the void
|
||||||
minetest.register_globalstep(function(dtime)
|
mcl_util.register_player_globalstep({
|
||||||
voidtimer = voidtimer + dtime
|
can_execute = function(dtime)
|
||||||
if voidtimer > VOID_DAMAGE_FREQ then
|
voidtimer = voidtimer + dtime
|
||||||
voidtimer = 0
|
if voidtimer > VOID_DAMAGE_FREQ then
|
||||||
local enable_damage = minetest.settings:get_bool("enable_damage")
|
voidtimer = 0
|
||||||
local players = get_connected()
|
return true
|
||||||
for p=1, #players do
|
end
|
||||||
local player = players[p]
|
end,
|
||||||
local pos = player:get_pos()
|
execute = function(player, dtime)
|
||||||
local void, void_deadly = is_in_void(pos)
|
local pos = player:get_pos()
|
||||||
if void_deadly then
|
local void, void_deadly = is_in_void(pos)
|
||||||
local immortal_val = player:get_armor_groups().immortal
|
if void_deadly then
|
||||||
local is_immortal = false
|
local immortal_val = player:get_armor_groups().immortal
|
||||||
if immortal_val and immortal_val > 0 then
|
local is_immortal = false
|
||||||
is_immortal = true
|
if immortal_val and immortal_val > 0 then
|
||||||
end
|
is_immortal = true
|
||||||
if is_immortal or not enable_damage then
|
end
|
||||||
-- If damage is disabled, we can't kill players.
|
if is_immortal or not enable_damage then
|
||||||
-- So we just teleport the player back to spawn.
|
-- If damage is disabled, we can't kill players.
|
||||||
local spawn = get_spawn_pos(player)
|
-- So we just teleport the player back to spawn.
|
||||||
player:set_pos(spawn)
|
local spawn = get_spawn_pos(player)
|
||||||
dim_change(player, pos_to_dim(spawn))
|
player:set_pos(spawn)
|
||||||
send_chat(player:get_player_name(), S("The void is off-limits to you!"))
|
dim_change(player, pos_to_dim(spawn))
|
||||||
elseif enable_damage and not is_immortal then
|
send_chat(player:get_player_name(), S("The void is off-limits to you!"))
|
||||||
-- Damage enabled, not immortal: Deal void damage (4 HP / 0.5 seconds)
|
elseif enable_damage and not is_immortal then
|
||||||
if player:get_hp() > 0 then
|
-- Damage enabled, not immortal: Deal void damage (4 HP / 0.5 seconds)
|
||||||
death_msg(player, S("@1 fell into the endless void.", player:get_player_name()))
|
if player:get_hp() > 0 then
|
||||||
player:set_hp(player:get_hp() - VOID_DAMAGE)
|
death_msg(player, S("@1 fell into the endless void.", player:get_player_name()))
|
||||||
end
|
player:set_hp(player:get_hp() - VOID_DAMAGE)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
end)
|
})
|
|
@ -1,6 +1,8 @@
|
||||||
local S = minetest.get_translator("doc_items")
|
local S = minetest.get_translator("doc_items")
|
||||||
local N = function(s) return s end
|
local N = function(s) return s end
|
||||||
|
|
||||||
|
local math = math
|
||||||
|
|
||||||
doc.sub.items = {}
|
doc.sub.items = {}
|
||||||
|
|
||||||
-- Template texts
|
-- Template texts
|
||||||
|
@ -1397,16 +1399,18 @@ TODO: If possible, try to replace this functionality by updating the revealed it
|
||||||
soon the player obtained a new item (probably needs new Minetest callbacks). ]]
|
soon the player obtained a new item (probably needs new Minetest callbacks). ]]
|
||||||
local checktime = 8
|
local checktime = 8
|
||||||
local timer = 0
|
local timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
timer = timer + dtime
|
|
||||||
if timer > checktime then
|
|
||||||
local players = minetest.get_connected_players()
|
|
||||||
for p=1, #players do
|
|
||||||
reveal_items_in_inventory(players[p])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
mcl_util.register_player_globalstep({
|
||||||
|
can_execute = function(dtime)
|
||||||
|
timer = timer + dtime
|
||||||
|
if timer > checktime then return true end
|
||||||
|
end,
|
||||||
|
execute = function(player, dtime)
|
||||||
|
reveal_items_in_inventory(player)
|
||||||
|
end,
|
||||||
|
after_execute = function(dtime)
|
||||||
timer = math.fmod(timer, checktime)
|
timer = math.fmod(timer, checktime)
|
||||||
end
|
end,
|
||||||
end)
|
})
|
||||||
|
|
||||||
minetest.register_on_mods_loaded(gather_descs)
|
minetest.register_on_mods_loaded(gather_descs)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name = doc_items
|
name = doc_items
|
||||||
author = Wuzzy
|
author = Wuzzy
|
||||||
description = Adds automatically generated help texts for items.
|
description = Adds automatically generated help texts for items.
|
||||||
depends = doc
|
depends = doc, mcl_util
|
||||||
|
|
|
@ -112,7 +112,7 @@ end)
|
||||||
|
|
||||||
local main_timer = 0
|
local main_timer = 0
|
||||||
local timer = 0
|
local timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
--[[minetest.register_globalstep(function(dtime)
|
||||||
main_timer = main_timer + dtime
|
main_timer = main_timer + dtime
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if main_timer > mcl_hbarmor.tick or timer > 4 then
|
if main_timer > mcl_hbarmor.tick or timer > 4 then
|
||||||
|
@ -132,4 +132,29 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if timer > 4 then timer = 0 end
|
if timer > 4 then timer = 0 end
|
||||||
end)
|
end)]]
|
||||||
|
|
||||||
|
mcl_util.register_player_globalstep({
|
||||||
|
can_execute = function(dtime)
|
||||||
|
main_timer = main_timer + dtime
|
||||||
|
timer = timer + dtime
|
||||||
|
if main_timer > mcl_hbarmor.tick or timer > 4 then
|
||||||
|
if minetest.settings:get_bool("enable_damage") then
|
||||||
|
if main_timer > mcl_hbarmor.tick then main_timer = 0 end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if timer > 4 then timer = 0 end
|
||||||
|
end,
|
||||||
|
execute = function(player, dtime)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if mcl_hbarmor.player_active[name] == true then
|
||||||
|
local ret = mcl_hbarmor.get_armor(player)
|
||||||
|
if ret == false then
|
||||||
|
minetest.log("error", "[mcl_hbarmor] Call to mcl_hbarmor.get_armor in globalstep returned with false!")
|
||||||
|
end
|
||||||
|
-- update all hud elements
|
||||||
|
update_hud(player)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name = mcl_hbarmor
|
name = mcl_hbarmor
|
||||||
author = BlockMen
|
author = BlockMen
|
||||||
description = Adds a HUD bar displaying the current damage of the player's armor.
|
description = Adds a HUD bar displaying the current damage of the player's armor.
|
||||||
depends = hudbars, mcl_armor
|
depends = hudbars, mcl_armor, mcl_util
|
||||||
|
|
|
@ -64,13 +64,12 @@ minetest.register_on_leaveplayer(function(player)
|
||||||
wieldindex[name] = nil
|
wieldindex[name] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
mcl_util.register_player_globalstep({
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
execute = function(player, dtime)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local wstack = player:get_wielded_item()
|
local wstack = player:get_wielded_item()
|
||||||
local wname = wstack:get_name()
|
local wname = wstack:get_name()
|
||||||
local windex = player:get_wield_index()
|
local windex = player:get_wield_index()
|
||||||
|
|
||||||
if dtimes[player_name] and dtimes[player_name] < dlimit then
|
if dtimes[player_name] and dtimes[player_name] < dlimit then
|
||||||
dtimes[player_name] = dtimes[player_name] + dtime
|
dtimes[player_name] = dtimes[player_name] + dtime
|
||||||
if dtimes[player_name] > dlimit and huds[player_name] then
|
if dtimes[player_name] > dlimit and huds[player_name] then
|
||||||
|
@ -83,12 +82,9 @@ minetest.register_globalstep(function(dtime)
|
||||||
wieldindex[player_name] = windex
|
wieldindex[player_name] = windex
|
||||||
wield[player_name] = wname
|
wield[player_name] = wname
|
||||||
dtimes[player_name] = 0
|
dtimes[player_name] = 0
|
||||||
|
|
||||||
if huds[player_name] then
|
if huds[player_name] then
|
||||||
|
|
||||||
local def = minetest.registered_items[wname]
|
local def = minetest.registered_items[wname]
|
||||||
local meta = wstack:get_meta()
|
local meta = wstack:get_meta()
|
||||||
|
|
||||||
--[[ Get description. Order of preference:
|
--[[ Get description. Order of preference:
|
||||||
* description from metadata
|
* description from metadata
|
||||||
* description from item definition
|
* description from item definition
|
||||||
|
@ -108,6 +104,5 @@ minetest.register_globalstep(function(dtime)
|
||||||
player:hud_change(huds[player_name], 'text', desc)
|
player:hud_change(huds[player_name], 'text', desc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
end)
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
name = show_wielded_item
|
name = show_wielded_item
|
||||||
author = 4aiman
|
author = 4aiman
|
||||||
description = Displays the name of the wielded item.
|
description = Displays the name of the wielded item.
|
||||||
|
depends = mcl_util
|
||||||
optional_depends = hudbars
|
optional_depends = hudbars
|
||||||
|
|
|
@ -340,17 +340,15 @@ controls.register_on_hold(function(player, key, time)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
mcl_util.register_player_globalstep({
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
execute = function(player, dtime)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local wielditem = player:get_wielded_item()
|
local wielditem = player:get_wielded_item()
|
||||||
local wieldindex = player:get_wield_index()
|
if type(bow_load[name]) == "number" and ((wielditem:get_name()~="mcl_bows:bow_0" and wielditem:get_name()~="mcl_bows:bow_1" and wielditem:get_name()~="mcl_bows:bow_2" and wielditem:get_name()~="mcl_bows:bow_0_enchanted" and wielditem:get_name()~="mcl_bows:bow_1_enchanted" and wielditem:get_name()~="mcl_bows:bow_2_enchanted") or player:get_wield_index() ~= bow_index[name]) then
|
||||||
local controls = player:get_player_control()
|
|
||||||
if type(bow_load[name]) == "number" and ((wielditem:get_name()~="mcl_bows:bow_0" and wielditem:get_name()~="mcl_bows:bow_1" and wielditem:get_name()~="mcl_bows:bow_2" and wielditem:get_name()~="mcl_bows:bow_0_enchanted" and wielditem:get_name()~="mcl_bows:bow_1_enchanted" and wielditem:get_name()~="mcl_bows:bow_2_enchanted") or wieldindex ~= bow_index[name]) then
|
|
||||||
reset_bow_state(player, true)
|
reset_bow_state(player, true)
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
end)
|
})
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
reset_bows(player)
|
reset_bows(player)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name = mcl_bows
|
name = mcl_bows
|
||||||
author = Arcelmi
|
author = Arcelmi
|
||||||
description = This mod adds bows and arrows for MineClone 2.
|
description = This mod adds bows and arrows for MineClone 2.
|
||||||
depends = controls, mcl_particles, mcl_enchanting, mcl_init
|
depends = controls, mcl_particles, mcl_enchanting, mcl_init, mcl_util
|
||||||
optional_depends = awards, mcl_achievements, mcl_core, mcl_mobitems, playerphysics, doc, doc_identifier, mesecons_button
|
optional_depends = awards, mcl_achievements, mcl_core, mcl_mobitems, playerphysics, doc, doc_identifier, mesecons_button
|
||||||
|
|
||||||
|
|
|
@ -76,25 +76,26 @@ end
|
||||||
-- This timer makes sure the clocks get updated from time to time regardless of time_speed,
|
-- This timer makes sure the clocks get updated from time to time regardless of time_speed,
|
||||||
-- just in case some clocks in the world go wrong
|
-- just in case some clocks in the world go wrong
|
||||||
local force_clock_update_timer = 0
|
local force_clock_update_timer = 0
|
||||||
|
local now
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
mcl_util.register_player_globalstep({
|
||||||
local now = watch.get_clock_frame()
|
can_execute = function(dtime)
|
||||||
force_clock_update_timer = force_clock_update_timer + dtime
|
now = watch.get_clock_frame()
|
||||||
random_timer = random_timer + dtime
|
force_clock_update_timer = force_clock_update_timer + dtime
|
||||||
-- This causes the random spinning of the clock
|
random_timer = random_timer + dtime
|
||||||
if random_timer >= random_timer_trigger then
|
-- This causes the random spinning of the clock
|
||||||
random_frame = (random_frame + math.random(-4, 4)) % clock_frames
|
if random_timer >= random_timer_trigger then
|
||||||
random_timer = 0
|
random_frame = (random_frame + math.random(-4, 4)) % clock_frames
|
||||||
end
|
random_timer = 0
|
||||||
|
end
|
||||||
if watch.old_time == now and force_clock_update_timer < 60 then
|
if watch.old_time == now and force_clock_update_timer < 60 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
force_clock_update_timer = 0
|
force_clock_update_timer = 0
|
||||||
|
watch.old_time = now
|
||||||
watch.old_time = now
|
return true
|
||||||
|
end,
|
||||||
for p, player in pairs(minetest.get_connected_players()) do
|
execute = function(player, dtime)
|
||||||
for s, stack in pairs(player:get_inventory():get_list("main")) do
|
for s, stack in pairs(player:get_inventory():get_list("main")) do
|
||||||
local dim = mcl_worlds.pos_to_dimension(player:get_pos())
|
local dim = mcl_worlds.pos_to_dimension(player:get_pos())
|
||||||
local frame
|
local frame
|
||||||
|
@ -111,8 +112,8 @@ minetest.register_globalstep(function(dtime)
|
||||||
player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count)
|
player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
end)
|
})
|
||||||
|
|
||||||
-- Immediately set correct clock time after crafting
|
-- Immediately set correct clock time after crafting
|
||||||
minetest.register_on_craft(function(itemstack)
|
minetest.register_on_craft(function(itemstack)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name = mcl_clock
|
name = mcl_clock
|
||||||
description = A fantasy clock item roughly shows the time of day.
|
description = A fantasy clock item roughly shows the time of day.
|
||||||
depends = mcl_init, mcl_worlds, mesecons
|
depends = mcl_init, mcl_worlds, mesecons, mcl_util
|
||||||
optional_depends = doc
|
optional_depends = doc
|
||||||
|
|
|
@ -12,22 +12,27 @@ local random_timer_trigger = 0.5 -- random compass spinning tick in seconds. Inc
|
||||||
|
|
||||||
local random_frame = math.random(0, compass_frames-1)
|
local random_frame = math.random(0, compass_frames-1)
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
local math = math
|
||||||
random_timer = random_timer + dtime
|
|
||||||
|
|
||||||
if random_timer >= random_timer_trigger then
|
local function has_compass(player)
|
||||||
random_frame = (random_frame + math.random(-1, 1)) % compass_frames
|
for _,stack in pairs(player:get_inventory():get_list("main")) do
|
||||||
random_timer = 0
|
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 then
|
||||||
end
|
return true
|
||||||
for i,player in pairs(minetest.get_connected_players()) do
|
|
||||||
local function has_compass(player)
|
|
||||||
for _,stack in pairs(player:get_inventory():get_list("main")) do
|
|
||||||
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
mcl_util.register_player_globalstep({
|
||||||
|
can_execute = function(dtime)
|
||||||
|
random_timer = random_timer + dtime
|
||||||
|
if random_timer >= random_timer_trigger then
|
||||||
|
random_frame = (random_frame + math.random(-1, 1)) % compass_frames
|
||||||
|
random_timer = 0
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
execute = function(player, dtime)
|
||||||
if has_compass(player) then
|
if has_compass(player) then
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local dim = mcl_worlds.pos_to_dimension(pos)
|
local dim = mcl_worlds.pos_to_dimension(pos)
|
||||||
|
@ -61,8 +66,8 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
end)
|
})
|
||||||
|
|
||||||
local images = {}
|
local images = {}
|
||||||
for frame = 0, compass_frames-1 do
|
for frame = 0, compass_frames-1 do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name = mcl_compass
|
name = mcl_compass
|
||||||
description = A compass item which points towards the world origin.
|
description = A compass item which points towards the world origin.
|
||||||
depends = mcl_core, mcl_worlds, mesecons
|
depends = mcl_core, mcl_worlds, mesecons, mcl_util
|
||||||
optional_depends = doc
|
optional_depends = doc
|
||||||
|
|
|
@ -19,7 +19,7 @@ local find_nodes_in_area = minetest.find_nodes_in_area
|
||||||
local find_node_near = minetest.find_node_near
|
local find_node_near = minetest.find_node_near
|
||||||
local get_item_group = minetest.get_item_group
|
local get_item_group = minetest.get_item_group
|
||||||
|
|
||||||
local get_connected_players = minetest.get_connected_players
|
--local get_connected_players = minetest.get_connected_players
|
||||||
|
|
||||||
local vector = vector
|
local vector = vector
|
||||||
local math = math
|
local math = math
|
||||||
|
@ -463,7 +463,7 @@ if flame_sound then
|
||||||
|
|
||||||
-- Cycle for updating players sounds
|
-- Cycle for updating players sounds
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
--[[minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if timer < cycle then
|
if timer < cycle then
|
||||||
return
|
return
|
||||||
|
@ -474,7 +474,21 @@ if flame_sound then
|
||||||
for n = 1, #players do
|
for n = 1, #players do
|
||||||
mcl_fire.update_player_sound(players[n])
|
mcl_fire.update_player_sound(players[n])
|
||||||
end
|
end
|
||||||
end)
|
end)]]
|
||||||
|
|
||||||
|
mcl_util.register_player_globalstep({
|
||||||
|
can_execute = function(dtime)
|
||||||
|
timer = timer + dtime
|
||||||
|
if timer < cycle then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
timer = 0
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
execute = function(player, dtime)
|
||||||
|
mcl_fire.update_player_sound(player)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
-- Stop sound and clear handle on player leave
|
-- Stop sound and clear handle on player leave
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
name = mcl_fire
|
name = mcl_fire
|
||||||
depends = mcl_core, mcl_worlds, mcl_sounds, mcl_particles
|
depends = mcl_core, mcl_worlds, mcl_sounds, mcl_particles, mcl_util
|
||||||
optional_depends = mcl_portals
|
optional_depends = mcl_portals
|
|
@ -97,14 +97,16 @@ end)
|
||||||
|
|
||||||
local updatetimer = 0
|
local updatetimer = 0
|
||||||
if not minetest.is_creative_enabled("") then
|
if not minetest.is_creative_enabled("") then
|
||||||
minetest.register_globalstep(function(dtime)
|
mcl_util.register_player_globalstep({
|
||||||
updatetimer = updatetimer + dtime
|
can_execute = function(dtime)
|
||||||
if updatetimer > 0.1 then
|
updatetimer = updatetimer + dtime
|
||||||
local players = minetest.get_connected_players()
|
if updatetimer > 0.1 then return true else return false end
|
||||||
for i=1, #players do
|
end,
|
||||||
update_minimap(players[i])
|
execute = function(player, dtime)
|
||||||
end
|
update_minimap(player)
|
||||||
|
end,
|
||||||
|
after_execute = function(dtime)
|
||||||
updatetimer = updatetimer - dtime
|
updatetimer = updatetimer - dtime
|
||||||
end
|
end,
|
||||||
end)
|
})
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
name = mcl_maps
|
name = mcl_maps
|
||||||
depends = mcl_wip
|
depends = mcl_wip, mcl_util
|
||||||
|
|
|
@ -181,6 +181,54 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--[[mcl_util.register_player_globalstep({
|
||||||
|
can_execute = function(dtime)
|
||||||
|
main_timer = main_timer + dtime
|
||||||
|
timer = timer + dtime
|
||||||
|
if main_timer > mcl_hunger.HUD_TICK or timer > 0.5 then
|
||||||
|
if main_timer > mcl_hunger.HUD_TICK then main_timer = 0 end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
execute = function(player, dtime)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local h = tonumber(mcl_hunger.get_hunger(player))
|
||||||
|
local hp = player:get_hp()
|
||||||
|
if timer > 0.5 then
|
||||||
|
-- Slow health regeneration, and hunger damage (every 4s).
|
||||||
|
-- Regeneration rate based on tutorial video <https://www.youtube.com/watch?v=zs2t-xCVHBo>.
|
||||||
|
-- Minecraft Wiki seems to be wrong in claiming that full hunger gives 0.5s regen rate.
|
||||||
|
if timerMult == 0 then
|
||||||
|
if h >= 18 and hp > 0 and hp < 20 then
|
||||||
|
-- +1 HP, +exhaustion
|
||||||
|
player:set_hp(hp+1)
|
||||||
|
mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_REGEN)
|
||||||
|
mcl_hunger.update_exhaustion_hud(player, mcl_hunger.get_exhaustion(player))
|
||||||
|
elseif h == 0 then
|
||||||
|
-- Damage hungry player down to 1 HP
|
||||||
|
-- TODO: Allow starvation at higher difficulty levels
|
||||||
|
if hp-1 > 0 then
|
||||||
|
if mod_death_messages then
|
||||||
|
mcl_death_messages.player_damage(player, S("@1 starved to death.", name))
|
||||||
|
end
|
||||||
|
player:set_hp(hp-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
after_execute = function(dtime)
|
||||||
|
if timer > 0.5 then
|
||||||
|
timer = 0
|
||||||
|
timerMult = timerMult + 1
|
||||||
|
if timerMult > 7 then
|
||||||
|
timerMult = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})]]
|
||||||
|
|
||||||
--[[ IF HUNGER IS NOT ENABLED ]]
|
--[[ IF HUNGER IS NOT ENABLED ]]
|
||||||
else
|
else
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name = mcl_hunger
|
name = mcl_hunger
|
||||||
author = BlockMen
|
author = BlockMen
|
||||||
description = Adds a simple hunger meachanic with satiation, food poisoning and different healing.
|
description = Adds a simple hunger meachanic with satiation, food poisoning and different healing.
|
||||||
depends = hudbars
|
depends = hudbars, mcl_util
|
||||||
optional_depends = mcl_death_messages
|
optional_depends = mcl_death_messages
|
||||||
|
|
|
@ -147,8 +147,8 @@ local player_set_animation = mcl_player.player_set_animation
|
||||||
local player_attached = mcl_player.player_attached
|
local player_attached = mcl_player.player_attached
|
||||||
|
|
||||||
-- Check each player and apply animations
|
-- Check each player and apply animations
|
||||||
minetest.register_globalstep(function(dtime)
|
mcl_util.register_player_globalstep({
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
execute = function(player, dtime)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local model_name = player_model[name]
|
local model_name = player_model[name]
|
||||||
local model = model_name and models[model_name]
|
local model = model_name and models[model_name]
|
||||||
|
@ -167,8 +167,6 @@ minetest.register_globalstep(function(dtime)
|
||||||
animation_speed_mod = animation_speed_mod / 2
|
animation_speed_mod = animation_speed_mod / 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- ask if player is swiming
|
-- ask if player is swiming
|
||||||
local head_in_water = minetest.get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0
|
local head_in_water = minetest.get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0
|
||||||
-- ask if player is sprinting
|
-- ask if player is sprinting
|
||||||
|
@ -217,8 +215,8 @@ minetest.register_globalstep(function(dtime)
|
||||||
player_set_animation(player, "sneak_stand", animation_speed_mod)
|
player_set_animation(player, "sneak_stand", animation_speed_mod)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
end)
|
})
|
||||||
|
|
||||||
-- Don't change HP if the player falls in the water or through End Portal:
|
-- Don't change HP if the player falls in the water or through End Portal:
|
||||||
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
name = mcl_player
|
name = mcl_player
|
||||||
author = celeron55
|
author = celeron55
|
||||||
|
depends = mcl_util
|
||||||
description = Adds the 3D player model, taken from Minetest Game 0.4.16.
|
description = Adds the 3D player model, taken from Minetest Game 0.4.16.
|
||||||
|
|
|
@ -39,37 +39,51 @@ local get_player_nodes = function(player_pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
time = time + dtime
|
time = time + dtime
|
||||||
|
|
||||||
-- Run the rest of the code every 0.5 seconds
|
-- Run the rest of the code every 0.5 seconds
|
||||||
if time < 0.5 then
|
if time < 0.5 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset time for next check
|
-- reset time for next check
|
||||||
-- FIXME: Make sure a regular check interval applies
|
-- FIXME: Make sure a regular check interval applies
|
||||||
time = 0
|
time = 0
|
||||||
|
|
||||||
-- check players
|
-- check players
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
-- who am I?
|
-- who am I?
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
-- where am I?
|
-- where am I?
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
|
||||||
-- what is around me?
|
-- what is around me?
|
||||||
local node_stand, node_stand_below, node_head, node_feet = get_player_nodes(pos)
|
local node_stand, node_stand_below, node_head, node_feet = get_player_nodes(pos)
|
||||||
mcl_playerinfo[name].node_stand = node_stand
|
mcl_playerinfo[name].node_stand = node_stand
|
||||||
mcl_playerinfo[name].node_stand_below = node_stand_below
|
mcl_playerinfo[name].node_stand_below = node_stand_below
|
||||||
mcl_playerinfo[name].node_head = node_head
|
mcl_playerinfo[name].node_head = node_head
|
||||||
mcl_playerinfo[name].node_feet = node_feet
|
mcl_playerinfo[name].node_feet = node_feet
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--[[mcl_util.register_player_globalstep({
|
||||||
|
can_execute = function(dtime)
|
||||||
|
time = time + dtime
|
||||||
|
if time < 0.5 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
-- reset time for next check
|
||||||
|
-- FIXME: Make sure a regular check interval applies
|
||||||
|
time = 0
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
execute = function(player, dtime)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local pos = player:get_pos()
|
||||||
|
local node_stand, node_stand_below, node_head, node_feet = get_player_nodes(pos)
|
||||||
|
mcl_playerinfo[name].node_stand = node_stand
|
||||||
|
mcl_playerinfo[name].node_stand_below = node_stand_below
|
||||||
|
mcl_playerinfo[name].node_head = node_head
|
||||||
|
mcl_playerinfo[name].node_feet = node_feet
|
||||||
|
end,
|
||||||
|
})]]
|
||||||
|
|
||||||
-- set to blank on join (for 3rd party mods)
|
-- set to blank on join (for 3rd party mods)
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name = mcl_playerinfo
|
name = mcl_playerinfo
|
||||||
author = TenPlus1
|
author = TenPlus1
|
||||||
description = This is a helper mod for other mod to query the nodes around the player.
|
description = This is a helper mod for other mod to query the nodes around the player.
|
||||||
depends = mcl_init, mcl_core, mcl_particles, mcl_death_messages
|
depends = mcl_init, mcl_core, mcl_particles, mcl_death_messages, mcl_util
|
||||||
|
|
|
@ -81,11 +81,18 @@ minetest.register_on_joinplayer(function(player)
|
||||||
end, player)
|
end, player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_globalstep(function()
|
--[[minetest.register_globalstep(function()
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
wieldview:update_wielded_item(player)
|
wieldview:update_wielded_item(player)
|
||||||
end
|
end
|
||||||
end)
|
end)]]
|
||||||
|
|
||||||
|
mcl_util.register_player_globalstep({
|
||||||
|
can_execute = function(dtime) return true end,
|
||||||
|
execute = function(player, dtime)
|
||||||
|
wieldview:update_wielded_item(player)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_entity("wieldview:wieldnode", {
|
minetest.register_entity("wieldview:wieldnode", {
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name = wieldview
|
name = wieldview
|
||||||
author = stujones11
|
author = stujones11
|
||||||
description = Makes hand wielded items visible to other players.
|
description = Makes hand wielded items visible to other players.
|
||||||
depends = mcl_armor
|
depends = mcl_armor, mcl_util
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue