1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2025-07-18 00:00:23 +02:00

Compare commits

...

4 Commits

4 changed files with 114 additions and 47 deletions

108
api.lua
View File

@ -8,12 +8,12 @@ local use_cmi = minetest.global_exists("cmi")
mobs = { mobs = {
mod = "redo", mod = "redo",
version = "20210323", version = "20210407",
intllib = S, intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {} invis = minetest.global_exists("invisibility") and invisibility or {}
} }
-- localize math functions -- localize common functions
local pi = math.pi local pi = math.pi
local square = math.sqrt local square = math.sqrt
local sin = math.sin local sin = math.sin
@ -112,7 +112,8 @@ local mob_class = {
light_damage_min = 14, light_damage_min = 14,
light_damage_max = 15, light_damage_max = 15,
water_damage = 0, water_damage = 0,
lava_damage = 0, lava_damage = 4,
fire_damage = 4,
air_damage = 0, air_damage = 0,
suffocation = 2, suffocation = 2,
fall_damage = 1, fall_damage = 1,
@ -164,6 +165,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)
@ -982,7 +984,12 @@ local is_node_dangerous = function(self, nodename)
end end
if self.lava_damage > 0 if self.lava_damage > 0
and minetest.get_item_group(nodename, "igniter") ~= 0 then and minetest.get_item_group(nodename, "lava") ~= 0 then
return true
end
if self.fire_damage > 0
and minetest.get_item_group(nodename, "fire") ~= 0 then
return true return true
end end
@ -1068,9 +1075,8 @@ function mob_class:do_env_damage()
local nodef = minetest.registered_nodes[self.standing_in] local nodef = minetest.registered_nodes[self.standing_in]
-- water -- water
if self.water_damage and nodef.groups.water then if self.water_damage ~= 0
and nodef.groups.water then
if self.water_damage ~= 0 then
self.health = self.health - self.water_damage self.health = self.health - self.water_damage
@ -1080,12 +1086,10 @@ function mob_class:do_env_damage()
pos = pos, node = self.standing_in}) then pos = pos, node = self.standing_in}) then
return true return true
end end
end
-- ignition source (fire or lava) -- lava damage
elseif self.lava_damage and nodef.groups.igniter then elseif self.lava_damage ~= 0
and nodef.groups.lava then
if self.lava_damage ~= 0 then
self.health = self.health - self.lava_damage self.health = self.health - self.lava_damage
@ -1095,10 +1099,23 @@ function mob_class:do_env_damage()
node = self.standing_in, hot = true}) then node = self.standing_in, hot = true}) then
return true return true
end end
-- fire damage
elseif self.fire_damage ~= 0
and nodef.groups.fire then
self.health = self.health - self.fire_damage
effect(pos, 15, "fire_basic_flame.png", 1, 5, 1, 0.2, 15, true)
if self:check_for_death({type = "environment", pos = pos,
node = self.standing_in, hot = true}) then
return true
end end
-- damage_per_second node check -- damage_per_second node check (not fire and lava)
elseif nodef.damage_per_second ~= 0 then elseif nodef.damage_per_second ~= 0
and nodef.groups.lava == 0 and nodef.groups.fire == 0 then
self.health = self.health - nodef.damage_per_second self.health = self.health - nodef.damage_per_second
@ -2772,10 +2789,16 @@ 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 -- did player hit mob and if so is it in protected area
if hitter:is_player() then
local player_name = hitter:get_player_name()
if player_name ~= self.owner
and minetest.is_protected(self.object:get_pos(), player_name) then
minetest.chat_send_player(hitter:get_player_name(), minetest.chat_send_player(hitter:get_player_name(),
S("Mob has been protected!")) S("Mob has been protected!"))
@ -2783,6 +2806,22 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
return true return true
end end
-- 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
local weapon = hitter:get_wielded_item() local weapon = hitter:get_wielded_item()
local weapon_def = weapon:get_definition() or {} local weapon_def = weapon:get_definition() or {}
local punch_interval = 1.4 local punch_interval = 1.4
@ -3149,8 +3188,7 @@ function mob_class:mob_activate(staticdata, def, dtime)
def.textures = {def.textures} def.textures = {def.textures}
end end
self.base_texture = def.textures and self.base_texture = def.textures and def.textures[random(#def.textures)]
def.textures[random(#def.textures)]
self.base_mesh = def.mesh self.base_mesh = def.mesh
self.base_size = self.visual_size self.base_size = self.visual_size
self.base_colbox = self.collisionbox self.base_colbox = self.collisionbox
@ -3557,6 +3595,7 @@ minetest.register_entity(name, setmetatable({
light_damage_max = def.light_damage_max, light_damage_max = def.light_damage_max,
water_damage = def.water_damage, water_damage = def.water_damage,
lava_damage = def.lava_damage, lava_damage = def.lava_damage,
fire_damage = def.fire_damage,
air_damage = def.air_damage, air_damage = def.air_damage,
suffocation = def.suffocation, suffocation = def.suffocation,
fall_damage = def.fall_damage, fall_damage = def.fall_damage,
@ -4460,8 +4499,9 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net,
return false return false
end end
-- cannot pick up if not owner -- cannot pick up if not owner (unless player has protection_bypass priv)
if self.owner ~= name and force_take == false then if not minetest.check_player_privs(name, "protection_bypass")
and self.owner ~= name and force_take == false then
minetest.chat_send_player(name, S("@1 is owner!", self.owner)) minetest.chat_send_player(name, S("@1 is owner!", self.owner))
@ -4562,19 +4602,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 +4624,15 @@ function mobs:protect(self, clicker)
clicker:set_wielded_item(tool) clicker:set_wielded_item(tool)
end end
-- set protection level
if tool_name == "mobs:protector" then
self.protected = true self.protected = true
else
self.protected = 2 ; self.fire_damage = 0
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",
@ -4682,12 +4730,12 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
end end
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
-- if mob has been tamed you can name it with a nametag -- if mob has been tamed you can name it with a nametag
if item:get_name() == "mobs:nametag" if item:get_name() == "mobs:nametag"
and clicker:get_player_name() == self.owner then and (name == self.owner
or minetest.check_player_privs(name, "protection_bypass")) then
local name = clicker:get_player_name()
-- store mob and nametag stack in external variables -- store mob and nametag stack in external variables
mob_obj[name] = self mob_obj[name] = self

View File

@ -66,7 +66,10 @@ functions needed for the mob to work properly which contains the following:
water. water.
'air_damage' holds damage per second inflicted to mob when standing in air. 'air_damage' holds damage per second inflicted to mob when standing in air.
'lava_damage' holds the damage per second inflicted to mobs when standing 'lava_damage' holds the damage per second inflicted to mobs when standing
in lava or fire or an ignition source. in lava.
'fire_damage' holds the damage per second inflicted to mobs when standing
in fire.
'light_damage' holds the damage per second inflicted to mobs when light 'light_damage' holds the damage per second inflicted to mobs when light
level is between the min and max values below level is between the min and max values below
'light_damage_min' minimum light value when mob is affected (default: 14) 'light_damage_min' minimum light value when mob is affected (default: 14)

View File

@ -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"),

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B