From 3a5244c72197e074d38d14e83cd1478b76c68e98 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Tue, 8 Aug 2023 21:19:49 -0300 Subject: [PATCH] improved mcl compatibility --- init.lua | 3 +++ inventory_management.lua | 4 ++-- lib_planes/entities.lua | 1 + lib_planes/utilities.lua | 24 ++++++++++++------------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/init.lua b/init.lua index 9d3271d..93b4fe7 100644 --- a/init.lua +++ b/init.lua @@ -20,6 +20,9 @@ airutils.colors ={ yellow='#ffe400', } +airutils.is_minetest = minetest.get_modpath("player_api") +airutils.is_mcl = minetest.get_modpath("mcl_player") + airutils.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1, ['biofuel:phial_fuel'] = 0.25, ['biofuel:fuel_can'] = 10} diff --git a/inventory_management.lua b/inventory_management.lua index 799906e..a671b31 100644 --- a/inventory_management.lua +++ b/inventory_management.lua @@ -3,7 +3,7 @@ airutils.modname = minetest.get_current_modname() --function to format formspec for mineclone. In case of minetest, just returns an empty string local function get_itemslot_bg(a, b, c, d) - if not minetest.get_modpath("player_api") then + if airutils.is_mcl then return mcl_formspec.get_itemslot_bg(a,b,c,d) end return "" @@ -12,7 +12,7 @@ end local function get_formspec_by_size(self, size) local background = "" local hotbar = "" - local is_minetest_game = minetest.get_modpath("player_api") or false + local is_minetest_game = airutils.is_minetest or false if is_minetest_game then background = background .. default.gui_bg .. default.gui_bg_img .. default.gui_slots hotbar = default.get_hotbar_bg(0,4.85) diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index 20ffd6d..b5bd303 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -654,6 +654,7 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage) -- deal with painting or destroying if itmstck then if airutils.set_param_paint(self, puncher, itmstck, 1) == false then + if not self.driver and toolcaps and toolcaps.damage_groups and toolcaps.groupcaps and toolcaps.groupcaps.choppy and item_name ~= airutils.fuel then --airutils.hurt(self,toolcaps.damage_groups.fleshy - 1) diff --git a/lib_planes/utilities.lua b/lib_planes/utilities.lua index e30cc14..e716988 100644 --- a/lib_planes/utilities.lua +++ b/lib_planes/utilities.lua @@ -56,10 +56,10 @@ function airutils.attach(self, player, instructor_mode) end player:set_eye_offset({x = 0, y = eye_y, z = 2}, {x = 0, y = 1, z = -30}) - if minetest.get_modpath("player_api") then + if airutils.is_minetest then player_api.player_attached[name] = true player_api.set_animation(player, "sit") - elseif minetest.get_modpath("mcl_player") then + elseif airutils.is_mcl then airutils.sit(player) end @@ -90,10 +90,10 @@ function airutils.dettachPlayer(self, player) if player then player:set_detach() player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0}) - if minetest.get_modpath("player_api") then + if airutils.is_minetest then player_api.player_attached[name] = nil player_api.set_animation(player, "stand") - elseif minetest.get_modpath("mcl_player") then + elseif airutils.is_mcl then mcl_player.player_attached[name] = nil mcl_player.player_set_animation(player, "stand") end @@ -124,10 +124,10 @@ local function attach_copilot(self, name, player, eye_y) -- attach the driver player:set_attach(self.co_pilot_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) player:set_eye_offset({x = 0, y = eye_y, z = 2}, {x = 0, y = 3, z = -30}) - if minetest.get_modpath("player_api") then + if airutils.is_minetest then player_api.player_attached[name] = true player_api.set_animation(player, "sit") - elseif minetest.get_modpath("mcl_player") then + elseif airutils.is_mcl then mcl_player.player_attached[name] = true airutils.sit(player) end @@ -186,10 +186,10 @@ function airutils.attach_pax(self, player, is_copilot) player:set_attach(self._passengers_base[i], "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) player:set_eye_offset({x = 0, y = eye_y, z = 0}, {x = 0, y = 3, z = -30}) - if minetest.get_modpath("player_api") then + if airutils.is_minetest then player_api.player_attached[name] = true player_api.set_animation(player, "sit") - elseif minetest.get_modpath("mcl_player") then + elseif airutils.is_mcl then mcl_player.player_attached[name] = true airutils.sit(player) end @@ -231,10 +231,10 @@ function airutils.dettach_pax(self, player) if player then player:set_detach() - if minetest.get_modpath("player_api") then + if airutils.is_minetest then player_api.player_attached[name] = nil player_api.set_animation(player, "stand") - elseif minetest.get_modpath("mcl_player") then + elseif airutils.is_mcl then mcl_player.player_attached[name] = nil mcl_player.player_set_animation(player, "stand") end @@ -914,10 +914,10 @@ local function do_attach(self, player, slot) end player:set_eye_offset({x = 0, y = eye_y, z = 2}, {x = 0, y = 3, z = -30}) - if minetest.get_modpath("player_api") then + if airutils.is_minetest then player_api.player_attached[name] = true player_api.set_animation(player, "sit") - elseif minetest.get_modpath("mcl_player") then + elseif airutils.is_mcl then mcl_player.player_attached[name] = true airutils.sit(player) end