animals/species/rat.lua
Ciaran Gultnieks 8f6174e3ae Lots more wip
2014-11-26 18:18:03 +00:00

101 lines
2.9 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.25,0,-0.25, 0.25,0.35,0.25},
hp_max = 7,
dead_drops = {"animals:dead_rat"},
catch_with = "animalmaterials:net",
-- 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, 48)
local count = 0
for k, obj in ipairs(objects) do
if not obj:is_player() then
local ent = obj:get_luaentity()
if ent and 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
})
minetest.register_craftitem("animals:dead_rat", {
description = "Dead rat",
inventory_image = "animals_rat_inv.png",
})
minetest.register_craftitem("animals:cooked_rat", {
description = "Cooked rat",
inventory_image = "animals_cooked_rat.png",
on_use = minetest.item_eat(5),
})
minetest.register_craft({
type = "cooking",
output = "animals:cooked_rat",
recipe = "animals:dead_rat",
})