1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-01-12 02:50:25 +01:00

Update mobs mod

From commits of TenpPlus1 :
- Dogfight and explosion tweaks
- Monster/Npc attack closest threat
- Added flying (and swimming) mob routine
- Fixed: flying mobs get stuck outwith fly_in node
- Fixed: dogfight jumping bug
- Fixed: jumping while dogfight attack for all size mobs
- Mobs can now walk up half-slabs without jumping
- Fixed jump glitch + Fixed do_jump
- Added ownership for tamed animals
This commit is contained in:
Quentin BUISSON-DEBON 2015-05-22 10:37:17 +02:00
parent 738d5396df
commit eae9dbfa83
9 changed files with 415 additions and 205 deletions

View File

@ -28,6 +28,8 @@ This mod contains the following additions:
Changelog: Changelog:
1.12- Added animal ownership so that players cannot steal your tamed animals
1.11- Added flying mobs (and swimming), fly=true and fly_in="air" or "deafult:water_source" for fishy
1,10- Footstep removed (use replace), explosion routine added for exploding mobs. 1,10- Footstep removed (use replace), explosion routine added for exploding mobs.
1.09- reworked breeding routine, added mob rotation value, added footstep feature, added jumping mobs with sounds feature, added magic lasso for picking up animals 1.09- reworked breeding routine, added mob rotation value, added footstep feature, added jumping mobs with sounds feature, added magic lasso for picking up animals
1.08- Mob throwing attack has been rehauled so that they can damage one another, also drops and on_die function added 1.08- Mob throwing attack has been rehauled so that they can damage one another, also drops and on_die function added

View File

