Fix depends, add nil check, sync upstream
* Merge branch 'master' of https://notabug.org/TenPlus1/mobs_redo into main
* add nil check: f54c3da9d7 (diff-d2643c2921d034dfcc814205174726af270f51bR277)
close https://notabug.org/TenPlus1/mobs_redo/issues/114
close https://codeberg.org/minenux/minetest-mod-mobs_redo/issues/107
* force depends on default and player_api
This commit is contained in:
commit
1921a03b45
6
api.lua
6
api.lua
@ -28,7 +28,7 @@ local use_cmi = minetest.global_exists("cmi")
|
||||
|
||||
mobs = {
|
||||
mod = "redo",
|
||||
version = "20220120",
|
||||
version = "20220313",
|
||||
intllib = S,
|
||||
invis = minetest.global_exists("invisibility") and invisibility or {}
|
||||
}
|
||||
@ -274,7 +274,7 @@ local check_for = function(look_for, look_inside)
|
||||
return true
|
||||
end
|
||||
|
||||
if str:find("group:") then
|
||||
if str and str:find("group:") then
|
||||
|
||||
local group = str:split(":")[2]
|
||||
|
||||
@ -785,7 +785,7 @@ function mob_class:update_tag()
|
||||
end
|
||||
|
||||
self.infotext = "Health: " .. self.health .. " / " .. self.hp_max
|
||||
.. "\n" .. "Owner: " .. self.owner
|
||||
.. (self.owner == "" and "" or "\n" .. "Owner: " .. self.owner)
|
||||
.. text
|
||||
|
||||
-- set changes
|
||||
|
@ -1,4 +1,4 @@
|
||||
default?
|
||||
default
|
||||
tnt?
|
||||
dye?
|
||||
farming?
|
||||
|
4
mod.conf
4
mod.conf
@ -1,4 +1,4 @@
|
||||
name = mobs
|
||||
depends =
|
||||
optional_depends = default, tnt, dye, farming, invisibility, intllib, lucky_block, cmi, toolranks, pathfinder
|
||||
depends =default, player_api
|
||||
optional_depends = tnt, dye, farming, invisibility, intllib, lucky_block, cmi, toolranks, pathfinder
|
||||
description = Adds a mob api for mods to add animals or monsters etc.
|
||||
|
39
mount.lua
39
mount.lua
@ -1,17 +1,16 @@
|
||||
-- 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 =
|
||||
math.abs, math.cos, math.floor, math.sin, math.sqrt, math.pi
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- check for minetest 5.x compatibility
|
||||
local is_50 = minetest.get_translator or nil
|
||||
|
||||
--
|
||||
-- Helper functions
|
||||
--
|
||||
|
||||
local node_ok = function(pos, fallback)
|
||||
|
||||
fallback = fallback or mobs.fallback_node
|
||||
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
@ -49,6 +48,7 @@ end
|
||||
|
||||
|
||||
local function get_sign(i)
|
||||
|
||||
i = i or 0
|
||||
|
||||
if i == 0 then
|
||||
@ -60,6 +60,7 @@ end
|
||||
|
||||
|
||||
local function get_velocity(v, yaw, y)
|
||||
|
||||
local x = -sin(yaw) * v
|
||||
local z = cos(yaw) * v
|
||||
|
||||
@ -74,6 +75,8 @@ end
|
||||
|
||||
local function force_detach(player)
|
||||
|
||||
if not player then return end
|
||||
|
||||
local attached_to = player:get_attach()
|
||||
|
||||
if not attached_to then
|
||||
@ -88,25 +91,27 @@ local function force_detach(player)
|
||||
end
|
||||
|
||||
player:set_detach()
|
||||
|
||||
local name = player:get_player_name()
|
||||
|
||||
if is_50 then
|
||||
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.player_attached[name] = false
|
||||
player_api.set_animation(player, "stand", 30)
|
||||
else
|
||||
default.player_attached[player:get_player_name()] = false
|
||||
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
default.player_attached[name] = false
|
||||
default.player_set_animation(player, "stand", 30)
|
||||
end
|
||||
player:set_properties({visual_size = {x = 1, y = 1}})
|
||||
|
||||
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
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
force_detach(player)
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
|
||||
local players = minetest.get_connected_players()
|
||||
@ -116,12 +121,12 @@ minetest.register_on_shutdown(function()
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
force_detach(player)
|
||||
return true
|
||||
end)
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
-- Just for correct detaching
|
||||
local function find_free_pos(pos)
|
||||
@ -156,7 +161,6 @@ local function find_free_pos(pos)
|
||||
return pos
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
function mobs.attach(entity, player)
|
||||
|
||||
@ -178,12 +182,13 @@ function mobs.attach(entity, player)
|
||||
|
||||
force_detach(player)
|
||||
|
||||
player:set_attach(entity.object, "", attach_at, entity.player_rotation)
|
||||
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_eye_offset(eye_offset, {x = 0, y = 0, z = 0})
|
||||
|
||||
player:set_properties({
|
||||
@ -196,6 +201,7 @@ function mobs.attach(entity, player)
|
||||
minetest.after(0.2, function()
|
||||
|
||||
if player and player:is_player() then
|
||||
|
||||
if is_50 then
|
||||
player_api.set_animation(player, "sit", 30)
|
||||
else
|
||||
@ -209,6 +215,7 @@ end
|
||||
|
||||
|
||||
function mobs.detach(player)
|
||||
|
||||
force_detach(player)
|
||||
|
||||
minetest.after(0.1, function()
|
||||
@ -279,6 +286,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
||||
entity.object:set_yaw(horz - entity.rotate)
|
||||
|
||||
if can_fly then
|
||||
|
||||
-- fly up
|
||||
if ctrl.jump then
|
||||
|
||||
@ -447,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 velo = entity.object:get_velocity()
|
||||
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
|
||||
|
||||
entity.object:set_velocity({
|
||||
x = dir.x * speed,
|
||||
y = dir.y * speed + 2,
|
||||
|
Loading…
x
Reference in New Issue
Block a user