Skip to content

Commit

Permalink
add 0.4.x compatibility when riding mod
Browse files Browse the repository at this point in the history
  • Loading branch information
tenplus1 committed Mar 1, 2022
1 parent 9f74408 commit 65e369e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions depends.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ lucky_block?
cmi?
toolranks?
pathfinder?
player_api?
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -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.
34 changes: 29 additions & 5 deletions mount.lua
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -87,18 +91,27 @@ local function force_detach(player)
end

player:set_detach()
player_api.player_attached[player:get_player_name()] = false

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_api.set_animation(player, "stand", 30)
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()
Expand All @@ -108,6 +121,7 @@ minetest.register_on_shutdown(function()
end
end)


minetest.register_on_dieplayer(function(player)
force_detach(player)
return true
Expand Down Expand Up @@ -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({
Expand All @@ -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)

Expand Down

0 comments on commit 65e369e

Please sign in to comment.