Ciaran Gultnieks cc29bce137 Lots more wip
2014-12-28 16:11:44 +00:00

127 lines
3.6 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["wolf"] = {
shortdesc = "Wolf",
mesh = "animals_wolf.b3d",
textures = {"animals_wolf_mesh.png"},
collisionbox = {-0.5,0,-0.5, 0.5,1,0.5},
animations = {
stand = { x= 0, y= 60},
walk = { x= 61, y=120},
sleep = { x=121, y=180}
},
hp_max = 10,
dead_drops = {},
sounds = {attack="animals_wolf_attack"},
-- These two are used to deal with model discrepancies, until I
-- can be arsed to fix the models.
yoffset = 0.5,
yawoffset = math.pi / 2,
on_activate = function(ent)
end,
on_act = function(ent)
local pos = ent.object:getpos()
-- See if there's a player nearby to attack...
local objs = minetest.get_objects_inside_radius(pos, 8)
local nearestplayer = nil
local nearestdist = 999
for _,v in ipairs(objs) do
if v:is_player() then
local dist = vector.distance(v:getpos(), pos)
if dist < nearestdist then
nearestplayer = v:get_player_name()
nearestdist = dist
end
end
end
if nearestplayer then
return {"attackplayer", name=nearestplayer}
end
-- Otherwise, wander aimlessly
if math.random() < 0.6 then
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:wolfspawner", {
description = "Wolf Spawner",
drawtype = "normal",
tiles = {"default_cobble.png"},
groups = {choppy=4, oddly_breakable_by_hand=3},
paramtype = "light",
})
minetest.register_abm({
nodenames = {"animals:wolfspawner"},
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 == "wolf" 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, "wolf")
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",
})