sea_urchin.lua

This commit is contained in:
Gundul 2022-07-10 14:26:22 +02:00
parent 14b1483602
commit d6f5e13c05

View File

@ -15,23 +15,19 @@ water_life.urchinspawn = {
"seacoral:seacoralsandskyblue"
}
local function urchin_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
if mobkit.timer(self,30) then
local ground = mobkit.get_stand_pos(self)
local coraltable = minetest.find_nodes_in_area({x=ground.x-2, y=ground.y-2, z=ground.z-2}, {x=ground.x+2, y=ground.y+2, z=ground.z+2}, water_life.urchinspawn)
local coraltable = minetest.find_nodes_in_area({x=ground.x-2, y=ground.y-2, z=ground.z-2},
{x=ground.x+2, y=ground.y+2, z=ground.z+2}, water_life.urchinspawn)
if not coraltable or #coraltable < 1 then mobkit.hurt(self,1) end
end
if mobkit.timer(self,60) then
local obj = mobkit.get_closest_entity(self,"water_life:urchin")
if obj then
@ -50,12 +46,10 @@ local function urchin_brain(self)
end
end
end
if mobkit.timer(self,1) then
local nature = water_life_get_biome_data(mobkit.get_stand_pos(self))
if not self.isinliquid or self.isinliquid ~= "default:water_source" or nature.temp < 20 then mobkit.hurt(self,1) end
if not self.isinliquid or self.isinliquid ~= "default:water_source"
or nature.temp < 20 then mobkit.hurt(self,1) end
local target = mobkit.get_nearby_player(self)
if target and target:is_player() then
local distance = vector.distance(mobkit.get_stand_pos(self),target:get_pos())
@ -63,29 +57,18 @@ local function urchin_brain(self)
target:punch(self.object,1,self.attack)
end
end
if water_life.random(100) < 30 then
if mobkit.get_queue_priority(self) < 99 then
water_life.hq_idle(self,99,water_life.random(30,120))
end
end
if mobkit.is_queue_empty_high(self) then
water_life.hq_snail_move(self,10)
end
end
end
---------------
-- the Entities
---------------
minetest.register_entity("water_life:urchin",{
-- common props
physical = true,
stepheight = 0.5,
collide_with_objects = false,
@ -93,19 +76,17 @@ minetest.register_entity("water_life:urchin",{
visual = "mesh",
mesh = "water_life_urchin.b3d",
textures = {"water_life_urchin.png"},
visual_size = {x = 1, y = 1}, --2.5
visual_size = {x = 1, y = 1},
static_save = true,
makes_footstep_sound = false,
on_step = mobkit.stepfunc, -- required
on_activate = mobkit.actfunc, -- required
on_step = mobkit.stepfunc,
on_activate = mobkit.actfunc,
get_staticdata = mobkit.statfunc,
-- api props
springiness=0,
buoyancy = 1.07, -- portion of hitbox submerged
buoyancy = 1.07,
max_speed = 0.2,
jump_height = 0.5,
view_range = 2,
-- lung_capacity = 0, -- seconds
max_hp = 10,
timeout=180,
wild = true,
@ -114,35 +95,21 @@ minetest.register_entity("water_life:urchin",{
{name = "default:diamond", chance = 20, min = 1, max = 1,},
{name = "water_life:meat_raw", chance = 2, min = 1, max = 1,},
},
--[[
animation = {
def={range={x=1,y=35},speed=40,loop=true}, --35
fast={range={x=1,y=35},speed=80,loop=true},
idle={range={x=36,y=75},speed=20,loop=true},
},
]]
brainfunc = urchin_brain,
on_punch=function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if mobkit.is_alive(self) then
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" and item:get_name() ~= water_life.catchNet) then return end
if not item or (item:get_name() ~= "fireflies:bug_net" and
item:get_name() ~= water_life.catchNet) then return end
if not inv:room_for_item("main", "water_life:urchin_item") then return end
inv:add_item("main", "water_life:urchin_item")
self.object:remove()
end,
})