mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-12-23 17:20:22 +01:00
add level 2 mob protector
This commit is contained in:
parent
34b06df758
commit
246b2769f7
54
api.lua
54
api.lua
@ -8,7 +8,7 @@ local use_cmi = minetest.global_exists("cmi")
|
|||||||
|
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20210323",
|
version = "20210404",
|
||||||
intllib = S,
|
intllib = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {}
|
invis = minetest.global_exists("invisibility") and invisibility or {}
|
||||||
}
|
}
|
||||||
@ -164,6 +164,7 @@ local mob_class = {
|
|||||||
|
|
||||||
local mob_class_meta = {__index = mob_class}
|
local mob_class_meta = {__index = mob_class}
|
||||||
|
|
||||||
|
|
||||||
-- play sound
|
-- play sound
|
||||||
function mob_class:mob_sound(sound)
|
function mob_class:mob_sound(sound)
|
||||||
|
|
||||||
@ -2772,15 +2773,32 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- is mob protected?
|
-- is mob protected
|
||||||
if self.protected and hitter:is_player()
|
if self.protected then
|
||||||
and minetest.is_protected(self.object:get_pos(),
|
|
||||||
hitter:get_player_name()) then
|
|
||||||
|
|
||||||
minetest.chat_send_player(hitter:get_player_name(),
|
-- did player hit mob and if so is it in protected area
|
||||||
S("Mob has been protected!"))
|
if hitter:is_player() and
|
||||||
|
minetest.is_protected(self.object:get_pos(), hitter:get_player_name() ) then
|
||||||
|
|
||||||
return true
|
minetest.chat_send_player(hitter:get_player_name(),
|
||||||
|
S("Mob has been protected!"))
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
-- if protection is on level 2 then dont let arrows harm mobs
|
||||||
|
elseif self.protected == 2 then
|
||||||
|
|
||||||
|
local ent = hitter and hitter:get_luaentity()
|
||||||
|
|
||||||
|
if ent and ent._is_arrow then
|
||||||
|
|
||||||
|
return true -- arrow entity
|
||||||
|
|
||||||
|
elseif not ent then
|
||||||
|
|
||||||
|
return true -- non entity
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local weapon = hitter:get_wielded_item()
|
local weapon = hitter:get_wielded_item()
|
||||||
@ -4562,19 +4580,21 @@ function mobs:protect(self, clicker)
|
|||||||
|
|
||||||
local name = clicker:get_player_name()
|
local name = clicker:get_player_name()
|
||||||
local tool = clicker:get_wielded_item()
|
local tool = clicker:get_wielded_item()
|
||||||
|
local tool_name = tool:get_name()
|
||||||
|
|
||||||
if tool:get_name() ~= "mobs:protector" then
|
if tool_name ~= "mobs:protector"
|
||||||
|
and tool_name ~= "mobs:protector2" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.tamed == false then
|
if not self.tamed then
|
||||||
minetest.chat_send_player(name, S("Not tamed!"))
|
minetest.chat_send_player(name, S("Not tamed!"))
|
||||||
return true -- false
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.protected == true then
|
if self.protected then
|
||||||
minetest.chat_send_player(name, S("Already protected!"))
|
minetest.chat_send_player(name, S("Already protected!"))
|
||||||
return true -- false
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if not mobs.is_creative(clicker:get_player_name()) then
|
if not mobs.is_creative(clicker:get_player_name()) then
|
||||||
@ -4582,9 +4602,15 @@ function mobs:protect(self, clicker)
|
|||||||
clicker:set_wielded_item(tool)
|
clicker:set_wielded_item(tool)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.protected = true
|
-- set protection level
|
||||||
|
if tool_name == "mobs:protector" then
|
||||||
|
self.protected = true
|
||||||
|
else
|
||||||
|
self.protected = 2
|
||||||
|
end
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
pos.y = pos.y + self.collisionbox[2] + 0.5
|
pos.y = pos.y + self.collisionbox[2] + 0.5
|
||||||
|
|
||||||
effect(self.object:get_pos(), 25, "mobs_protect_particle.png",
|
effect(self.object:get_pos(), 25, "mobs_protect_particle.png",
|
||||||
|
16
crafts.lua
16
crafts.lua
@ -115,6 +115,22 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- level 2 protection rune
|
||||||
|
minetest.register_craftitem("mobs:protector2", {
|
||||||
|
description = S("Mob Protection Rune (Level 2)"),
|
||||||
|
inventory_image = "mobs_protector2.png",
|
||||||
|
groups = {flammable = 2}
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "mobs:protector2",
|
||||||
|
recipe = {
|
||||||
|
{"mobs:protector", "default:mese_crystal", "mobs:protector"},
|
||||||
|
{"default:mese_crystal", "default:diamondblock", "default:mese_crystal"},
|
||||||
|
{"mobs:protector", "default:mese_crystal", "mobs:protector"}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
-- saddle
|
-- saddle
|
||||||
minetest.register_craftitem("mobs:saddle", {
|
minetest.register_craftitem("mobs:saddle", {
|
||||||
description = S("Saddle"),
|
description = S("Saddle"),
|
||||||
|
BIN
textures/mobs_protector2.png
Normal file
BIN
textures/mobs_protector2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 164 B |
Loading…
Reference in New Issue
Block a user