mirror of
https://github.com/Poikilos/mobs.git
synced 2023-10-03 07:28:50 -07:00
Add sheep
This commit is contained in:
parent
7f14760087
commit
5869d604b5
192
init.lua
192
init.lua
@ -14,6 +14,7 @@ function mobs:register_monster(name, def)
|
||||
damage = def.damage,
|
||||
light_resistant = def.light_resistant,
|
||||
drop = def.drop,
|
||||
drop_count = def.drop_count,
|
||||
|
||||
timer = 0,
|
||||
attack = {player=nil, dist=nil},
|
||||
@ -194,11 +195,130 @@ function mobs:register_monster(name, def)
|
||||
on_punch = function(self, hitter)
|
||||
if self.object:get_hp() <= 0 then
|
||||
if hitter and hitter:is_player() and hitter:get_inventory() then
|
||||
for i=1,math.random(0,3)+2 do
|
||||
for i=1,math.random(0,2)-1+self.drop_count do
|
||||
hitter:get_inventory():add_item("main", ItemStack(self.drop))
|
||||
end
|
||||
else
|
||||
for i=1,math.random(0,3)+2 do
|
||||
for i=1,math.random(0,2)-1+self.drop_count do
|
||||
local obj = minetest.env:add_item(self.object:getpos(), self.drop)
|
||||
if obj then
|
||||
obj:get_luaentity().collect = true
|
||||
local x = math.random(1, 5)
|
||||
if math.random(1,2) == 1 then
|
||||
x = -x
|
||||
end
|
||||
local z = math.random(1, 5)
|
||||
if math.random(1,2) == 1 then
|
||||
z = -z
|
||||
end
|
||||
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
})
|
||||
end
|
||||
|
||||
function mobs:register_animal(name, def)
|
||||
minetest.register_entity(name, {
|
||||
hp_max = def.hp_max,
|
||||
physical = def.physical,
|
||||
collisionbox = def.collisionbox,
|
||||
visual = def.visual,
|
||||
visual_size = def.visual_size,
|
||||
textures = def.textures,
|
||||
makes_footstep_sound = def.makes_footstep_sound,
|
||||
walk_velocity = def.walk_velocity,
|
||||
drop = def.drop,
|
||||
on_rightclick = def.on_rightclick,
|
||||
drop_count = def.drop_count,
|
||||
|
||||
timer = 0,
|
||||
state = "stand",
|
||||
|
||||
|
||||
set_velocity = function(self, v)
|
||||
local yaw = self.object:getyaw()
|
||||
yaw = yaw+(math.pi/2)
|
||||
local x = math.sin(yaw) * -v
|
||||
local z = math.cos(yaw) * v
|
||||
self.object:setvelocity({x=x, y=self.object:getvelocity().y, z=z})
|
||||
end,
|
||||
|
||||
get_velocity = function(self)
|
||||
local v = self.object:getvelocity()
|
||||
return (v.x^2 + v.z^2)^(0.5)
|
||||
end,
|
||||
|
||||
on_step = function(self, dtime)
|
||||
if self.object:getvelocity().y > 0.1 then
|
||||
local yaw = self.object:getyaw()
|
||||
yaw = yaw+(math.pi/2)
|
||||
local x = math.sin(yaw) * -2
|
||||
local z = math.cos(yaw) * 2
|
||||
self.object:setacceleration({x=x, y=-10, z=z})
|
||||
else
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
end
|
||||
|
||||
self.timer = self.timer+dtime
|
||||
if self.timer < 1 then
|
||||
return
|
||||
end
|
||||
self.timer = 0
|
||||
|
||||
if string.find(minetest.env:get_node(self.object:getpos()).name, "default:lava") then
|
||||
self.object:punch(self.object, 1.0, {
|
||||
full_punch_interval=1.0,
|
||||
groupcaps={
|
||||
fleshy={times={[3]=1/2}},
|
||||
}
|
||||
}, nil)
|
||||
end
|
||||
|
||||
if self.state == "stand" then
|
||||
if math.random(1, 2) == 1 then
|
||||
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
|
||||
end
|
||||
if math.random(1, 100) <= 50 then
|
||||
self.set_velocity(self, self.walk_velocity)
|
||||
self.state = "walk"
|
||||
end
|
||||
elseif self.state == "walk" then
|
||||
if math.random(1, 100) <= 30 then
|
||||
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
|
||||
self.set_velocity(self, self.get_velocity(self))
|
||||
end
|
||||
if math.random(1, 100) <= 10 then
|
||||
self.set_velocity(self, 0)
|
||||
self.state = "stand"
|
||||
end
|
||||
if self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then
|
||||
local v = self.object:getvelocity()
|
||||
v.y = 5
|
||||
self.object:setvelocity(v)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
on_activate = function(self, staticdata)
|
||||
self.object:set_armor_groups({fleshy=3})
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
self.state = "stand"
|
||||
self.object:setvelocity({x=0, y=self.object:getvelocity().y, z=0})
|
||||
self.object:setyaw(math.random(1, 360)/180*math.pi)
|
||||
end,
|
||||
|
||||
on_punch = function(self, hitter)
|
||||
if self.object:get_hp() <= 0 then
|
||||
if hitter and hitter:is_player() and hitter:get_inventory() then
|
||||
for i=1,math.random(0,2)-1+self.drop_count do
|
||||
hitter:get_inventory():add_item("main", ItemStack(self.drop))
|
||||
end
|
||||
else
|
||||
for i=1,math.random(0,2)-1+self.drop_count do
|
||||
local obj = minetest.env:add_item(self.object:getpos(), self.drop)
|
||||
if obj then
|
||||
obj:get_luaentity().collect = true
|
||||
@ -233,6 +353,7 @@ mobs:register_monster("mobs:dirt_monster", {
|
||||
run_velocity = 3,
|
||||
damage = 2,
|
||||
drop = "default:dirt",
|
||||
drop_count = 3,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
@ -242,6 +363,9 @@ minetest.register_abm({
|
||||
chance = 5000,
|
||||
action = function(pos, node)
|
||||
pos.y = pos.y+1
|
||||
if not minetest.env:get_node_light(pos) then
|
||||
return
|
||||
end
|
||||
if minetest.env:get_node_light(pos) > 3 then
|
||||
return
|
||||
end
|
||||
@ -269,6 +393,7 @@ mobs:register_monster("mobs:stone_monster", {
|
||||
run_velocity = 2,
|
||||
damage = 3,
|
||||
drop = "default:mossycobble",
|
||||
drop_count = 3,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
@ -308,6 +433,7 @@ mobs:register_monster("mobs:sand_monster", {
|
||||
run_velocity = 4,
|
||||
damage = 1,
|
||||
drop = "default:sand",
|
||||
drop_count = 3,
|
||||
light_resistant = true,
|
||||
})
|
||||
|
||||
@ -328,3 +454,65 @@ minetest.register_abm({
|
||||
minetest.env:add_entity(pos, "mobs:sand_monster")
|
||||
end
|
||||
})
|
||||
|
||||
mobs:register_animal("mobs:sheep", {
|
||||
hp_max = 5,
|
||||
physical = true,
|
||||
collisionbox = {-0.6, -0.625, -0.6, 0.6, 0.625, 0.6},
|
||||
visual = "upright_sprite",
|
||||
visual_size = {x=2, y=1.25},
|
||||
textures = {"mobs_sheep.png", "mobs_sheep.png"},
|
||||
makes_footstep_sound = true,
|
||||
walk_velocity = 1,
|
||||
drop = "mobs:meat_raw",
|
||||
drop_count = 2,
|
||||
|
||||
on_rightclick = function(self, clicker)
|
||||
if self.naked then
|
||||
return
|
||||
end
|
||||
if clicker:get_inventory() then
|
||||
self.naked = true,
|
||||
clicker:get_inventory():add_item("main", ItemStack("wool:white "..math.random(1,3)))
|
||||
self.object:set_properties({
|
||||
textures = {"mobs_sheep_naked.png", "mobs_sheep_naked.png"},
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:dirt_with_grass"},
|
||||
neighbors = {"default:dirt", "default:dirt_with_grass"},
|
||||
interval = 60,
|
||||
chance = 5000,
|
||||
action = function(pos, node)
|
||||
pos.y = pos.y+1
|
||||
if minetest.env:get_node(pos).name ~= "air" then
|
||||
return
|
||||
end
|
||||
pos.y = pos.y+1
|
||||
if minetest.env:get_node(pos).name ~= "air" then
|
||||
return
|
||||
end
|
||||
minetest.env:add_entity(pos, "mobs:sheep")
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craftitem("mobs:meat_raw", {
|
||||
description = "Raw Meat",
|
||||
inventory_image = "mobs_meat_raw.png",
|
||||
})
|
||||
|
||||
minetest.register_craftitem("mobs:meat", {
|
||||
description = "Meat",
|
||||
inventory_image = "mobs_meat.png",
|
||||
on_use = minetest.item_eat(8),
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "mobs:meat",
|
||||
recipe = "mobs:meat_raw",
|
||||
cooktime = 5,
|
||||
})
|
||||
|
BIN
textures/mobs_meat.png
Normal file
BIN
textures/mobs_meat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 411 B |
BIN
textures/mobs_meat_raw.png
Normal file
BIN
textures/mobs_meat_raw.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 426 B |
BIN
textures/mobs_sheep.png
Normal file
BIN
textures/mobs_sheep.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
textures/mobs_sheep_naked.png
Normal file
BIN
textures/mobs_sheep_naked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
textures/mobs_sheep_old.png
Normal file
BIN
textures/mobs_sheep_old.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 909 B |
Loading…
x
Reference in New Issue
Block a user