diff --git a/api.lua b/api.lua index a41f910..aecf691 100644 --- a/api.lua +++ b/api.lua @@ -1,14 +1,34 @@ --- Load support for intllib. local MP = minetest.get_modpath(minetest.get_current_modname()) -local S = minetest.get_translator and minetest.get_translator("mobs_redo") or - dofile(MP .. "/intllib.lua") + +-- Check for translation method +local S +if minetest.get_translator ~= nil then + S = minetest.get_translator("mobs") -- 5.x translation function +else + if minetest.get_modpath("intllib") then + dofile(minetest.get_modpath("intllib") .. "/init.lua") + if intllib.make_gettext_pair then + gettext, ngettext = intllib.make_gettext_pair() -- new gettext method + else + gettext = intllib.Getter() -- old text file method + end + S = gettext + else -- boilerplate function + S = function(str, ...) + local args = {...} + return str:gsub("@%d+", function(match) + return args[tonumber(match:sub(2))] + end) + end + end +end -- CMI support check local use_cmi = minetest.global_exists("cmi") mobs = { mod = "redo", - version = "20210920", + version = "20220314", intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {} } @@ -254,9 +274,9 @@ return true end - if str:find("group:") then - - local group = str:split(":")[2] + if str and str:find("group:") then + + local group = str:split(":")[2] or "" if minetest.get_item_group(look_for, group) ~= 0 then return true @@ -765,7 +785,7 @@ end self.infotext = "Health: " .. self.health .. " / " .. self.hp_max - .. "\n" .. "Owner: " .. self.owner + .. (self.owner == "" and "" or "\n" .. "Owner: " .. self.owner) .. text -- set changes @@ -1002,19 +1022,19 @@ -- Returns true is node can deal damage to self -local is_node_dangerous = function(self, nodename) - - if self.water_damage > 0 +function mobs:is_node_dangerous(mob_object, nodename) + + if mob_object.water_damage > 0 and minetest.get_item_group(nodename, "water") ~= 0 then return true end - if self.lava_damage > 0 + if mob_object.lava_damage > 0 and minetest.get_item_group(nodename, "lava") ~= 0 then return true end - if self.fire_damage > 0 + if mob_object.fire_damage > 0 and minetest.get_item_group(nodename, "fire") ~= 0 then return true end @@ -1024,6 +1044,10 @@ end return false +end + +local function is_node_dangerous(mob_object, nodename) + return mobs:is_node_dangerous(mob_object, nodename) end @@ -2108,7 +2132,7 @@ for n = 1, #players do - if get_distance(players[n]:get_pos(), s) < self.view_range + if players[n] and get_distance(players[n]:get_pos(), s) < self.view_range and not is_invisible(self, players[n]:get_player_name()) then self.following = players[n] @@ -4337,7 +4361,7 @@ if def and def.on_rightclick then return def.on_rightclick( - pointed_thing.under, under, placer, itemstack) + pointed_thing.under, under, placer, itemstack, pointed_thing) end if pos @@ -4388,7 +4412,7 @@ if def and def.on_rightclick then return def.on_rightclick( - pointed_thing.under, under, placer, itemstack) + pointed_thing.under, under, placer, itemstack, pointed_thing) end if pos diff --git a/api.txt b/api.txt index 772f76a..99547af 100644 --- a/api.txt +++ b/api.txt @@ -691,6 +691,12 @@ otherwise nil is returned. +mobs:is_node_dangerous(mob_object, nodename) + +This function returns true if the node name given is harmful to the mob (mob_object), +it is mainly used when a mob is near a node it has to avoid. + + External Settings for "minetest.conf" ------------------------------------ diff --git a/depends.txt b/depends.txt index 0c580bd..6297913 100644 --- a/depends.txt +++ b/depends.txt @@ -8,3 +8,4 @@ cmi? toolranks? pathfinder? +player_api? diff --git a/init.lua b/init.lua index 518d50d..4632238 100644 --- a/init.lua +++ b/init.lua @@ -22,4 +22,4 @@ -- Lucky Blocks dofile(path .. "/lucky_block.lua") -minetest.log("action", "[MOD] Mobs Redo loaded") +print("[MOD] Mobs Redo loaded") diff --git a/intllib.lua b/intllib.lua deleted file mode 100644 index adb0f88..0000000 --- a/intllib.lua +++ /dev/null @@ -1,3 +0,0 @@ --- Support for the old multi-load method -dofile(minetest.get_modpath("intllib").."/init.lua") - diff --git a/locale/de_DE.po b/locale/de_DE.po index 210990d..ac406bf 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -11,7 +11,7 @@ "PO-Revision-Date: 2017-07-02 14:27+0200\n" "Last-Translator: Wuzzy \n" "Language-Team: \n" -"Language: de_DE\n" +"Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/locale/mobs.de.tr b/locale/mobs.de.tr new file mode 100644 index 0000000..f11b665 --- /dev/null +++ b/locale/mobs.de.tr @@ -0,0 +1,34 @@ +# textdomain:mobs +#** Peaceful Mode Active - No Monsters Will Spawn= +@1 (Tamed)=@1 (Gezähmt) +@1 at full health (@2)=@1 bei voller Gesundheit (@2) +@1 has been tamed!=@1 wurde gezähmt! +@1 is owner!=@1 ist der Besitzer! +#Active Mob Limit Reached!= +Already protected!=Bereits geschützt! +#Change= +#Command:= +Enter name:=Namen eingeben: +#Enter texture:= +Lasso (right-click animal to put in inventory)=Lasso (Rechtsklick auf Tier, um es zu nehmen) +Leather=Leder +Meat=Fleisch +Missed!=Daneben! +Mob Fence=Kreaturen Zaun +#Mob Fence Top= +Mob Protection Rune=Kreaturschutzrune +#Mob Reset Stick= +#Mob Spawner= +Mob Spawner settings failed!=Kreaturenspawner-Einstellungen gescheitert! +Mob has been protected!=Kreatur wurde geschützt! +Name Tag=Namensschild +Net (right-click animal to put in inventory)=Netz (Rechtsklick auf Tier, um es zu nehmen) +Not tamed!=Nicht gezähmt! +Raw Meat=Rohes Fleisch +Rename=Umbenennen +Saddle=Sattel +Spawner Active (@1)=Spawner aktiv (@1) +Spawner Not Active (enter settings)=Nicht aktiv (Einstellungen eingeben) +Steel Shears (right-click to shear)=Stahlschere (Rechtsklick zum Scheren) +#Syntax: “name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] player_distance[1-20] y_offset[-10 to 10]”= +#lifetimer expired, removed @1= diff --git a/locale/mobs.de_DE.tr b/locale/mobs.de_DE.tr deleted file mode 100644 index f11b665..0000000 --- a/locale/mobs.de_DE.tr +++ /dev/null @@ -1,34 +0,0 @@ -# textdomain:mobs -#** Peaceful Mode Active - No Monsters Will Spawn= -@1 (Tamed)=@1 (Gezähmt) -@1 at full health (@2)=@1 bei voller Gesundheit (@2) -@1 has been tamed!=@1 wurde gezähmt! -@1 is owner!=@1 ist der Besitzer! -#Active Mob Limit Reached!= -Already protected!=Bereits geschützt! -#Change= -#Command:= -Enter name:=Namen eingeben: -#Enter texture:= -Lasso (right-click animal to put in inventory)=Lasso (Rechtsklick auf Tier, um es zu nehmen) -Leather=Leder -Meat=Fleisch -Missed!=Daneben! -Mob Fence=Kreaturen Zaun -#Mob Fence Top= -Mob Protection Rune=Kreaturschutzrune -#Mob Reset Stick= -#Mob Spawner= -Mob Spawner settings failed!=Kreaturenspawner-Einstellungen gescheitert! -Mob has been protected!=Kreatur wurde geschützt! -Name Tag=Namensschild -Net (right-click animal to put in inventory)=Netz (Rechtsklick auf Tier, um es zu nehmen) -Not tamed!=Nicht gezähmt! -Raw Meat=Rohes Fleisch -Rename=Umbenennen -Saddle=Sattel -Spawner Active (@1)=Spawner aktiv (@1) -Spawner Not Active (enter settings)=Nicht aktiv (Einstellungen eingeben) -Steel Shears (right-click to shear)=Stahlschere (Rechtsklick zum Scheren) -#Syntax: “name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] player_distance[1-20] y_offset[-10 to 10]”= -#lifetimer expired, removed @1= 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 eec1ab9..331caa5 100644 --- a/mount.lua +++ b/mount.lua @@ -1,14 +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 ------------------------------------------------------------------------------- -- -- Helper functions -- local node_ok = function(pos, fallback) + fallback = fallback or mobs.fallback_node local node = minetest.get_node_or_nil(pos) @@ -46,6 +48,7 @@ local function get_sign(i) + i = i or 0 if i == 0 then @@ -57,6 +60,7 @@ local function get_velocity(v, yaw, y) + local x = -sin(yaw) * v local z = cos(yaw) * v @@ -70,6 +74,8 @@ local function force_detach(player) + + if not player then return end local attached_to = player:get_attach() @@ -85,19 +91,27 @@ 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 - -------------------------------------------------------------------------------- +end + minetest.register_on_leaveplayer(function(player) force_detach(player) end) + minetest.register_on_shutdown(function() local players = minetest.get_connected_players() @@ -106,13 +120,13 @@ force_detach(players[i]) end end) + minetest.register_on_dieplayer(function(player) force_detach(player) return true end) -------------------------------------------------------------------------------- -- Just for correct detaching local function find_free_pos(pos) @@ -147,7 +161,6 @@ return pos end -------------------------------------------------------------------------------- function mobs.attach(entity, player) @@ -169,8 +182,13 @@ 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({ @@ -183,7 +201,12 @@ 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) @@ -192,6 +215,7 @@ function mobs.detach(player) + force_detach(player) minetest.after(0.1, function() @@ -218,7 +242,7 @@ end local acce_y = 0 - local velo = entity.object:get_velocity() + local velo = entity.object:get_velocity() ; if not velo then return end entity.v = get_v(velo) * get_sign(entity.v) @@ -262,6 +286,7 @@ entity.object:set_yaw(horz - entity.rotate) if can_fly then + -- fly up if ctrl.jump then @@ -427,14 +452,15 @@ -- directional flying routine by D00Med (edited by TenPlus1) function mobs.fly(entity, _, speed, shoots, arrow, moving_anim, stand_anim) - local ctrl = entity.driver:get_player_control() + 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 - -if not ctrl or not velo then return end + local yaw = entity.driver:get_look_horizontal() + 1.57 + + 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,