From c41176b807473356c4ffd2ec399a09f20033e7d8 Mon Sep 17 00:00:00 2001 From: general Date: Sat, 30 Mar 2024 01:41:54 -0400 Subject: [PATCH] tweak for mineclone and 5.x, backguard compat 0.4, intlib only for older * backported commit https://codeberg.org/tenplus1/mobs_redo/commit/131c932aa6c7f72eaab4d32bb8a14b8c5a2529f3 that will tweak detection of player api for mt5, mineclone2 and mt 0.4 * backported adapted https://codeberg.org/tenplus1/mobs_redo/commit/5e96602085f2a81f9c455a702de8a98308ab575e --- api.lua | 19 +++++++++++++------ init.lua | 5 ++++- lucky_block.lua | 31 ++++++++++++++----------------- mount.lua | 41 ++++++++++++++++++++++------------------- 4 files changed, 53 insertions(+), 43 deletions(-) diff --git a/api.lua b/api.lua index 7c25dfd..ad6cc9f 100644 --- a/api.lua +++ b/api.lua @@ -1,4 +1,4 @@ -local MP = minetest.get_modpath(minetest.get_current_modname()) +local MP = minetest.get_modpath("mobs") -- Check for translation method local S @@ -21,22 +21,29 @@ else end end end +local FS = function(...) return minetest.formspec_escape(S(...)) end + -- CMI support check local use_cmi = minetest.global_exists("cmi") +-- MineClone2 check +local use_mc2 = minetest.get_modpath("mcl_core") + +-- Global mobs = { mod = "redo", - version = "20230807", - intllib = S, + version = "20230809", + translate = S, intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {}, node_ice = "default:ice", - node_snow = minetest.registered_aliases["mapgen_snow"] or "default:snow" or "mcl_core:snow", - node_dirt = minetest.registered_aliases["mapgen_dirt"] or "default:dirt" or "mcl_core:dirt" + node_snow = minetest.registered_aliases["mapgen_snow"] + or (use_mc2 and "mcl_core:snow") or "default:snow", + node_dirt = minetest.registered_aliases["mapgen_dirt"] + or (use_mc2 and "mcl_core:dirt") or "default:dirt" } mobs.fallback_node = mobs.node_dirt - -- localize common functions local pi = math.pi local square = math.sqrt diff --git a/init.lua b/init.lua index 0205b39..b0a8cf5 100644 --- a/init.lua +++ b/init.lua @@ -21,6 +21,9 @@ dofile(path .. "/crafts.lua") dofile(path .. "/spawner.lua") -- Lucky Blocks -dofile(path .. "/lucky_block.lua") +if minetest.get_modpath("lucky_block") then + dofile(path .. "/lucky_block.lua") +end + print("[MOD] Mobs Redo loaded") diff --git a/lucky_block.lua b/lucky_block.lua index b823e83..dafab3c 100644 --- a/lucky_block.lua +++ b/lucky_block.lua @@ -1,18 +1,15 @@ -if minetest.get_modpath("lucky_block") then - - lucky_block:add_blocks({ - {"dro", {"mobs:meat_raw"}, 5}, - {"dro", {"mobs:meat"}, 5}, - {"dro", {"mobs:nametag"}, 1}, - {"dro", {"mobs:leather"}, 5}, - {"dro", {"default:stick"}, 10}, - {"dro", {"mobs:net"}, 1}, - {"dro", {"mobs:lasso"}, 1}, - {"dro", {"mobs:shears"}, 1}, - {"dro", {"mobs:protector"}, 1}, - {"dro", {"mobs:fence_wood"}, 10}, - {"dro", {"mobs:fence_top"}, 12}, - {"lig"} - }) -end +lucky_block:add_blocks({ + {"dro", {"mobs:meat_raw"}, 5}, + {"dro", {"mobs:meat"}, 5}, + {"dro", {"mobs:nametag"}, 1}, + {"dro", {"mobs:leather"}, 5}, + {"dro", {"default:stick"}, 10}, + {"dro", {"mobs:net"}, 1}, + {"dro", {"mobs:lasso"}, 1}, + {"dro", {"mobs:shears"}, 1}, + {"dro", {"mobs:protector"}, 1}, + {"dro", {"mobs:fence_wood"}, 10}, + {"dro", {"mobs:fence_top"}, 12}, + {"lig"} +}) diff --git a/mount.lua b/mount.lua index 3341f65..a8fda52 100644 --- a/mount.lua +++ b/mount.lua @@ -1,8 +1,10 @@ -- lib_mount by Blert2112 (edited by TenPlus1) ---[[ one of these is needed (for now) to ride mobs, otherwise no riding for you -if not minetest.get_modpath("default") -or not minetest.get_modpath("player_api") then +local is_pa = minetest.get_modpath("player_api") -- 5.x compatibility +local is_mc2 = minetest.get_modpath("mcl_mobs") -- MineClone2 check + +-- one of these is needed to ride mobs, otherwise no riding for you +if not minetest.get_modpath("default") and not is_pa and not is_mc2 then function mobs.attach() end function mobs.detach() end @@ -11,10 +13,6 @@ or not minetest.get_modpath("player_api") then return end -]] - -local is_pa = minetest.get_modpath("player_api") -- 5.x compatibility -local is_mc2 = minetest.get_modpath("mcl_mobs") -- MineClone2 compatibility -- are we a real player ? local function is_player(player) @@ -25,7 +23,7 @@ local function is_player(player) return false end - +-- Localise some functions local abs, cos, floor, sin, sqrt, pi = math.abs, math.cos, math.floor, math.sin, math.sqrt, math.pi @@ -117,15 +115,17 @@ local function force_detach(player) local name = player:get_player_name() - if is_pa then - player_api.player_attached[name] = false - player_api.set_animation(player, "stand", 30) - elseif is_mc2 then + if is_mc2 then mcl_player.player_attached[player:get_player_name()] = false mcl_player.player_set_animation(player, "stand", 30) else + if is_pa 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 end player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) @@ -209,12 +209,14 @@ function mobs.attach(entity, player) force_detach(player) - if is_pa then - player_api.player_attached[player:get_player_name()] = true - elseif is_mc2 then + if is_mc2 then mcl_player.player_attached[player:get_player_name()] = true else + if is_pa then + player_api.player_attached[player:get_player_name()] = true + else default.player_attached[player:get_player_name()] = true + end end player:set_attach(entity.object, "", attach_at, entity.player_rotation) @@ -231,13 +233,14 @@ function mobs.attach(entity, player) if is_player(player) then - if is_pa then - player_api.set_animation(player, "sit", 30) - elseif is_mc2 then + if is_mc2 then mcl_player.player_set_animation(player, "sit_mount" , 30) else + if is_pa then + player_api.set_animation(player, "sit", 30) + else default.player_set_animation(player, "sit", 30) - end + end end end)