From 65e369e5fc8b59f2365294cab56ca54c1372f483 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Tue, 1 Mar 2022 09:04:38 +0000 Subject: [PATCH] add 0.4.x compatibility when riding mod --- depends.txt | 1 + mod.conf | 2 +- mount.lua | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/depends.txt b/depends.txt index 0c580bd..6297913 100644 --- a/depends.txt +++ b/depends.txt @@ -8,3 +8,4 @@ lucky_block? cmi? toolranks? pathfinder? +player_api? diff --git a/mod.conf b/mod.conf index 1760bd4..d1f746c 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = mobs 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. diff --git a/mount.lua b/mount.lua index 35f774a..331caa5 100644 --- a/mount.lua +++ b/mount.lua @@ -1,5 +1,7 @@ -- 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 @@ -73,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 @@ -87,11 +91,19 @@ local function force_detach(player) end 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 @@ -99,6 +111,7 @@ minetest.register_on_leaveplayer(function(player) force_detach(player) end) + minetest.register_on_shutdown(function() local players = minetest.get_connected_players() @@ -108,6 +121,7 @@ minetest.register_on_shutdown(function() end end) + minetest.register_on_dieplayer(function(player) force_detach(player) return true @@ -168,8 +182,13 @@ function mobs.attach(entity, 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_api.player_attached[player:get_player_name()] = true player:set_eye_offset(eye_offset, {x = 0, y = 0, z = 0}) player:set_properties({ @@ -182,7 +201,12 @@ function mobs.attach(entity, player) minetest.after(0.2, function() 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)