Merge pull request 'Next mobs-redo batch' (#2480) from mobs-redo-merge into master

Reviewed-on: MineClone2/MineClone2#2480
This commit is contained in:
cora 2022-07-24 10:00:17 +00:00
commit 306c0d99ef
13 changed files with 130 additions and 108 deletions

View File

@ -248,7 +248,7 @@ local set_velocity = function(self, v)
end end
-- halt mob if it has been ordered to stay -- halt mob if it has been ordered to stay
if self.order == "stand" then if self.order == "stand" or self.order == "sit" then
self.object:set_velocity({x = 0, y = 0, z = 0}) self.object:set_velocity({x = 0, y = 0, z = 0})
return return
end end
@ -1907,10 +1907,9 @@ end
-- find someone to attack -- find someone to attack
local monster_attack = function(self) local monster_attack = function(self)
if not damage_enabled if not damage_enabled
or minetest.is_creative_enabled("") or minetest.is_creative_enabled("")
or self.passive or self.passive ~= false
or self.state == "attack" or self.state == "attack"
or day_docile(self) then or day_docile(self) then
return return
@ -2393,9 +2392,13 @@ local do_states = function(self, dtime)
yaw = set_yaw(self, yaw, 8) yaw = set_yaw(self, yaw, 8)
end end
if self.order == "sit" then
set_animation(self, "sit")
set_velocity(self, 0) set_velocity(self, 0)
else
set_animation(self, "stand") set_animation(self, "stand")
set_velocity(self, 0)
end
-- npc's ordered to stand stay standing -- npc's ordered to stand stay standing
if self.type ~= "npc" if self.type ~= "npc"
@ -3596,10 +3599,23 @@ local mob_activate = function(self, staticdata, def, dtime)
end end
end end
local function check_aggro(self,dtime)
if not self._aggro or not self.attack then return end
if not self._check_aggro_timer or self._check_aggro_timer > 5 then
self._check_aggro_timer = 0
if not self.attack:get_pos() or vector.distance(self.attack:get_pos(),self.object:get_pos()) > 128 then
self._aggro = nil
self.attack = nil
self.state = "stand"
end
end
self._check_aggro_timer = self._check_aggro_timer + dtime
end
-- main mob function -- main mob function
local mob_step = function(self, dtime) local mob_step = function(self, dtime)
check_item_pickup(self) check_item_pickup(self)
check_aggro(self,dtime)
if not self.fire_resistant then if not self.fire_resistant then
mcl_burning.tick(self.object, dtime, self) mcl_burning.tick(self.object, dtime, self)
end end
@ -4018,6 +4034,7 @@ minetest.register_entity(name, {
teleport = teleport, teleport = teleport,
do_teleport = def.do_teleport, do_teleport = def.do_teleport,
spawn_class = def.spawn_class, spawn_class = def.spawn_class,
can_spawn = def.can_spawn,
ignores_nametag = def.ignores_nametag or false, ignores_nametag = def.ignores_nametag or false,
rain_damage = def.rain_damage or 0, rain_damage = def.rain_damage or 0,
glow = def.glow, glow = def.glow,
@ -4365,73 +4382,69 @@ function mcl_mobs:feed_tame(self, clicker, feed_count, breed, tame, notake)
if not self.follow then if not self.follow then
return false return false
end end
-- can eat/tame with item in hand -- can eat/tame with item in hand
if self.nofollow or follow_holding(self, clicker) then if self.nofollow or follow_holding(self, clicker) then
local consume_food = false
-- if not in creative then take item -- tame if not still a baby
if not minetest.is_creative_enabled(clicker:get_player_name()) then
local item = clicker:get_wielded_item() if tame and not self.child then
if not self.owner or self.owner == "" then
if not notake then item:take_item() end self.tamed = true
self.owner = clicker:get_player_name()
clicker:set_wielded_item(item) consume_food = true
end
end end
mob_sound(self, "eat", nil, true)
-- increase health -- increase health
self.health = self.health + 4
if self.health >= self.hp_max then if self.health < self.hp_max and not consume_food then
consume_food = true
self.health = self.hp_max self.health = min(self.health + 4, self.hp_max)
if self.htimer < 1 then if self.htimer < 1 then
self.htimer = 5 self.htimer = 5
end end
end
self.object:set_hp(self.health) self.object:set_hp(self.health)
end
update_tag(self)
-- make children grow quicker -- make children grow quicker
if self.child == true then
if not consume_food and self.child == true then
consume_food = true
-- deduct 10% of the time to adulthood -- deduct 10% of the time to adulthood
self.hornytimer = self.hornytimer + ((CHILD_GROW_TIME - self.hornytimer) * 0.1) self.hornytimer = self.hornytimer + ((CHILD_GROW_TIME - self.hornytimer) * 0.1)
return true
end end
-- feed and tame -- breed animals
if breed and not consume_food and self.hornytimer == 0 and not self.horny then
self.food = (self.food or 0) + 1 self.food = (self.food or 0) + 1
consume_food = true
if self.food >= feed_count then if self.food >= feed_count then
self.food = 0 self.food = 0
if breed and self.hornytimer == 0 then
self.horny = true self.horny = true
end end
if tame then
self.tamed = true
if not self.owner or self.owner == "" then
self.owner = clicker:get_player_name()
end
end end
-- make sound when fed so many times update_tag(self)
-- play a sound if the animal used the item and take the item if not in creative
if consume_food then
-- don't consume food if clicker is in creative
if not minetest.is_creative_enabled(clicker:get_player_name()) and not notake then
local item = clicker:get_wielded_item()
item:take_item()
clicker:set_wielded_item(item)
end
-- always play the eat sound if food is used, even in creative
mob_sound(self, "eat", nil, true)
else
-- make sound when the mob doesn't want food
mob_sound(self, "random", true) mob_sound(self, "random", true)
end end
return true return true
end end
return false return false
end end
@ -4481,31 +4494,6 @@ function mcl_mobs:spawn_child(pos, mob_type)
return child return child
end end
-- compatibility function for old entities to new modpack entities
function mcl_mobs:alias_mob(old_name, new_name)
-- spawn egg
minetest.register_alias(old_name, new_name)
-- entity
minetest.register_entity(":" .. old_name, {
physical = false,
on_step = function(self)
if minetest.registered_entities[new_name] then
minetest.add_entity(self.object:get_pos(), new_name)
end
self.object:remove()
end
})
end
local timer = 0 local timer = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
timer = timer + dtime timer = timer + dtime

View File

@ -533,6 +533,9 @@ if mobs_spawn then
return return
end end
end end
if minetest.registered_entities[mob_def.name].can_spawn and not minetest.registered_entities[mob_def.name].can_spawn(pos) then
return
end
--everything is correct, spawn mob --everything is correct, spawn mob
local object local object
if spawn_in_group then if spawn_in_group then

View File

@ -74,7 +74,7 @@ mcl_mobs:register_mob("mobs_mc:chicken", {
fear_height = 4, fear_height = 4,
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
if mcl_mobs:feed_tame(self, clicker, 1, true, true) then return end if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end if mcl_mobs:protect(self, clicker) then return end
if mcl_mobs:capture_mob(self, clicker, 0, 60, 5, false, nil) then return end if mcl_mobs:capture_mob(self, clicker, 0, 60, 5, false, nil) then return end
end, end,

View File

@ -48,7 +48,7 @@ local cow_def = {
run_end = 40, run_end = 40,
}, },
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
if mcl_mobs:feed_tame(self, clicker, 1, true, true) then return end if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end if mcl_mobs:protect(self, clicker) then return end
if self.child then if self.child then
@ -87,7 +87,7 @@ mooshroom_def.spawn_in_group_min = 4
mooshroom_def.spawn_in_group = 8 mooshroom_def.spawn_in_group = 8
mooshroom_def.textures = { {"mobs_mc_mooshroom.png", "mobs_mc_mushroom_red.png"}, {"mobs_mc_mooshroom_brown.png", "mobs_mc_mushroom_brown.png" } } mooshroom_def.textures = { {"mobs_mc_mooshroom.png", "mobs_mc_mushroom_red.png"}, {"mobs_mc_mooshroom_brown.png", "mobs_mc_mushroom_brown.png" } }
mooshroom_def.on_rightclick = function(self, clicker) mooshroom_def.on_rightclick = function(self, clicker)
if mcl_mobs:feed_tame(self, clicker, 1, true, true) then return end if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end if mcl_mobs:protect(self, clicker) then return end
if self.child then if self.child then

View File

@ -257,6 +257,9 @@ mcl_mobs:register_mob("mobs_mc:enderman", {
}, },
animation = select_enderman_animation("normal"), animation = select_enderman_animation("normal"),
_taken_node = "", _taken_node = "",
can_spawn = function(pos)
return #minetest.find_nodes_in_area(vector.offset(pos,0,1,0),vector.offset(pos,0,3,0),{"air"}) > 2
end,
do_custom = function(self, dtime) do_custom = function(self, dtime)
-- PARTICLE BEHAVIOUR HERE. -- PARTICLE BEHAVIOUR HERE.
local enderpos = self.object:get_pos() local enderpos = self.object:get_pos()

View File

@ -65,6 +65,14 @@ mcl_mobs:register_mob("mobs_mc:ghast", {
makes_footstep_sound = false, makes_footstep_sound = false,
instant_death = true, instant_death = true,
fire_resistant = true, fire_resistant = true,
can_spawn = function(pos)
if not minetest.get_item_group(minetest.get_node(pos).name,"solid") then return false end
local p1=vector.offset(pos,-2,1,-2)
local p2=vector.offset(pos,2,5,2)
local nn = minetest.find_nodes_in_area(p1,p2,{"air"})
if #nn< 41 then return false end
return true
end,
do_custom = function(self) do_custom = function(self)
if self.firing == true then if self.firing == true then
self.base_texture = {"mobs_mc_ghast_firing.png"} self.base_texture = {"mobs_mc_ghast_firing.png"}

View File

@ -28,13 +28,17 @@ mcl_mobs:register_mob("mobs_mc:llama", {
description = S("Llama"), description = S("Llama"),
type = "animal", type = "animal",
spawn_class = "passive", spawn_class = "passive",
passive = false,
attack_type = "shoot",
shoot_interval = 5.5,
arrow = "mobs_mc:llamaspit",
shoot_offset = 1, --3.5 *would* be a good value visually but it somehow messes with the projectiles trajectory
spawn_in_group_min = 4, spawn_in_group_min = 4,
spawn_in_group = 6, spawn_in_group = 6,
hp_min = 15, hp_min = 15,
hp_max = 30, hp_max = 30,
xp_min = 1, xp_min = 1,
xp_max = 3, xp_max = 3,
passive = false,
collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.86, 0.45}, collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.86, 0.45},
visual = "mesh", visual = "mesh",
mesh = "mobs_mc_llama.b3d", mesh = "mobs_mc_llama.b3d",
@ -47,7 +51,7 @@ mcl_mobs:register_mob("mobs_mc:llama", {
}, },
visual_size = {x=3, y=3}, visual_size = {x=3, y=3},
makes_footstep_sound = true, makes_footstep_sound = true,
runaway = true, runaway = false,
walk_velocity = 1, walk_velocity = 1,
run_velocity = 4.4, run_velocity = 4.4,
follow_velocity = 4.4, follow_velocity = 4.4,
@ -213,6 +217,30 @@ mcl_mobs:register_mob("mobs_mc:llama", {
}) })
-- spit arrow (weapon)
mcl_mobs:register_arrow("mobs_mc:llamaspit", {
visual = "sprite",
visual_size = {x = 0.10, y = 0.10},
textures = {"mobs_mc_llama_spit.png"},
velocity = 5,
hit_player = function(self, player)
player:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = 1},
}, nil)
end,
hit_mob = function(self, mob)
mob:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = 1},
}, nil)
end,
hit_node = function(self, pos, node)
end
})
--spawn --spawn
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:llama", "mobs_mc:llama",

