1
0
Fork 0

Compare commits

...

6 Commits

Author SHA1 Message Date
cora 9e4faf1b62 Fix despawning 2022-09-09 23:51:54 +02:00
cora 90419424ae Use api spawn command for natural spawn 2022-09-09 22:41:04 +02:00
cora 831a5c949c Fix spawn command 2022-09-09 22:32:51 +02:00
cora ad4eb2c0d6 Vindicators attack villagers too 2022-09-09 22:31:32 +02:00
cora 64f672c15f Only zombies attack villagers 2022-09-09 22:31:32 +02:00
cora bd6e6b48d9 disable smooth rotation 2022-09-09 22:31:32 +02:00
5 changed files with 44 additions and 11 deletions

View File

@ -311,7 +311,10 @@ end
-- set and return valid yaw -- set and return valid yaw
local set_yaw = function(self, yaw, delay, dtime) local set_yaw = function(self, yaw, delay, dtime)
if true then
self.object:set_yaw(yaw)
return yaw
end
if not yaw or yaw ~= yaw then if not yaw or yaw ~= yaw then
yaw = 0 yaw = 0
end end
@ -1946,7 +1949,7 @@ local monster_attack = function(self)
-- find specific mob to attack, failing that attack player/npc/animal -- find specific mob to attack, failing that attack player/npc/animal
if specific_attack(self.specific_attack, name) if specific_attack(self.specific_attack, name)
and (type == "player" or type == "npc" and (type == "player" or ( type == "npc" and self.attack_npcs )
or (type == "animal" and self.attack_animals == true)) then or (type == "animal" and self.attack_animals == true)) then
p = player:get_pos() p = player:get_pos()
@ -3403,21 +3406,20 @@ end
-- get entity staticdata -- get entity staticdata
local mob_staticdata = function(self) local mob_staticdata = function(self)
--[[
-- remove mob when out of range unless tamed -- remove mob when out of range unless tamed
if remove_far if remove_far
and self.can_despawn and self.can_despawn
and self.remove_ok and self.remove_ok
and ((not self.nametag) or (self.nametag == "")) and ((not self.nametag) or (self.nametag == ""))
and self.lifetimer <= 20 then and self.lifetimer <= 20 then
minetest.log("action", "Mob "..tostring(self.name).." despawns in mob_staticdata at "..minetest.pos_to_string(self.object:get_pos()))
minetest.log("action", "Mob "..name.." despawns in mob_staticdata at "..minetest.pos_to_string(self.object.get_pos(), 1))
mcl_burning.extinguish(self.object) mcl_burning.extinguish(self.object)
self.object:remove() self.object:remove()
return ""-- nil return "remove"-- nil
end end
--]]
self.remove_ok = true self.remove_ok = true
self.attack = nil self.attack = nil
self.following = nil self.following = nil
@ -3453,6 +3455,11 @@ local mob_activate = function(self, staticdata, def, dtime)
return return
end end
if staticdata == "remove" then
mcl_burning.extinguish(self.object)
self.object:remove()
return
end
-- load entity variables -- load entity variables
local tmp = minetest.deserialize(staticdata) local tmp = minetest.deserialize(staticdata)
@ -3620,6 +3627,7 @@ end
-- main mob function -- main mob function
local mob_step = function(self, dtime) local mob_step = function(self, dtime)
self.lifetimer = self.lifetimer - dtime
check_item_pickup(self) check_item_pickup(self)
check_aggro(self,dtime) check_aggro(self,dtime)
if not self.fire_resistant then if not self.fire_resistant then
@ -3833,12 +3841,11 @@ local mob_step = function(self, dtime)
and ((not self.nametag) or (self.nametag == "")) and ((not self.nametag) or (self.nametag == ""))
and self.state ~= "attack" and self.state ~= "attack"
and self.following == nil then and self.following == nil then
self.lifetimer = self.lifetimer - dtime
if self.despawn_immediately or self.lifetimer <= 0 then if self.despawn_immediately or self.lifetimer <= 0 then
minetest.log("action", "Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1)) minetest.log("action", "Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1))
mcl_burning.extinguish(self.object) mcl_burning.extinguish(self.object)
self.object:remove() self.object:remove()
return
elseif self.lifetimer <= 10 then elseif self.lifetimer <= 10 then
if math.random(10) < 4 then if math.random(10) < 4 then
self.despawn_immediately = true self.despawn_immediately = true
@ -4030,6 +4037,7 @@ minetest.register_entity(name, {
dogshoot_count_max = def.dogshoot_count_max or 5, dogshoot_count_max = def.dogshoot_count_max or 5,
dogshoot_count2_max = def.dogshoot_count2_max or (def.dogshoot_count_max or 5), dogshoot_count2_max = def.dogshoot_count2_max or (def.dogshoot_count_max or 5),
attack_animals = def.attack_animals or false, attack_animals = def.attack_animals or false,
attack_npcs = def.attack_npcs or false,
specific_attack = def.specific_attack, specific_attack = def.specific_attack,
runaway_from = def.runaway_from, runaway_from = def.runaway_from,
owner_loyal = def.owner_loyal, owner_loyal = def.owner_loyal,

View File

@ -466,6 +466,15 @@ local function spawn_check(pos,spawn_def)
return false return false
end end
function mcl_mobs.spawn(pos,id)
local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id]
if not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then
return false
end
return minetest.add_entity(pos, def.name)
end
local function spawn_group(p,mob,spawn_on,group_max,group_min) local function spawn_group(p,mob,spawn_on,group_max,group_min)
if not group_min then group_min = 1 end if not group_min then group_min = 1 end
local nn= minetest.find_nodes_in_area_under_air(vector.offset(p,-5,-3,-5),vector.offset(p,5,3,5),spawn_on) local nn= minetest.find_nodes_in_area_under_air(vector.offset(p,-5,-3,-5),vector.offset(p,5,3,5),spawn_on)
@ -481,13 +490,26 @@ local function spawn_group(p,mob,spawn_on,group_max,group_min)
if mob.type_of_spawning == "water" then if mob.type_of_spawning == "water" then
sp = get_water_spawn(sp) sp = get_water_spawn(sp)
end end
o = minetest.add_entity(sp,mob.name) o = mcl_mobs.spawn(sp,mob.name)
if o then dbg_spawn_succ = dbg_spawn_succ + 1 end if o then dbg_spawn_succ = dbg_spawn_succ + 1 end
end end
end end
return o return o
end end
mcl_mobs.spawn_group = spawn_group
minetest.register_chatcommand("spawn_mob",{
privs = { debug = true },
func = function(n,param)
local pos = minetest.get_player_by_name(n):get_pos()
if mcl_mobs.spawn(pos,param) then
return true, param.." spawned at "..minetest.pos_to_string(pos)
end
return false, "Couldn't spawn "..param
end
})
if mobs_spawn then if mobs_spawn then
local perlin_noise local perlin_noise
@ -541,7 +563,7 @@ if mobs_spawn then
object = spawn_group(spawning_position,mob_def,{minetest.get_node(vector.offset(spawning_position,0,-1,0)).name},spawn_in_group,spawn_in_group_min) object = spawn_group(spawning_position,mob_def,{minetest.get_node(vector.offset(spawning_position,0,-1,0)).name},spawn_in_group,spawn_in_group_min)
minetest.log("action", "A group of mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1)) minetest.log("action", "A group of mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1))
else else
object = minetest.add_entity(spawning_position, mob_def.name) object = mcl_mobs.spawn(spawning_position, mob_def.name)
minetest.log("action", "Mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1)) minetest.log("action", "Mob " .. mob_def.name .. " spawns at " .. minetest.pos_to_string(spawning_position, 1))
end end

View File

@ -38,6 +38,7 @@ mcl_mobs:register_mob("mobs_mc:vindicator", {
walk_velocity = 1.2, walk_velocity = 1.2,
run_velocity = 2.4, run_velocity = 2.4,
attack_type = "dogfight", attack_type = "dogfight",
attack_npcs = true,
drops = { drops = {
{name = "mcl_core:emerald", {name = "mcl_core:emerald",
chance = 1, chance = 1,

View File

@ -133,6 +133,7 @@ mcl_mobs:register_mob("mobs_mc:villager_zombie", {
view_range = 16, view_range = 16,
fear_height = 4, fear_height = 4,
harmed_by_heal = true, harmed_by_heal = true,
attack_npcs = true,
}) })
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(

View File

@ -101,6 +101,7 @@ local zombie = {
self.object:set_properties({visual_size = self.visual_size}) self.object:set_properties({visual_size = self.visual_size})
self.base_size = self.visual_size self.base_size = self.visual_size
end, end,
attack_npcs = true,
} }
mcl_mobs:register_mob("mobs_mc:zombie", zombie) mcl_mobs:register_mob("mobs_mc:zombie", zombie)