animals/species/rat.lua
Ciaran Gultnieks 9c9244dabb Further
2014-11-03 22:21:25 +00:00

81 lines
2.3 KiB
Lua

local dbg
if moddebug then dbg=moddebug.dbg("animals") else dbg={v1=function() end,v2=function() end,v3=function() end} end
animals.species["rat"] = {
shortdesc = "Rat",
mesh = "animals_rat.b3d",
textures = {"animals_rat.png"},
collisionbox = {-0.35,0,-0.35, 0.35,0.35,0.35},
-- These two are used to deal with model discrepancies, until I
-- can be arsed to fix the models.
yoffset = 0.1,
yawoffset = math.pi / 2,
on_activate = function(ent)
end,
on_act = function(ent)
if math.random() < 0.6 then
local pos = ent.object:getpos()
local dist = math.random() * 5 + 5
local dir = math.random() * math.pi * 2
dbg.v3("ent.name decided to move " .. dist .. "m")
move = vector.from_speed_yaw(dist, dir)
pos.x = pos.x + move.x
pos.z = pos.z + move.z
return {"go", pos=pos}
end
return {"wait", time=5}
end,
on_hit = function(ent, playername)
end,
}
minetest.register_node("animals:ratsnest", {
description = "Rat's Nest",
drawtype = "normal",
tiles = {"animals_ratsnest.png"},
groups = {choppy=4, flammable=1, oddly_breakable_by_hand=3},
paramtype = "light",
})
minetest.register_abm({
nodenames = {"animals:ratsnest"},
neighbors = {"default:air"},
interval = 120,
chance = 0.5,
action = function(pos, node, active_object_count, active_object_count_wider)
local objects = minetest.get_objects_inside_radius(pos, 16)
local count = 0
for k, obj in ipairs(objects) do
if not obj:is_player() then
local ent = obj:get_luaentity()
if ent.species == "rat" then
count = count + 1
if count >= 4 then return end
end
end
end
local dirs = {{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=0, y=0, z=1},
{x=0, y=0, z=-1}}
for _, pp in ipairs(dirs) do
local ppos = vector.add(pos, pp)
if minetest.get_node(ppos).name == "air" then
animals.create(ppos, "rat")
return
end
end
end
})