View File

@ -99,7 +99,7 @@ mcl_mobs:register_mob("mobs_mc:pig", {
local wielditem = clicker:get_wielded_item() local wielditem = clicker:get_wielded_item()
-- Feed pig -- Feed pig
if wielditem:get_name() ~= "mcl_mobitems:carrot_on_a_stick" then if wielditem:get_name() ~= "mcl_mobitems:carrot_on_a_stick" then
if mcl_mobs:feed_tame(self, clicker, 1, true, true) then return end if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
end end
if mcl_mobs:protect(self, clicker) then return end if mcl_mobs:protect(self, clicker) then return end

View File

@ -75,7 +75,7 @@ local rabbit = {
}, },
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
-- Feed, tame protect or capture -- Feed, tame protect or capture
if mcl_mobs:feed_tame(self, clicker, 1, true, true) then return end if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end if mcl_mobs:protect(self, clicker) then return end
if mcl_mobs:capture_mob(self, clicker, 0, 50, 80, false, nil) then return end if mcl_mobs:capture_mob(self, clicker, 0, 50, 80, false, nil) then return end
end, end,

View File

@ -70,6 +70,8 @@ mcl_mobs:register_mob("mobs_mc:sheep", {
color = "unicolor_white", color = "unicolor_white",
makes_footstep_sound = true, makes_footstep_sound = true,
walk_velocity = 1, walk_velocity = 1,
runaway = true,
runaway_from = {"mobs_mc:wolf"},
drops = { drops = {
{name = "mcl_mobitems:mutton", {name = "mcl_mobitems:mutton",
chance = 1, chance = 1,
@ -195,7 +197,7 @@ mcl_mobs:register_mob("mobs_mc:sheep", {
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
if mcl_mobs:feed_tame(self, clicker, 1, true, true) then return end if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end if mcl_mobs:protect(self, clicker) then return end
if item:get_name() == "mcl_tools:shears" and not self.gotten and not self.child then if item:get_name() == "mcl_tools:shears" and not self.gotten and not self.child then

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

View File

@ -65,6 +65,11 @@ local wolf = {
dog:set_yaw(yaw) dog:set_yaw(yaw)
ent = dog:get_luaentity() ent = dog:get_luaentity()
ent.owner = clicker:get_player_name() ent.owner = clicker:get_player_name()
ent.tamed = true
mcl_mobs:set_animation(ent, "sit")
ent.walk_chance = 0
ent.jump = false
ent.health = self.health
-- cornfirm taming -- cornfirm taming
minetest.sound_play("mobs_mc_wolf_bark", {object=dog, max_hear_distance=16}, true) minetest.sound_play("mobs_mc_wolf_bark", {object=dog, max_hear_distance=16}, true)
-- Replace wolf -- Replace wolf
@ -74,9 +79,10 @@ local wolf = {
end, end,
animation = { animation = {
speed_normal = 50, speed_run = 100, speed_normal = 50, speed_run = 100,
stand_start = 40, stand_end = 45, stand_start = 0, stand_end = 40,
walk_start = 0, walk_end = 40, walk_start = 40, walk_end = 80,
run_start = 0, run_end = 40, run_start = 80, run_end = 120,
sit_start = 121, sit_end = 140,
}, },
jump = true, jump = true,
attacks_monsters = true, attacks_monsters = true,
@ -127,7 +133,8 @@ dog.hp_max = 20
dog.textures = get_dog_textures("unicolor_red") dog.textures = get_dog_textures("unicolor_red")
dog.owner = "" dog.owner = ""
-- TODO: Start sitting by default -- TODO: Start sitting by default
dog.order = "roam" dog.order = "sit"
dog.state = "stand"
dog.owner_loyal = true dog.owner_loyal = true
dog.follow_velocity = 3.2 dog.follow_velocity = 3.2
-- Automatically teleport dog to owner -- Automatically teleport dog to owner
@ -150,33 +157,12 @@ end
dog.on_rightclick = function(self, clicker) dog.on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item() local item = clicker:get_wielded_item()
if mcl_mobs:protect(self, clicker) then if mcl_mobs:feed_tame(self, clicker, 1, true, false) then
return
elseif mcl_mobs:protect(self, clicker) then
return return
elseif item:get_name() ~= "" and mcl_mobs:capture_mob(self, clicker, 0, 2, 80, false, nil) then elseif item:get_name() ~= "" and mcl_mobs:capture_mob(self, clicker, 0, 2, 80, false, nil) then
return return
elseif is_food(item:get_name()) then
-- Feed to increase health
local hp = self.health
local hp_add = 0
-- Use eatable group to determine health boost
local eatable = minetest.get_item_group(item, "eatable")
if eatable > 0 then
hp_add = eatable
elseif item:get_name() == "mcl_mobitems:rotten_flesh" then
hp_add = 4
else
hp_add = 4
end
local new_hp = hp + hp_add
if new_hp > self.hp_max then
new_hp = self.hp_max
end
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end
self.health = new_hp
return
elseif minetest.get_item_group(item:get_name(), "dye") == 1 then elseif minetest.get_item_group(item:get_name(), "dye") == 1 then
-- Dye (if possible) -- Dye (if possible)
for group, _ in pairs(colors) do for group, _ in pairs(colors) do
@ -210,14 +196,18 @@ dog.on_rightclick = function(self, clicker)
if not self.order or self.order == "" or self.order == "sit" then if not self.order or self.order == "" or self.order == "sit" then
particle = "mobs_mc_wolf_icon_roam.png" particle = "mobs_mc_wolf_icon_roam.png"
self.order = "roam" self.order = "roam"
self.state = "stand"
self.walk_chance = default_walk_chance self.walk_chance = default_walk_chance
self.jump = true self.jump = true
mcl_mobs:set_animation(self, "stand")
-- TODO: Add sitting model -- TODO: Add sitting model
else else
particle = "mobs_mc_wolf_icon_sit.png" particle = "mobs_mc_wolf_icon_sit.png"
self.order = "sit" self.order = "sit"
self.state = "stand"
self.walk_chance = 0 self.walk_chance = 0
self.jump = false self.jump = false
mcl_mobs:set_animation(self, "sit")
end end
-- Display icon to show current order (sit or roam) -- Display icon to show current order (sit or roam)
minetest.add_particle({ minetest.add_particle({