1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2025-07-21 01:30:21 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
65e369e5fc add 0.4.x compatibility when riding mod 2022-03-01 09:04:38 +00:00
9f74408792 remove owner infotext if no owner present 2022-02-05 12:25:01 +00:00
4 changed files with 42 additions and 15 deletions

View File

@ -28,7 +28,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = { mobs = {
mod = "redo", mod = "redo",
version = "20220120", version = "20220205",
intllib = S, intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {} invis = minetest.global_exists("invisibility") and invisibility or {}
} }
@ -785,7 +785,7 @@ function mob_class:update_tag()
end end
self.infotext = "Health: " .. self.health .. " / " .. self.hp_max self.infotext = "Health: " .. self.health .. " / " .. self.hp_max
.. "\n" .. "Owner: " .. self.owner .. (self.owner == "" and "" or "\n" .. "Owner: " .. self.owner)
.. text .. text
-- set changes -- set changes

View File

@ -8,3 +8,4 @@ lucky_block?
cmi? cmi?
toolranks? toolranks?
pathfinder? pathfinder?
player_api?

View File

@ -1,4 +1,4 @@
name = mobs name = mobs
depends = depends =
optional_depends = default, tnt, dye, farming, invisibility, intllib, lucky_block, cmi, toolranks, pathfinder optional_depends = default, tnt, dye, farming, invisibility, intllib, lucky_block, cmi, toolranks, pathfinder, player_api
description = Adds a mob api for mods to add animals or monsters etc. description = Adds a mob api for mods to add animals or monsters etc.

View File

@ -1,14 +1,16 @@
-- lib_mount by Blert2112 (edited by TenPlus1) -- lib_mount by Blert2112 (edited by TenPlus1)
local is_50 = minetest.get_modpath("player_api") -- 5.x compatibility
local abs, cos, floor, sin, sqrt, pi = local abs, cos, floor, sin, sqrt, pi =
math.abs, math.cos, math.floor, math.sin, math.sqrt, math.pi math.abs, math.cos, math.floor, math.sin, math.sqrt, math.pi
------------------------------------------------------------------------------
-- --
-- Helper functions -- Helper functions
-- --
local node_ok = function(pos, fallback) local node_ok = function(pos, fallback)
fallback = fallback or mobs.fallback_node fallback = fallback or mobs.fallback_node
local node = minetest.get_node_or_nil(pos) local node = minetest.get_node_or_nil(pos)
@ -46,6 +48,7 @@ end
local function get_sign(i) local function get_sign(i)
i = i or 0 i = i or 0
if i == 0 then if i == 0 then
@ -57,6 +60,7 @@ end
local function get_velocity(v, yaw, y) local function get_velocity(v, yaw, y)
local x = -sin(yaw) * v local x = -sin(yaw) * v
local z = cos(yaw) * v local z = cos(yaw) * v
@ -71,6 +75,8 @@ end
local function force_detach(player) local function force_detach(player)
if not player then return end
local attached_to = player:get_attach() local attached_to = player:get_attach()
if not attached_to then if not attached_to then
@ -85,19 +91,27 @@ local function force_detach(player)
end end
player:set_detach() player:set_detach()
player_api.player_attached[player:get_player_name()] = false
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
player_api.set_animation(player, "stand", 30)
player:set_properties({visual_size = {x = 1, y = 1}})
local name = player:get_player_name()
if is_50 then
player_api.player_attached[name] = false
player_api.set_animation(player, "stand", 30)
else
default.player_attached[name] = false
default.player_set_animation(player, "stand", 30)
end
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
player:set_properties({visual_size = {x = 1, y = 1}})
end end
-------------------------------------------------------------------------------
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
force_detach(player) force_detach(player)
end) end)
minetest.register_on_shutdown(function() minetest.register_on_shutdown(function()
local players = minetest.get_connected_players() local players = minetest.get_connected_players()
@ -107,12 +121,12 @@ minetest.register_on_shutdown(function()
end end
end) end)
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
force_detach(player) force_detach(player)
return true return true
end) end)
-------------------------------------------------------------------------------
-- Just for correct detaching -- Just for correct detaching
local function find_free_pos(pos) local function find_free_pos(pos)
@ -147,7 +161,6 @@ local function find_free_pos(pos)
return pos return pos
end end
-------------------------------------------------------------------------------
function mobs.attach(entity, player) function mobs.attach(entity, player)
@ -169,8 +182,13 @@ function mobs.attach(entity, player)
force_detach(player) force_detach(player)
if is_50 then
player_api.player_attached[player:get_player_name()] = true
else
default.player_attached[player:get_player_name()] = true
end
player:set_attach(entity.object, "", attach_at, entity.player_rotation) player:set_attach(entity.object, "", attach_at, entity.player_rotation)
player_api.player_attached[player:get_player_name()] = true
player:set_eye_offset(eye_offset, {x = 0, y = 0, z = 0}) player:set_eye_offset(eye_offset, {x = 0, y = 0, z = 0})
player:set_properties({ player:set_properties({
@ -183,7 +201,12 @@ function mobs.attach(entity, player)
minetest.after(0.2, function() minetest.after(0.2, function()
if player and player:is_player() then if player and player:is_player() then
player_api.set_animation(player, "sit", 30)
if is_50 then
player_api.set_animation(player, "sit", 30)
else
default.player_set_animation(player, "sit", 30)
end
end end
end) end)
@ -192,6 +215,7 @@ end
function mobs.detach(player) function mobs.detach(player)
force_detach(player) force_detach(player)
minetest.after(0.1, function() minetest.after(0.1, function()
@ -262,6 +286,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
entity.object:set_yaw(horz - entity.rotate) entity.object:set_yaw(horz - entity.rotate)
if can_fly then if can_fly then
-- fly up -- fly up
if ctrl.jump then if ctrl.jump then
@ -430,11 +455,12 @@ function mobs.fly(entity, _, speed, shoots, arrow, moving_anim, stand_anim)
local ctrl = entity.driver:get_player_control() ; if not ctrl then return end local ctrl = entity.driver:get_player_control() ; if not ctrl then return end
local velo = entity.object:get_velocity() local velo = entity.object:get_velocity()
local dir = entity.driver:get_look_dir() local dir = entity.driver:get_look_dir()
local yaw = entity.driver:get_look_horizontal() + 1.57 -- offset fix between old and new commands local yaw = entity.driver:get_look_horizontal() + 1.57
if not ctrl or not velo then return end if not ctrl or not velo then return end
if ctrl.up then if ctrl.up then
entity.object:set_velocity({ entity.object:set_velocity({
x = dir.x * speed, x = dir.x * speed,
y = dir.y * speed + 2, y = dir.y * speed + 2,