water_life/animals/coralfish.lua

173 lines
5.4 KiB
Lua
Raw Permalink Normal View History

2020-06-06 18:21:35 +02:00
local random = water_life.random
2020-05-31 18:51:00 +02:00
local function fish_brain(self)
if not mobkit.is_alive(self) then
mobkit.clear_queue_high(self)
water_life.handle_drops(self)
mobkit.hq_die(self)
return
end
2020-06-06 18:21:35 +02:00
if mobkit.timer(self,2) then
local members = water_life.get_herd_members(self,5)
local score = 0
local entity = {}
if #members > 1 then
for i = #members,1,-1 do
entity = members[i]:get_luaentity()
if entity then
if entity.head <= score then
table.remove(members,i)
else
score = entity.head
end
else
table.remove(members,i)
end
end
local hpos = members[1]:get_pos()
2022-07-10 13:54:11 +02:00
if self.head ~= score then self.base = hpos end
2020-06-06 18:21:35 +02:00
end
end
if mobkit.timer(self,2) then
local pos = self.object:get_pos()
local obj = self.object
local prio = mobkit.get_queue_priority(self)
if prio < 50 then
if self.base and vector.distance(self.base,pos) > 3 then
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
water_life.hq_swimto(self,20,0.5,nil,self.base)
else
2022-07-10 13:54:11 +02:00
local coraltable = minetest.find_nodes_in_area({x=pos.x-5, y=pos.y-5, z=pos.z-5},
{x=pos.x+5, y=pos.y+5, z=pos.z+5},water_life.urchinspawn)
2020-06-06 18:21:35 +02:00
if #coraltable > 0 then self.base = coraltable[random(#coraltable)] end
end
end
end
2020-05-31 18:51:00 +02:00
if mobkit.timer(self,1) then
if not self.isinliquid then
mobkit.hurt(self,1)
end
local plyr = mobkit.get_nearby_player(self)
2020-08-22 10:11:31 +02:00
if plyr and plyr:is_player() and self.wild then
2020-05-31 18:51:00 +02:00
mobkit.animate(self,"fast")
water_life.hq_swimfrom(self,50,plyr,1)
end
if self.isinliquid and self.isinliquid =="default:river_water_source" then
water_life.hq_swimto(self,30,1,"default:water_source")
end
if mobkit.is_queue_empty_high(self) then
mobkit.animate(self,"def")
mobkit.hq_aqua_roam(self,10,0.5)
end
end
end
minetest.register_entity("water_life:coralfish",{
physical = true,
stepheight = 0.3,
collide_with_objects = false,
collisionbox = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
visual = "mesh",
mesh = "water_life_coralfish.b3d",
textures = {"water_life_coralfish.png","water_life_coralfish2.png","water_life_coralfish3.png"},
2022-07-10 13:54:11 +02:00
visual_size = {x = 0.2, y = 0.2, z = 0.2},
2021-01-27 17:42:51 +01:00
static_save = true,
2022-07-10 14:02:53 +02:00
makes_footstep_sound = false,
2022-07-10 13:54:11 +02:00
on_step = mobkit.stepfunc,
on_activate = mobkit.actfunc,
2020-05-31 18:51:00 +02:00
get_staticdata = mobkit.statfunc,
springiness=0,
2022-07-10 13:54:11 +02:00
buoyancy = 1.0,
2020-05-31 18:51:00 +02:00
max_speed = 2,
jump_height = 0.5,
2020-06-06 18:21:35 +02:00
view_range = 3,
2020-05-31 18:51:00 +02:00
max_hp = 5,
timeout=300,
2020-06-06 18:21:35 +02:00
wild = true,
swarm = {},
base = nil,
head = 65535,
2020-05-31 18:51:00 +02:00
drops = {},
animation = {
2022-07-10 13:54:11 +02:00
def={range={x=1,y=80},speed=40,loop=true},
2020-05-31 18:51:00 +02:00
fast={range={x=81,y=155},speed=80,loop=true},
},
brainfunc = fish_brain,
on_punch=function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if mobkit.is_alive(self) then
2021-01-23 16:35:27 +01:00
if water_life.bloody then water_life.spilltheblood(self.object) end
2020-05-31 18:51:00 +02:00
mobkit.hurt(self,tool_capabilities.damage_groups.fleshy or 1)
end
end,
on_rightclick = function(self, clicker)
if not clicker or not clicker:is_player() then return end
local inv = clicker:get_inventory()
local item = clicker:get_wielded_item()
if not item or item:get_name() ~= "fireflies:bug_net" then return end
if not inv:room_for_item("main", "water_life:coralfish") then return end
inv:add_item("main", "water_life:coralfish")
self.object:remove()
end,
})
minetest.register_entity("water_life:coralfish_tamed",{
physical = true,
stepheight = 0.3,
collide_with_objects = false,
collisionbox = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
visual = "mesh",
mesh = "water_life_coralfish.b3d",
textures = {"water_life_coralfish.png","water_life_coralfish2.png","water_life_coralfish3.png"},
visual_size = {x = 0.2, y = 0.2, z = 0.2},
static_save = true,
2022-07-10 14:02:53 +02:00
makes_footstep_sound = false,
2022-07-10 13:54:11 +02:00
on_step = mobkit.stepfunc,
on_activate = mobkit.actfunc,
2020-05-31 18:51:00 +02:00
get_staticdata = mobkit.statfunc,
springiness=0,
2022-07-10 13:54:11 +02:00
buoyancy = 1.0,
2020-05-31 18:51:00 +02:00
max_speed = 2,
jump_height = 0.5,
view_range = 3,
max_hp = 5,
2021-01-27 17:42:51 +01:00
timeout=0,
2020-06-06 18:21:35 +02:00
wild = false,
swarm = {},
base = nil,
head = 65535,
2020-11-29 17:50:54 +01:00
owner = "",
2020-05-31 18:51:00 +02:00
drops = {},
animation = {
def={range={x=1,y=80},speed=40,loop=true},
fast={range={x=81,y=155},speed=80,loop=true},
},
brainfunc = fish_brain,
on_punch=function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if mobkit.is_alive(self) then
2022-07-10 13:54:11 +02:00
if self.owner and self.owner ~= puncher:get_player_name() and self.owner ~= "" then
return
end
2020-05-31 18:51:00 +02:00
if not puncher or not puncher:is_player() then return end
2022-07-10 13:54:11 +02:00
if water_life.bloody then
water_life.spilltheblood(self.object)
end
2020-05-31 18:51:00 +02:00
mobkit.hurt(self,tool_capabilities.damage_groups.fleshy or 1)
end
end,
on_rightclick = function(self, clicker)
if not clicker or not clicker:is_player() then return end
local inv = clicker:get_inventory()
local item = clicker:get_wielded_item()
2022-07-10 13:54:11 +02:00
if not item or (item:get_name() ~= "fireflies:bug_net" and
item:get_name() ~= water_life.catchNet) then return end
2020-05-31 18:51:00 +02:00
if not inv:room_for_item("main", "water_life:coralfish") then return end
2022-07-10 13:54:11 +02:00
if self.owner and self.owner ~= clicker:get_player_name() and self.owner ~= "" then
return
end
2020-05-31 18:51:00 +02:00
inv:add_item("main", "water_life:coralfish")
self.object:remove()
end,
})