Compare commits

...

3 Commits

Author SHA1 Message Date
cora 2db1deb706 add basic parrot perching 2022-05-22 14:44:45 +02:00
cora 991cffbaf7 entity cramming: check less often 2022-05-22 14:44:41 +02:00
cora 9a02a0e596 mcl_mobs: add entity_cramming 2022-05-22 14:44:41 +02:00
2 changed files with 96 additions and 13 deletions

View File

@ -2998,6 +2998,47 @@ local function check_item_pickup(self)
end
end
local function damage_mob(self,reason,damage)
if not self.health then return end
damage = floor(damage)
if damage > 0 then
self.health = self.health - damage
effect(pos, 5, "mcl_particles_smoke.png", 1, 2, 2, nil)
if check_for_death(self, reason, {type = reason}) then
return true
end
end
end
local entity_cramming_max = 24
local cramming_damage = 3
local function check_entity_cramming(self)
local p = self.object:get_pos()
local oo = minetest.get_objects_inside_radius(p,1)
local clear = false
if #oo < entity_cramming_max then clear = true end
local ncram = {}
for _,o in pairs(oo) do
local l = o:get_luaentity()
if l and clear then
l.cram = nil
elseif l and l.cram == nil then
table.insert(ncram,l)
elseif not clear and l and l.cram then
damage_mob(l,"cramming",cramming_damage)
end
end
for i,l in ipairs(ncram) do
if i > entity_cramming_max then
l.cram = true
else
l.cram = nil
end
end
end
-- falling and fall damage
-- returns true if mob died
local falling = function(self, pos)
@ -3075,16 +3116,7 @@ local falling = function(self, pos)
if add ~= 0 then
damage = damage + damage * (add/100)
end
damage = floor(damage)
if damage > 0 then
self.health = self.health - damage
effect(pos, 5, "mcl_particles_smoke.png", 1, 2, 2, nil)
if check_for_death(self, "fall", {type = "fall"}) then
return true
end
end
damage_mob(self,"fall",damage)
end
self.old_y = self.object:get_pos().y
@ -3716,7 +3748,7 @@ local mob_step = function(self, dtime)
if (self.state == "attack" and self.env_damage_timer > 1)
or self.state ~= "attack" then
check_entity_cramming(self)
self.env_damage_timer = 0
-- check for environmental damage (water, fire, lava etc.)

View File

@ -8,7 +8,35 @@ local S = minetest.get_translator("mobs_mc")
--###################
--################### PARROT
--###################
local shoulders = {
left = vector.new(-3.25,10.5,0),
right = vector.new(3.25,10.5,0)
}
--find a free shoulder or return nil
local function get_shoulder(player)
local sh = 0
for _,o in pairs(player:get_children()) do
local l = o:get_luaentity()
if l and l.name == "mobs_mc:parrot" then
local _,_,a = l.object:get_attach()
for _,s in pairs(shoulders) do
if a and vector.equals(a,s) then sh = sh + 1 end
end
end
end
if sh == 0 then return shoulders["left"]
elseif sh == 1 then return shoulders["right"] end
end
local function perch(self,player)
if self.tamed and player:get_player_name() == self.owner and not self.object:get_attach() then
local shoulder = get_shoulder(player)
if not shoulder then return true end
self.object:set_attach(player,"",shoulder,vector.new(0,0,0),true)
mobs:set_animation(self, "stand")
end
end
mobs:register_mob("mobs_mc:parrot", {
@ -85,12 +113,35 @@ mobs:register_mob("mobs_mc:parrot", {
-- Feed to tame, but not breed
if mobs:feed_tame(self, clicker, 1, false, true) then return end
if mobs:protect(self, clicker) then return end
if mobs:capture_mob(self, clicker, 0, 50, 80, false, nil) then return end
perch(self,clicker)
end,
do_custom = function(self,dtime)
for _,p in pairs(minetest.get_connected_players()) do
if vector.distance(self.object:get_pos(),p:get_pos()) < 1 then
perch(self,p)
end
for _,o in pairs(p:get_children()) do
local l = o:get_luaentity()
if l and l.name == "mobs_mc:parrot" then
if minetest.get_node(vector.offset(p:get_pos(),0,-1,0)).name == "air" then
o:set_detach()
end
end
end
end
end
})
minetest.register_on_leaveplayer(function(p)
for _,o in pairs(p:get_children()) do
local l = o:get_luaentity()
if l and l.name == "mobs_mc:parrot" then
l.object:set_detach()
end
end
end)
-- Parrots spawn rarely in jungles. TODO: Also check for jungle *biome* <- I'll get to this eventually -j4i
mobs:spawn_specific(
"mobs_mc:parrot",