@ -1,4 +1,4 @@
-- Mobs Api (26th April 2015) -- Mobs Api (20th May 2015)
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
@ -12,8 +12,14 @@ local enable_blood = minetest.setting_getbool("mobs_enable_blood") or true
function mobs:register_mob(name, def) function mobs:register_mob(name, def)
minetest.register_entity(name, { minetest.register_entity(name, {
--weight = 5,
--is_visible = true,
--automatic_rotate = false,
--automatic_face_movement_dir = 0.0, -- set yaw direction in degrees, false to disable
stepheight = def.stepheight or 0.6,
name = name, name = name,
fly = def.fly,
fly_in = def.fly_in or "air",
owner = def.owner, owner = def.owner,
order = def.order or "", order = def.order or "",
on_die = def.on_die, on_die = def.on_die,
@ -37,10 +43,9 @@ lifetimer = def.lifetimer or 600,
water_damage = def.water_damage, water_damage = def.water_damage,
lava_damage = def.lava_damage, lava_damage = def.lava_damage,
fall_damage = def.fall_damage or 1, fall_damage = def.fall_damage or 1,
fall_speed = def.fall_speed or -10, -- must be lower than -2 fall_speed = def.fall_speed or -10, -- must be lower than -2 (default: -10)
drops = def.drops or {}, drops = def.drops or {},
armor = def.armor, armor = def.armor,
--drawtype = def.drawtype,
on_rightclick = def.on_rightclick, on_rightclick = def.on_rightclick,
type = def.type, type = def.type,
attack_type = def.attack_type, attack_type = def.attack_type,
@ -61,7 +66,10 @@ lifetimer = def.lifetimer or 600,
blood_texture = def.blood_texture or "mobs_blood.png", blood_texture = def.blood_texture or "mobs_blood.png",
shoot_offset = def.shoot_offset or 0, shoot_offset = def.shoot_offset or 0,
floats = def.floats or 1, -- floats in water by default floats = def.floats or 1, -- floats in water by default
replacements = def.replacements or {}, replace_rate = def.replace_rate,
replace_what = def.replace_what,
replace_with = def.replace_with,
replace_offset = def.replace_offset or 0,
timer = 0, timer = 0,
env_damage_timer = 0, -- only if state = "attack" env_damage_timer = 0, -- only if state = "attack"
attack = {player=nil, dist=nil}, attack = {player=nil, dist=nil},
@ -72,6 +80,7 @@ lifetimer = def.lifetimer or 600,
hornytimer = 0, hornytimer = 0,
child = false, child = false,
gotten = false, gotten = false,
owner = "",
do_attack = function(self, player, dist) do_attack = function(self, player, dist)
if self.state ~= "attack" then if self.state ~= "attack" then
@ -177,32 +186,21 @@ lifetimer = def.lifetimer or 600,
end end
-- check for mob drop/replace (used for chicken egg and sheep eating grass/wheat) -- check for mob drop/replace (used for chicken egg and sheep eating grass/wheat)
--[[ if self.replace_rate
old fields : and self.child == false
replace_rate = def.replace_rate, and math.random(1,self.replace_rate) == 1 then
replace_what = def.replace_what,
replace_with = def.replace_with,
replace_offset = def.replace_offset or 0,
]]--
for _, fields in pairs(self.replacements) do
if fields.replace_rate
and math.random(1,fields.replace_rate) == 1
and self.child == false then
fields.replace_offset = fields.replace_offset or 0
local pos = self.object:getpos() local pos = self.object:getpos()
pos.y = pos.y + fields.replace_offset pos.y = pos.y + self.replace_offset
if #minetest.find_nodes_in_area(pos,pos,fields.replace_what) > 0 if self.replace_what
and self.object:getvelocity().y == 0 and self.object:getvelocity().y == 0
and fields.replace_what then and #minetest.find_nodes_in_area(pos, pos, self.replace_what) > 0 then
minetest.set_node(pos, {name = fields.replace_with}) --and self.state == "stand" then
end minetest.set_node(pos, {name = self.replace_with})
end end
end end
-- jump direction (adapted from Carbone mobs), gravity, falling or floating in water -- jump direction (adapted from Carbone mobs), gravity, falling or floating in water
if not self.fly then
if self.object:getvelocity().y > 0.1 then if self.object:getvelocity().y > 0.1 then
local yaw = self.object:getyaw() + self.rotate local yaw = self.object:getyaw() + self.rotate
local x = math.sin(yaw) * -2 local x = math.sin(yaw) * -2
@ -230,6 +228,7 @@ lifetimer = def.lifetimer or 600,
end end
self.old_y = self.object:getpos().y self.old_y = self.object:getpos().y
end end
end
-- knockback timer -- knockback timer
if self.pause_timer > 0 then if self.pause_timer > 0 then
@ -262,8 +261,8 @@ lifetimer = def.lifetimer or 600,
if self.light_damage and self.light_damage ~= 0 if self.light_damage and self.light_damage ~= 0
and pos.y > 0 and pos.y > 0
and (minetest.get_node_light(pos) or 0) > 10 -- direct sunlight (was 4) and tod > 0.2 and tod < 0.8
and tod > 0.2 and tod < 0.8 then and (minetest.get_node_light(pos) or 0) > 10 then
self.object:set_hp(self.object:get_hp()-self.light_damage) self.object:set_hp(self.object:get_hp()-self.light_damage)
effect(pos, 5, "tnt_smoke.png") effect(pos, 5, "tnt_smoke.png")
end end
@ -284,14 +283,20 @@ lifetimer = def.lifetimer or 600,
end end
local do_jump = function(self) local do_jump = function(self)
if self.fly then return end
self.jumptimer = (self.jumptimer or 0) + 1
if self.jumptimer < 3 then
local pos = self.object:getpos() local pos = self.object:getpos()
pos.y = pos.y - (-self.collisionbox[2] + self.collisionbox[5]) pos.y = (pos.y + self.collisionbox[2]) - 0.2
local nod = minetest.get_node(pos) local nod = minetest.get_node(pos)
--print ("stand", nod.name, pos.y)
if not nod or not minetest.registered_nodes[nod.name] if not nod or not minetest.registered_nodes[nod.name]
or minetest.registered_nodes[nod.name].walkable == false then return end or minetest.registered_nodes[nod.name].walkable == false then return end
if self.direction then if self.direction then
local nod = minetest.get_node_or_nil({x=pos.x + self.direction.x,y=pos.y+1,z=pos.z + self.direction.z}) pos.y = pos.y + 0.2
local nod = minetest.get_node_or_nil({x=pos.x + self.direction.x,y=pos.y,z=pos.z + self.direction.z})
--print ("front", nod.name, pos.y)
if nod and nod.name and (nod.name ~= "air" or self.walk_chance == 0) then if nod and nod.name and (nod.name ~= "air" or self.walk_chance == 0) then
local def = minetest.registered_items[nod.name] local def = minetest.registered_items[nod.name]
if (def and def.walkable and not nod.name:find("fence")) or self.walk_chance == 0 then if (def and def.walkable and not nod.name:find("fence")) or self.walk_chance == 0 then
@ -306,6 +311,9 @@ lifetimer = def.lifetimer or 600,
end end
end end
end end
else
self.jumptimer = 0
end
end end
-- environmental damage timer -- environmental damage timer
@ -342,12 +350,12 @@ lifetimer = def.lifetimer or 600,
end end
if type == "player" or type == "npc" then if type == "player" or type == "npc" then
local s = self.object:getpos() s = self.object:getpos()
local p = player:getpos() p = player:getpos()
local sp = s sp = s
p.y = p.y + 1 p.y = p.y + 1
sp.y = sp.y + 1 -- aim higher to make looking up hills more realistic sp.y = sp.y + 1 -- aim higher to make looking up hills more realistic
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist < self.view_range then -- and self.in_fov(self,p) then if dist < self.view_range then -- and self.in_fov(self,p) then
-- choose closest player to attack -- choose closest player to attack
if minetest.line_of_sight(sp,p,2) == true if minetest.line_of_sight(sp,p,2) == true
@ -500,7 +508,7 @@ lifetimer = def.lifetimer or 600,
-- anyone but standing npc's can move along -- anyone but standing npc's can move along
if dist > 2 and self.order ~= "stand" then if dist > 2 and self.order ~= "stand" then
if (self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0) if (self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0)
or (self.object:getvelocity().y == 0 and self.jump_chance > 0) then or (self.object:getvelocity().y == 0 and self.jump_chance > 0) then -- CHANGED from self.jump
self.direction = {x = math.sin(yaw)*-1, y = -20, z = math.cos(yaw)} self.direction = {x = math.sin(yaw)*-1, y = -20, z = math.cos(yaw)}
do_jump(self) do_jump(self)
end end
@ -564,15 +572,14 @@ lifetimer = def.lifetimer or 600,
end end
-- jumping mobs only -- jumping mobs only
if self.jump_chance ~= 0 and math.random(1, 100) <= self.jump_chance then -- if self.jump and math.random(1, 100) <= self.jump_chance then
self.direction = {x=0, y=0, z=0} -- self.direction = {x=0, y=0, z=0}
do_jump(self) -- do_jump(self)
self.set_velocity(self, self.walk_velocity) -- self.set_velocity(self, self.walk_velocity)
end -- end
end end
elseif self.state == "walk" then elseif self.state == "walk" then
local s = self.object:getpos() local s = self.object:getpos()
-- if there is water nearby, try to avoid it -- if there is water nearby, try to avoid it
local lp = minetest.find_node_near(s, 2, {"group:water"}) local lp = minetest.find_node_near(s, 2, {"group:water"})
@ -684,7 +691,6 @@ lifetimer = def.lifetimer or 600,
-- end of exploding mobs -- end of exploding mobs
elseif self.state == "attack" and self.attack_type == "dogfight" then elseif self.state == "attack" and self.attack_type == "dogfight" then
if not self.attack.player or not self.attack.player:getpos() then if not self.attack.player or not self.attack.player:getpos() then
print("stop attacking") print("stop attacking")
self.state = "stand" self.state = "stand"
@ -694,6 +700,32 @@ lifetimer = def.lifetimer or 600,
local s = self.object:getpos() local s = self.object:getpos()
local p = self.attack.player:getpos() local p = self.attack.player:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
-- fly bit modified from BlockMens creatures mod
if self.fly and dist > 2 then
local nod = minetest.get_node_or_nil(s)
local p1 = s
local me_y = math.floor(p1.y)
local p2 = p
local p_y = math.floor(p2.y+1)
if nod and nod.name == self.fly_in then
if me_y < p_y then
self.object:setvelocity({x=self.object:getvelocity().x,y=1*self.walk_velocity,z=self.object:getvelocity().z})
elseif me_y > p_y then
self.object:setvelocity({x=self.object:getvelocity().x,y=-1*self.walk_velocity,z=self.object:getvelocity().z})
end
else
if me_y < p_y then
self.object:setvelocity({x=self.object:getvelocity().x,y=0.01,z=self.object:getvelocity().z})
elseif me_y > p_y then
self.object:setvelocity({x=self.object:getvelocity().x,y=-0.01,z=self.object:getvelocity().z})
end
end
end
-- end fly bit
if dist > self.view_range or self.attack.player:get_hp() <= 0 then if dist > self.view_range or self.attack.player:get_hp() <= 0 then
self.state = "stand" self.state = "stand"
self.set_velocity(self, 0) self.set_velocity(self, 0)
@ -711,7 +743,7 @@ lifetimer = def.lifetimer or 600,
end end
self.object:setyaw(yaw) self.object:setyaw(yaw)
-- attack distance is 2 + half of mob width so the bigger mobs can attack (like slimes) -- attack distance is 2 + half of mob width so the bigger mobs can attack (like slimes)
if self.attack.dist > ((-self.collisionbox[1]+self.collisionbox[4])/2)+1.5 then if self.attack.dist > ((-self.collisionbox[1]+self.collisionbox[4])/2)+2 then
-- jump attack -- jump attack
if (self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0) if (self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0)
or (self.object:getvelocity().y == 0 and self.jump_chance > 0) then or (self.object:getvelocity().y == 0 and self.jump_chance > 0) then
@ -803,11 +835,12 @@ lifetimer = def.lifetimer or 600,
on_activate = function(self, staticdata, dtime_s) on_activate = function(self, staticdata, dtime_s)
local pos = self.object:getpos() local pos = self.object:getpos()
self.object:set_hp( math.random(self.hp_min, self.hp_max) ) -- set HP self.object:set_hp( math.random(self.hp_min, self.hp_max) ) -- set HP
self.oldhp = self.object:get_hp(self) self.oldhp = self.object:get_hp(self) -- used for hurt sound
self.object:set_armor_groups({fleshy=self.armor}) self.object:set_armor_groups({fleshy=self.armor})
self.object:setacceleration({x=0, y= self.fall_speed, z=0}) self.object:setacceleration({x=0, y= self.fall_speed, z=0})
self.state = "stand" self.state = "stand"
self.object:setvelocity({x=0, y=self.object:getvelocity().y, z=0}) ; self.old_y = self.object:getpos().y self.object:setvelocity({x=0, y=self.object:getvelocity().y, z=0})
self.old_y = self.object:getpos().y
self.object:setyaw(math.random(1, 360)/180*math.pi) self.object:setyaw(math.random(1, 360)/180*math.pi)
if self.type == "monster" and peaceful_only then if self.type == "monster" and peaceful_only then
self.object:remove() self.object:remove()
@ -846,6 +879,9 @@ lifetimer = def.lifetimer or 600,
if tmp.base_mesh then if tmp.base_mesh then
self.base_mesh = tmp.base_mesh self.base_mesh = tmp.base_mesh
end end
if tmp.owner then
self.owner = tmp.owner
end
end end
end end
-- quick fix for dog so it doesn't revert back to wolf -- quick fix for dog so it doesn't revert back to wolf
@ -895,6 +931,7 @@ lifetimer = def.lifetimer or 600,
visual_size = vis_size, visual_size = vis_size,
base_texture = self.base_texture, base_texture = self.base_texture,
collisionbox = colbox, collisionbox = colbox,
owner = self.owner,
} }
self.object:set_properties(tmp) self.object:set_properties(tmp)
return minetest.serialize(tmp) return minetest.serialize(tmp)
@ -916,7 +953,7 @@ lifetimer = def.lifetimer or 600,
-- https://github.com/BlockMen/pyramids -- https://github.com/BlockMen/pyramids
local kb = self.knock_back local kb = self.knock_back
local r = self.recovery_time local r = self.recovery_time
local ykb = 2 local ykb = 0 -- was 2
local v = self.object:getvelocity() local v = self.object:getvelocity()
if tflp < tool_capabilities.full_punch_interval then if tflp < tool_capabilities.full_punch_interval then
kb = kb * ( tflp / tool_capabilities.full_punch_interval ) kb = kb * ( tflp / tool_capabilities.full_punch_interval )
@ -1107,6 +1144,7 @@ function mobs:explosion(pos, radius, fire, smoke, sound)
end end
end end
end end
end
-- on mob death drop items -- on mob death drop items
function check_for_death(self) function check_for_death(self)
@ -1161,8 +1199,7 @@ function entity_physics(pos, radius)
obj_vel = obj:getvelocity() obj_vel = obj:getvelocity()
dist = math.max(1, vector.distance(pos, obj_pos)) dist = math.max(1, vector.distance(pos, obj_pos))
if obj_vel ~= nil then if obj_vel ~= nil then
obj:setvelocity(calc_velocity(pos, obj_pos, obj:setvelocity(calc_velocity(pos, obj_pos, obj_vel, radius * 10))
obj_vel, radius * 10))
end end
local damage = (4 / dist) * radius local damage = (4 / dist) * radius
obj:set_hp(obj:get_hp() - damage) obj:set_hp(obj:get_hp() - damage)
@ -1245,7 +1282,11 @@ minetest.register_craftitem(mob, {
local pos = pointed_thing.above local pos = pointed_thing.above
if pointed_thing.above and not minetest.is_protected(pos, placer:get_player_name()) then if pointed_thing.above and not minetest.is_protected(pos, placer:get_player_name()) then
pos.y = pos.y + 0.5 pos.y = pos.y + 0.5
minetest.add_entity(pos, mob) local mob = minetest.add_entity(pos, mob)
local ent = mob:get_luaentity()
-- set owner
ent.owner = placer:get_player_name()
ent.tamed = true
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack

View File

@ -7,13 +7,12 @@ mobs:register_mob("mobs:bunny", {
-- is it aggressive -- is it aggressive
passive = true, passive = true,
-- health & armor -- health & armor
hp_min = 3, hp_min = 3, hp_max = 6, armor = 200,
hp_max = 6,
armor = 200,
-- textures and model -- textures and model
collisionbox = {-0.268, -0.5, -0.268, 0.268, 0.167, 0.268}, collisionbox = {-0.268, -0.5, -0.268, 0.268, 0.167, 0.268},
visual = "mesh", visual = "mesh",
mesh = "mobs_bunny.b3d", mesh = "mobs_bunny.b3d",
drawtype = "front",
textures = { textures = {
{"mobs_bunny_grey.png"}, {"mobs_bunny_grey.png"},
{"mobs_bunny_brown.png"}, {"mobs_bunny_brown.png"},
@ -23,9 +22,9 @@ mobs:register_mob("mobs:bunny", {
sounds = {}, sounds = {},
makes_footstep_sound = false, makes_footstep_sound = false,
-- speed and jump -- speed and jump
walk_velocity = 1, walk_velocity = 1, run_velocity = 2,
jump = true, jump = true,
-- drops meat when deat -- drops meat when dead
drops = { drops = {
{name = "mobs:meat_raw", {name = "mobs:meat_raw",
chance = 1, min = 1, max = 2,}, chance = 1, min = 1, max = 2,},
@ -39,6 +38,7 @@ mobs:register_mob("mobs:bunny", {
speed_normal = 15, speed_normal = 15,
stand_start = 1, stand_end = 15, stand_start = 1, stand_end = 15,
walk_start = 16, walk_end = 24, walk_start = 16, walk_end = 24,
punch_start = 16, punch_end = 24,
}, },
-- follows carrot from farming redo -- follows carrot from farming redo
follow = "farming:carrot", follow = "farming:carrot",
@ -50,17 +50,40 @@ mobs:register_mob("mobs:bunny", {
-- right click to pick up rabbit -- right click to pick up rabbit
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
if item:get_name() == "farming_plus:carrot_item" if item:get_name() == "farming_plus:carrot_item"
or item:get_name() == "farming:carrot" then or item:get_name() == "farming:carrot" then
-- take item
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
item:take_item() item:take_item()
clicker:set_wielded_item(item) clicker:set_wielded_item(item)
end end
-- feed and tame
self.food = (self.food or 0) + 1 self.food = (self.food or 0) + 1
if self.food >= 4 then if self.food > 3 then
self.food = 0 self.food = 0
self.tamed = true self.tamed = true
-- make owner
if not self.owner or self.owner == "" then
self.owner = name
end end
end
return
end
-- Monty Python tribute
if item:get_name() == "mobs:lava_orb" then
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
self.object:set_properties({
textures = {"mobs_bunny_evil.png"},
})
self.type = "monster"
self.state = "attack"
self.object:set_hp(20)
return return
end end
@ -68,10 +91,22 @@ mobs:register_mob("mobs:bunny", {
and clicker:get_inventory() and clicker:get_inventory()
and self.child == false and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:bunny") then and clicker:get_inventory():room_for_item("main", "mobs:bunny") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:bunny") clicker:get_inventory():add_item("main", "mobs:bunny")
self.object:remove() self.object:remove()
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not owner
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end end
end, end,
attack_type = "dogfight",
damage = 5,
}) })
mobs:register_spawn("mobs:bunny", {"default:dirt_with_grass"}, 20, 8, 10000, 1, 31000) mobs:register_spawn("mobs:bunny", {"default:dirt_with_grass"}, 20, 8, 10000, 1, 31000)

View File

@ -7,9 +7,7 @@ mobs:register_mob("mobs:chicken", {
-- is it aggressive -- is it aggressive
passive = true, passive = true,
-- health & armor -- health & armor
hp_min = 4, hp_min = 4, hp_max = 8, armor = 200,
hp_max = 8,
armor = 200,
-- textures and model -- textures and model
collisionbox = {-0.3, -0.75, -0.3, 0.3, 0.1, 0.3}, collisionbox = {-0.3, -0.75, -0.3, 0.3, 0.1, 0.3},
visual = "mesh", visual = "mesh",
@ -54,35 +52,43 @@ mobs:register_mob("mobs:chicken", {
}, },
-- follows wheat -- follows wheat
follow = "farming:seed_wheat", follow = "farming:seed_wheat",
view_range = 8, view_range = 5,
-- replace air with egg (lay) replace_rate = 4000,
replacements = {
{
replace_rate = 2000,
replace_what = {"air"}, replace_what = {"air"},
replace_with = "mobs:egg", replace_with = "mobs:egg",
}
},
-- right click to pick up chicken -- right click to pick up chicken
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local tool = clicker:get_wielded_item() local tool = clicker:get_wielded_item()
local name = clicker:get_player_name()
if tool:get_name() == "farming:seed_wheat" then if tool:get_name() == "farming:seed_wheat" then
-- take item
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
tool:take_item(1) tool:take_item(1)
clicker:set_wielded_item(tool) clicker:set_wielded_item(tool)
end end
-- make child grow quicker
if self.child == true then if self.child == true then
self.hornytimer = self.hornytimer + 10 self.hornytimer = self.hornytimer + 10
return return
end end
-- feed and tame
self.food = (self.food or 0) + 1 self.food = (self.food or 0) + 1
if self.food >= 8 then if self.food > 7 then
self.food = 0 self.food = 0
if self.hornytimer == 0 then if self.hornytimer == 0 then
self.horny = true self.horny = true
end end
self.tamed = true self.tamed = true
minetest.sound_play("mobs_chicken", {object = self.object,gain = 1.0,max_hear_distance = 16,loop = false,}) -- make owner
if not self.owner or self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_chicken", {
object = self.object,gain = 1.0,
max_hear_distance = 15,
loop = false,
})
end end
return return
end end
@ -91,8 +97,18 @@ mobs:register_mob("mobs:chicken", {
and clicker:get_inventory() and clicker:get_inventory()
and self.child == false and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:chicken") then and clicker:get_inventory():room_for_item("main", "mobs:chicken") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:chicken") clicker:get_inventory():add_item("main", "mobs:chicken")
self.object:remove() self.object:remove()
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not owner
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end end
end, end,
}) })
@ -145,6 +161,7 @@ description = "Raw Chicken",
on_use = minetest.item_eat(2), on_use = minetest.item_eat(2),
}) })
-- cooked chicken
minetest.register_craftitem("mobs:chicken_cooked", { minetest.register_craftitem("mobs:chicken_cooked", {
description = "Cooked Chicken", description = "Cooked Chicken",
inventory_image = "mobs_chicken_cooked.png", inventory_image = "mobs_chicken_cooked.png",

View File

@ -18,7 +18,7 @@ mobs:register_mob("mobs:cow", {
mesh = "mobs_cow.x", mesh = "mobs_cow.x",
textures = { textures = {
{"mobs_cow.png"}, {"mobs_cow.png"},
--{"mobs_cow_brown.png"}, -- dé-commenter quand "mobs_cow_brown.png" sera compatible --{"mobs_cow_brown.png"}, -- dé-commenter quand "mobs_cow_brown.png" sera compatible
}, },
blood_texture = "mobs_blood.png", blood_texture = "mobs_blood.png",
visual_size = {x=1,y=1}, visual_size = {x=1,y=1},
@ -52,7 +52,7 @@ mobs:register_mob("mobs:cow", {
}, },
-- follows wheat -- follows wheat
follow = "farming:wheat", view_range = 8, follow = "farming:wheat", view_range = 8,
-- replace grass/wheat with air (eat) -- replace grass/wheat with air (eat) -- Modif MFF /DEBUT
replacements = { replacements = {
{ {
replace_rate = 50, replace_rate = 50,
@ -65,10 +65,12 @@ mobs:register_mob("mobs:cow", {
replace_what = {"air"}, replace_what = {"air"},
replace_with = "mobs:dung", replace_with = "mobs:dung",
} }
}, }, -- Modif MFF /FIN
-- right-click cow with empty bucket to get milk, then feed 8 wheat to replenish milk -- right-click cow with empty bucket to get milk, then feed 8 wheat to replenish milk
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local tool = clicker:get_wielded_item() local tool = clicker:get_wielded_item()
local name = clicker:get_player_name()
if tool:get_name() == "bucket:bucket_empty" then if tool:get_name() == "bucket:bucket_empty" then
if self.gotten == true if self.gotten == true
or self.child == true then or self.child == true then
@ -88,23 +90,35 @@ mobs:register_mob("mobs:cow", {
end end
if tool:get_name() == "farming:wheat" then if tool:get_name() == "farming:wheat" then
-- take item
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
tool:take_item(1) tool:take_item(1)
clicker:set_wielded_item(tool) clicker:set_wielded_item(tool)
end end
-- make child grow quicker
if self.child == true then if self.child == true then
self.hornytimer = self.hornytimer + 10 self.hornytimer = self.hornytimer + 10
return return
end end
-- feed and tame
self.food = (self.food or 0) + 1 self.food = (self.food or 0) + 1
if self.food >= 8 then if self.food > 7 then
self.food = 0 self.food = 0
if self.hornytimer == 0 then if self.hornytimer == 0 then
self.horny = true self.horny = true
end end
self.gotten = false -- ready to be milked again self.gotten = false -- ready to be milked again
self.tamed = true self.tamed = true
minetest.sound_play("mobs_cow", {object = self.object,gain = 1.0,max_hear_distance = 32,loop = false,}) -- make owner
if not self.owner or self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_cow", {
object = self.object,
gain = 1.0,
max_hear_distance = 32,
loop = false,
})
end end
return return
end end
@ -114,10 +128,21 @@ mobs:register_mob("mobs:cow", {
and clicker:get_inventory() and clicker:get_inventory()
and self.child == false and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:cow") then and clicker:get_inventory():room_for_item("main", "mobs:cow") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:cow") clicker:get_inventory():add_item("main", "mobs:cow")
self.object:remove() self.object:remove()
tool:add_wear(3000) -- 22 uses tool:add_wear(3000) -- 22 uses
clicker:set_wielded_item(tool) clicker:set_wielded_item(tool)
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not owner
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end end
end, end,
}) })

View File

@ -7,9 +7,7 @@ mobs:register_mob("mobs:kitten", {
-- is it aggressive -- is it aggressive
passive = true, passive = true,
-- health & armor -- health & armor
hp_min = 4, hp_min = 4, hp_max = 8, armor = 200,
hp_max = 8,
armor = 200,
-- textures and model -- textures and model
collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.1, 0.3}, collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.1, 0.3},
visual = "mesh", visual = "mesh",
@ -32,8 +30,6 @@ mobs:register_mob("mobs:kitten", {
jump = false, jump = false,
-- drops string and coins -- drops string and coins
drops = { drops = {
{name = "maptools:copper_coin",
chance = 10, min = 1, max = 1,},
{name = "farming:string", {name = "farming:string",
chance = 2, min = 1, max = 1}, chance = 2, min = 1, max = 1},
}, },
@ -52,17 +48,30 @@ mobs:register_mob("mobs:kitten", {
-- feed with raw fish to tame or right click to pick up -- feed with raw fish to tame or right click to pick up
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
if item:get_name() == "fishing:fish_raw" if item:get_name() == "fishing:fish_raw"
or item:get_name() == "ethereal:fish_raw" then or item:get_name() == "ethereal:fish_raw" then
-- take item
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
item:take_item() item:take_item()
clicker:set_wielded_item(item) clicker:set_wielded_item(item)
end end
-- feed and tame
self.food = (self.food or 0) + 1 self.food = (self.food or 0) + 1
if self.food >= 4 then if self.food > 3 then
self.food = 0 self.food = 0
self.tamed = true self.tamed = true
minetest.sound_play("mobs_kitten", {object = self.object,gain = 1.0,max_hear_distance = 32,loop = false,}) -- make owner
if not self.owner or self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_kitten", {
object = self.object,
gain = 1.0,
max_hear_distance = 10,
loop = false,
})
end end
return return
end end
@ -71,10 +80,20 @@ mobs:register_mob("mobs:kitten", {
and clicker:get_inventory() and clicker:get_inventory()
and self.child == false and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:kitten") then and clicker:get_inventory():room_for_item("main", "mobs:kitten") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:kitten") clicker:get_inventory():add_item("main", "mobs:kitten")
self.object:remove() self.object:remove()
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not owner
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end
end end
end,
}) })
mobs:register_spawn("mobs:kitten", {"default:dirt_with_grass"}, 20, 0, 10000, 1, 31000) mobs:register_spawn("mobs:kitten", {"default:dirt_with_grass"}, 20, 0, 10000, 1, 31000)

View File

@ -17,13 +17,12 @@ mobs:register_mob("mobs:npc", {
attack_type = "dogfight", attack_type = "dogfight",
attacks_monsters = true, attacks_monsters = true,
-- health & armor -- health & armor
hp_min = 20, hp_min = 20, hp_max = 20, armor = 100,
hp_max = 20,
armor = 100,
-- textures and model -- textures and model
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.8,0.35}, collisionbox = {-0.35,-1.0,-0.35, 0.35,0.8,0.35},
visual = "mesh", visual = "mesh",
mesh = "character.b3d", mesh = "character.b3d",
drawtype = "front",
textures = { textures = {
{"mobs_npc.png"}, {"mobs_npc.png"},
}, },
@ -67,12 +66,16 @@ mobs:register_mob("mobs:npc", {
-- right clicking with "cooked meat" or "bread" will give npc more health -- right clicking with "cooked meat" or "bread" will give npc more health
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
-- heal npc
if item:get_name() == "mobs:meat" if item:get_name() == "mobs:meat"
or item:get_name() == "farming:bread" then or item:get_name() == "farming:bread" then
-- feed and add health
local hp = self.object:get_hp() local hp = self.object:get_hp()
if hp + 4 > self.hp_max then if hp + 4 > self.hp_max then return end
return self.object:set_hp(hp+4)
end -- take item
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
item:take_item() item:take_item()
clicker:set_wielded_item(item) clicker:set_wielded_item(item)
@ -91,12 +94,31 @@ mobs:register_mob("mobs:npc", {
self.diamond_count = (self.diamond_count or 0) + 1 self.diamond_count = (self.diamond_count or 0) + 1
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
item:take_item() item:take_item()
-- pick up npc
elseif item:get_name() == "mobs:magic_lasso"
and clicker:is_player()
and clicker:get_inventory()
and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:npc") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:npc")
self.object:remove()
item:add_wear(3000) -- 22 uses
clicker:set_wielded_item(item) clicker:set_wielded_item(item)
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not tamed
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end end
if self.diamond_count < 4 then return end if self.diamond_count < 4 then return end
if self.owner == "" then else
self.owner = clicker:get_player_name() -- if owner switch between follow and stand
if self.owner and self.owner == clicker:get_player_name() then
self.damages = 4 self.damages = 4
else else
if self.order == "follow" then if self.order == "follow" then
@ -104,6 +126,8 @@ mobs:register_mob("mobs:npc", {
else else
self.order = "follow" self.order = "follow"
end end
else
self.owner = clicker:get_player_name()
end end
end end
end, end,

View File

@ -58,28 +58,42 @@ mobs:register_mob("mobs:sheep", {
-- right click sheep to shear sheep and get wood, feed 8 wheat for wool to grow back -- right click sheep to shear sheep and get wood, feed 8 wheat for wool to grow back
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
if item:get_name() == "farming:wheat" then if item:get_name() == "farming:wheat" then
-- take item
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
item:take_item() item:take_item()
clicker:set_wielded_item(item) clicker:set_wielded_item(item)
end end
-- make child grow quicker
if self.child == true then if self.child == true then
self.hornytimer = self.hornytimer + 10 self.hornytimer = self.hornytimer + 10
return return
end end
-- feed and tame
self.food = (self.food or 0) + 1 self.food = (self.food or 0) + 1
if self.food >= 8 then if self.food > 7 then
self.food = 0 self.food = 0
if self.hornytimer == 0 then if self.hornytimer == 0 then
self.horny = true self.horny = true
end end
self.gotten = false -- can be shaved again self.gotten = false -- can be shaved again
self.tamed = true self.tamed = true
-- make owner
if not self.owner or self.owner == "" then
self.owner = name
end
self.object:set_properties({ self.object:set_properties({
textures = {"mobs_sheep.png"}, textures = {"mobs_sheep.png"},
mesh = "mobs_sheep.x", mesh = "mobs_sheep.x",
}) })
minetest.sound_play("mobs_sheep", {object = self.object,gain = 1.0,max_hear_distance = 32,loop = false,}) minetest.sound_play("mobs_sheep", {
object = self.object,
gain = 1.0,
max_hear_distance = 20,
loop = false,
})
end end
return return
end end
@ -109,11 +123,20 @@ mobs:register_mob("mobs:sheep", {
and clicker:get_inventory() and clicker:get_inventory()
and self.child == false and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:sheep") then and clicker:get_inventory():room_for_item("main", "mobs:sheep") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:sheep") clicker:get_inventory():add_item("main", "mobs:sheep")
self.object:remove() self.object:remove()
item:add_wear(3000) -- 22 uses item:add_wear(3000) -- 22 uses
print ("wear", item:get_wear())
clicker:set_wielded_item(item) clicker:set_wielded_item(item)
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not tamed
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end end
end, end,
}) })
@ -126,7 +149,7 @@ mobs:register_egg("mobs:sheep", "Sheep", "wool_white.png", 1)
minetest.register_tool("mobs:shears", { minetest.register_tool("mobs:shears", {
description = "Steel Shears (right-click sheep to shear)", description = "Steel Shears (right-click sheep to shear)",
inventory_image = "mobs_shears.png", inventory_image = "mobs_shears.png",
tool_capabilities = { tool_capabilities = { -- Modif MFF /DEBUT
full_punch_interval = 1, full_punch_interval = 1,
max_drop_level=1, max_drop_level=1,
groupcaps={ groupcaps={
@ -134,7 +157,7 @@ minetest.register_tool("mobs:shears", {
}, },
damage_groups = {fleshy=0}, damage_groups = {fleshy=0},
} }
}) }) -- Modif MFF /FIN
minetest.register_craft({ minetest.register_craft({
output = 'mobs:shears', output = 'mobs:shears',

View File

@ -53,23 +53,37 @@ mobs:register_mob("mobs:pumba", {
-- can be tamed by feeding 8 wheat (will not attack when tamed) -- can be tamed by feeding 8 wheat (will not attack when tamed)
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
if item:get_name() == "default:apple" then if item:get_name() == "default:apple" then
-- take item
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
item:take_item() item:take_item()
clicker:set_wielded_item(item) clicker:set_wielded_item(item)
end end
-- make child grow quicker
if self.child == true then if self.child == true then
self.hornytimer = self.hornytimer + 10 self.hornytimer = self.hornytimer + 10
return return
end end
-- feed and tame
self.food = (self.food or 0) + 1 self.food = (self.food or 0) + 1
if self.food >= 8 then if self.food > 7 then
self.food = 0 self.food = 0
if self.hornytimer == 0 then if self.hornytimer == 0 then
self.horny = true self.horny = true
end end
self.tamed = true self.tamed = true
minetest.sound_play("mobs_pig", {object = self.object,gain = 1.0, max_hear_distance = 32,loop = false,}) -- make owner
if not self.owner or self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_pig", {
object = self.object,
gain = 1.0,
max_hear_distance = 16,
loop = false,
})
end end
return return
end end
@ -79,10 +93,20 @@ mobs:register_mob("mobs:pumba", {
and clicker:get_inventory() and clicker:get_inventory()
and self.child == false and self.child == false
and clicker:get_inventory():room_for_item("main", "mobs:pumba") then and clicker:get_inventory():room_for_item("main", "mobs:pumba") then
-- pick up if owner
if self.owner == name then
clicker:get_inventory():add_item("main", "mobs:pumba") clicker:get_inventory():add_item("main", "mobs:pumba")
self.object:remove() self.object:remove()
item:add_wear(3000) -- 22 uses item:add_wear(3000) -- 22 uses
clicker:set_wielded_item(item) clicker:set_wielded_item(item)
-- cannot pick up if not tamed
elseif not self.owner or self.owner == "" then
minetest.chat_send_player(name, "Not tamed!")
-- cannot pick up if not tamed
elseif self.owner ~= name then
minetest.chat_send_player(name, "Not owner!")
end
end end
end, end,
}) })