rabbits standoffishly follow carrots, but may get spooked

This commit is contained in:
Hildigerr Vergaray 2020-04-18 22:39:42 -07:00
parent c08116f42e
commit 229c096223
2 changed files with 54 additions and 3 deletions

View File

@ -21,7 +21,7 @@ Upstream contributions have been included from:
### Animals ###
- [x] Cow (and milk)
- [x] Rabbit
- [x] **Rabbits** are cute little critters that you can pick up. They are tasty when cooked. They like carrots, but are shy and get spooked easy.
- [x] Racoon
- [x] Rat
- [x] Sheep

View File

@ -4,8 +4,10 @@ mobs:register_mob("rabbit", {
hp_max = 12,
armor = {crumbly = 25, cracky = 25, choppy = 90, fleshy = 100},
view_range = 15,
attack_range = 12,
walk_velocity = 4,
run_velocity = 4,
run_velocity = 1,
spawning_nodes = {"default:dirt_with_grass"},
max_spawn_light = 20,
@ -23,6 +25,47 @@ mobs:register_mob("rabbit", {
textures = {"mobs_rabbit.png", "mobs_rabbit.png"},
makes_footstep_sound = false,
follow = function(item)
return item == "mobs:carrot"
end,
attack = function(self, target)
if self.tamed then
self.run_velocity = 2
self.walk_velocity = 2
self.view_range = 10
self.attack_range = 2
self.attack = function(self, target)
if self.timer > 10 and math.random(1, 100) <= 15 then
self.timer = 0
minetest.chat_send_player(
target.player:get_player_name(),
"[Rabbit] Please, may I have another carrot?"
)
end
return false
end
self.timer = 0
return true
elseif self.timer > 1 then
chance = math.random(1, 100)
if chance <= 10 then
self.state = "flee"
self.follow = false
self.run_velocity = self.walk_velocity
self.object:set_yaw(self.object:get_yaw()+(math.pi/4)*math.random(2,5))
self:try_jump()
self.set_velocity(self, self.run_velocity)
self.set_animation(self, "run")
elseif chance <= 45 then
if self.attack_range > 2 then
self.attack_range = self.attack_range-1
end
end
self.timer = 0
end
return false
end,
drops = {
{
@ -34,7 +77,15 @@ mobs:register_mob("rabbit", {
},
on_rightclick = function(self, clicker)
if clicker:is_player() and clicker:get_inventory() then
local item = clicker:get_wielded_item()
if item:get_name() == "mobs:carrot" then
item:take_item()
clicker:set_wielded_item(item)
self.tamed = true
if self.state == "flee" then
self.state = "stand"
end
elseif clicker:is_player() and clicker:get_inventory() then
clicker:get_inventory():add_item("main", "mobs:rabbit")
self.object:remove()
end