From 127dad97a799a619d64e6dd77e741844caeec91e Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Tue, 8 Nov 2016 16:11:00 +0000 Subject: [PATCH] added ability to protect tamed mobs --- api.lua | 35 ++++++++++++++++++++++++++++++++++- api.txt | 8 ++++++++ crafts.lua | 15 +++++++++++++++ textures/mobs_protector.png | Bin 0 -> 164 bytes 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 textures/mobs_protector.png diff --git a/api.lua b/api.lua index 1c27238..bd9e969 100644 --- a/api.lua +++ b/api.lua @@ -1,5 +1,5 @@ --- Mobs Api (31st October 2016) +-- Mobs Api (8th November 2016) mobs = {} mobs.mod = "redo" @@ -1848,6 +1848,14 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) return end +-- is mob protected? +if self.protected +and minetest.is_protected(self.object:getpos(), hitter:get_player_name()) then + minetest.chat_send_player(hitter:get_player_name(), "Mob has been protected!") + return +end + + -- weapon wear local weapon = hitter:get_wielded_item() local punch_interval = 1.4 @@ -2949,6 +2957,31 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, end end +-- protect tamed mob with rune iten +function mobs:protect(self, clicker) + + if self.tamed == false then + minetest.chat_send_player(name, S("Not tamed!")) + return false + end + + local tool = clicker:get_wielded_item() + local name = clicker:get_player_name() + + if tool:get_name() == "mobs:protector" then + + tool:take_item() -- take 1 protection rune + clicker:set_wielded_item(tool) + + self.protected = true + minetest.chat_send_player(name, S("Protected!")) + + return true + end + + return false +end + local mob_obj = {} local mob_sta = {} diff --git a/api.txt b/api.txt index 028b92a..3473b38 100644 --- a/api.txt +++ b/api.txt @@ -240,6 +240,14 @@ This function allows the mob to be fed the item inside self.follow be it apple, 'tame' true or false stating if mob can be tamed so player can pick them up +mobs:protect(self, clicker) + +This function can be used to right-click any tamed mob with mobs:protector item, this will protect the mob from harm inside of a protected area from other players. + + 'self' mob information + 'clicker' player information + + Useful Internal Variables 'self.health' contains current health of mob diff --git a/crafts.lua b/crafts.lua index 15521ef..4d32326 100644 --- a/crafts.lua +++ b/crafts.lua @@ -83,3 +83,18 @@ minetest.register_craft({ {'', 'group:stick', 'default:steel_ingot'}, } }) + +-- protection rune +minetest.register_craftitem("mobs:protector", { + description = S("Mob Protection Rune"), + inventory_image = "mobs_protector.png", +}) + +minetest.register_craft({ + output = "mobs:protector", + recipe = { + {"default:stone", "default:stone", "default:stone"}, + {"default:stone", "default:goldblock", "default:stone"}, + {"default:stone", "default:stone", "default:stone"}, + } +}) diff --git a/textures/mobs_protector.png b/textures/mobs_protector.png new file mode 100644 index 0000000000000000000000000000000000000000..f3937b70e14dee1c2f768ae287713f4a8802d185 GIT binary patch literal 164 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPHV5AX?bO)b$iFwzf;2yJg_e0bff zLjIZ>P>Qi6$S;_|;n|HeAjjF$#W95AdUApTLs~K;NA8j(9BGEymYSM}B)k+9l~u(h z4xi*ak`NYD6x3)qWsXRqQkQ{gSH>;{o|cnMO-)Q5c?=9cFLJ$DmQ+{;G>*a3)z4*} HQ$iB}$7V2G literal 0 HcmV?d00001