2019-03-02 10:13:39 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-12-24 11:21:45 -05:00
|
|
|
local minetest, nodecore, pairs, table
|
|
|
|
= minetest, nodecore, pairs, table
|
|
|
|
local table_concat
|
|
|
|
= table.concat
|
2019-03-02 10:13:39 -05:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
2019-09-07 09:08:57 -04:00
|
|
|
nodecore.amcoremod()
|
|
|
|
|
2019-03-02 10:13:39 -05:00
|
|
|
local modname = minetest.get_current_modname()
|
2019-03-02 09:01:12 -05:00
|
|
|
|
2019-02-27 20:20:07 -08:00
|
|
|
local anim = {
|
2019-08-27 19:14:51 -04:00
|
|
|
stand = {x = 0, y = 0},
|
|
|
|
sit = {x = 1, y = 1},
|
|
|
|
walk = {x = 2, y = 42},
|
|
|
|
mine = {x = 43, y = 57, speed = 0.85},
|
|
|
|
lay = {x = 58, y = 58},
|
|
|
|
walk_mine = {x = 59, y = 103},
|
|
|
|
swim_up = {x = 105, y = 162, speed = 0.4},
|
2019-08-09 08:54:05 -04:00
|
|
|
swim_down = {x = 163, y = 223, speed = 0.4},
|
|
|
|
swim_mine = {x = 224, y = 281, speed = 0.5}
|
2019-03-02 10:13:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
local function setcached(func)
|
|
|
|
local cache = {}
|
|
|
|
return function(player, value)
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
if cache[pname] == value then return end
|
|
|
|
cache[pname] = value
|
|
|
|
return func(player, value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local setanim = setcached(function(player, x)
|
2019-04-04 01:48:54 -04:00
|
|
|
local a = anim[x] or anim.stand
|
|
|
|
player:set_animation({x = a.x, y = a.y},
|
|
|
|
72 * (a.speed or 1))
|
2019-03-02 10:13:39 -05:00
|
|
|
end)
|
|
|
|
local setskin = setcached(function(player, x)
|
|
|
|
player:set_properties({textures = {x}})
|
|
|
|
end)
|
|
|
|
|
2019-04-02 08:23:09 -04:00
|
|
|
local skintimes = {}
|
2019-04-04 01:48:54 -04:00
|
|
|
|
|
|
|
local liquids = {}
|
|
|
|
minetest.after(0, function()
|
|
|
|
for k, v in pairs(minetest.registered_items) do
|
|
|
|
if v.liquidtype and v.liquidtype ~= "none" then
|
|
|
|
liquids[k] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
local function swimming(player)
|
|
|
|
local pos = player:get_pos()
|
2019-04-04 02:01:49 -04:00
|
|
|
local r = 0.6
|
|
|
|
for dz = -r, r, r do
|
|
|
|
for dx = -r, r, r do
|
2019-04-04 01:48:54 -04:00
|
|
|
local p = {
|
|
|
|
x = pos.x + dx,
|
2019-04-04 02:01:49 -04:00
|
|
|
y = pos.y,
|
2019-04-04 01:48:54 -04:00
|
|
|
z = pos.z + dz
|
|
|
|
}
|
|
|
|
local node = minetest.get_node(p)
|
2019-04-04 02:01:49 -04:00
|
|
|
if (node.name == "air" or liquids[node.name]) then
|
|
|
|
p.y = p.y - 0.35
|
|
|
|
node = minetest.get_node(p)
|
2019-04-04 01:48:54 -04:00
|
|
|
end
|
2019-04-04 02:01:49 -04:00
|
|
|
if not liquids[node.name] then return end
|
2019-04-04 01:48:54 -04:00
|
|
|
end
|
|
|
|
end
|
2019-04-04 02:01:49 -04:00
|
|
|
return true
|
2019-04-04 01:48:54 -04:00
|
|
|
end
|
|
|
|
|
2019-12-24 11:21:45 -05:00
|
|
|
nodecore.player_skin = nodecore.player_skin or function(player)
|
|
|
|
local skin = player:get_meta():get_string("custom_skin") or ""
|
|
|
|
if skin ~= "" then return skin end
|
|
|
|
|
2019-12-24 12:27:05 -05:00
|
|
|
local layers = {modname .. "_base.png"}
|
2019-12-24 11:21:45 -05:00
|
|
|
|
|
|
|
local privs = minetest.get_player_privs(player:get_player_name())
|
2019-12-24 12:27:05 -05:00
|
|
|
if not privs.interact then
|
|
|
|
layers[#layers + 1] = modname .. "_no_interact.png"
|
|
|
|
layers[#layers + 1] = "[makealpha:254,0,253"
|
|
|
|
end
|
|
|
|
if not privs.shout then
|
|
|
|
layers[#layers + 1] = modname .. "_no_shout.png"
|
2019-12-24 11:21:45 -05:00
|
|
|
end
|
|
|
|
|
2019-12-24 12:27:05 -05:00
|
|
|
return table_concat(layers, "^"), layers
|
2019-12-24 11:21:45 -05:00
|
|
|
end
|
|
|
|
|
2019-03-02 10:13:39 -05:00
|
|
|
local function updatevisuals(player)
|
2019-03-11 23:00:42 -04:00
|
|
|
local hp = player:get_hp()
|
2019-03-02 10:13:39 -05:00
|
|
|
if hp <= 0 then
|
|
|
|
setanim(player, "lay")
|
|
|
|
else
|
|
|
|
local ctl = player:get_player_control()
|
|
|
|
local walk = ctl.up or ctl.down or ctl.right or ctl.left
|
|
|
|
local mine = ctl.LMB or ctl.RMB
|
2019-04-02 13:47:41 -07:00
|
|
|
|
2019-04-04 01:48:54 -04:00
|
|
|
if not swimming(player) then
|
2019-04-02 13:47:41 -07:00
|
|
|
if walk and mine then
|
|
|
|
setanim(player, "walk_mine")
|
|
|
|
elseif walk then
|
|
|
|
setanim(player, "walk")
|
|
|
|
elseif mine then
|
|
|
|
setanim(player, "mine")
|
|
|
|
else
|
|
|
|
setanim(player, "stand")
|
|
|
|
end
|
2019-03-02 10:13:39 -05:00
|
|
|
else
|
2019-04-02 13:47:41 -07:00
|
|
|
local v = player:get_player_velocity()
|
|
|
|
|
2019-04-04 01:48:54 -04:00
|
|
|
if mine then
|
2019-08-09 08:54:05 -04:00
|
|
|
setanim(player, "swim_mine")
|
2019-04-04 01:48:54 -04:00
|
|
|
elseif v and v.y >= -0.5 then
|
2019-04-02 13:47:41 -07:00
|
|
|
setanim(player, "swim_up")
|
|
|
|
else
|
|
|
|
setanim(player, "swim_down")
|
|
|
|
end
|
2019-03-02 10:13:39 -05:00
|
|
|
end
|
|
|
|
end
|
2019-02-27 20:20:07 -08:00
|
|
|
|
2019-04-02 08:23:09 -04:00
|
|
|
local pname = player:get_player_name()
|
|
|
|
local now = minetest.get_us_time() / 1000000
|
|
|
|
local last = skintimes[pname] or 0
|
2019-12-24 11:21:45 -05:00
|
|
|
if now >= last + 2 then
|
|
|
|
skintimes[pname] = now
|
|
|
|
setskin(player, nodecore.player_skin(player))
|
2019-03-02 10:13:39 -05:00
|
|
|
end
|
|
|
|
end
|
2019-02-27 20:20:07 -08:00
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2019-03-02 10:13:39 -05:00
|
|
|
player:set_properties({
|
|
|
|
visual = "mesh",
|
2019-03-02 12:02:08 -05:00
|
|
|
visual_size = {x = 0.9, y = 0.9, z = 0.9},
|
2019-04-06 11:21:34 -04:00
|
|
|
mesh = modname .. ".b3d"
|
2019-03-02 10:13:39 -05:00
|
|
|
})
|
|
|
|
setskin(player, "dummy")
|
|
|
|
setanim(player, "dummy")
|
|
|
|
updatevisuals(player)
|
2019-02-27 20:20:07 -08:00
|
|
|
end)
|
|
|
|
|
2019-08-31 09:26:53 -04:00
|
|
|
minetest.register_globalstep(function()
|
2019-03-02 10:13:39 -05:00
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
2019-12-11 06:52:09 -05:00
|
|
|
if nodecore.player_visible(player) then
|
|
|
|
updatevisuals(player)
|
|
|
|
end
|
2019-02-28 08:37:33 -08:00
|
|
|
end
|
2019-03-02 10:13:39 -05:00
|
|
|
end)
|