german_shepherd.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. local get_distance = function(a, b)
  2. local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
  3. return (x * x + y * y + z * z)
  4. end
  5. mobs:register_mob('farm_mobs:german_shepherd', {
  6. type = 'animal',
  7. passive = false,
  8. attack_type = 'dogfight',
  9. group_attack = true,
  10. reach = 3,
  11. damage = 10,
  12. damage_max = 20,
  13. damage_chance = 150,
  14. hp_min = 50,
  15. hp_max = 150,
  16. armor = 75,
  17. collisionbox = {-0.3, -0.01, -0.3, 0.3, .7, 0.3},
  18. visual = 'mesh',
  19. visual_size = {x=4,y=4},
  20. rotate = 180,
  21. mesh = 'farm_mobs_german_shepherd.b3d',
  22. textures = {
  23. {'farm_mobs_german_shepherd.png'},
  24. },
  25. makes_footstep_sound = true,
  26. sounds = {
  27. random = 'farm_mobs_dog_bark',
  28. attack = 'farm_mobs_dog_bark',
  29. damage = 'farm_mobs_dog_whine'
  30. },
  31. walk_velocity = 2,
  32. run_velocity = 5,
  33. jump = true,
  34. follow = {'mobs:meat_raw', 'farm_mobs:dog_treat', 'mobs:pork_raw', 'mobs:rabbit_raw'},
  35. drops = {
  36. {name = 'mobs:meat_raw', chance = 1, min = 1, max = 3},
  37. },
  38. water_damage = 0,
  39. lava_damage = 5,
  40. light_damage = 0,
  41. animation = {
  42. speed_normal = 40,
  43. speed_run = 30,
  44. stand_speed = 7,
  45. stand_start = 75,
  46. stand_end = 95,
  47. stand1_start = 100,
  48. stand1_end = 130,
  49. walk_start = 135,
  50. walk_end = 195,
  51. run_start = 135,
  52. run_end = 195,
  53. punch_start = 200,
  54. punch_end = 250,
  55. sit_start = 0,
  56. sit_end = 20,
  57. },
  58. view_range = 7,
  59. fear_height = 2,
  60. on_rightclick = function(self, clicker)
  61. if mobs:protect(self, clicker) then return end
  62. local name = clicker:get_player_name()
  63. local inv = clicker:get_inventory()
  64. local tool = clicker:get_wielded_item()
  65. local item = tool:get_name()
  66. if mobs:feed_tame(self, clicker, 10, false, true) then
  67. self.type = 'npc'
  68. self.owner_loyal = true
  69. self.pathfinding = true
  70. self.owner = name
  71. return
  72. end
  73. if mobs:protect(self, clicker) then return end
  74. if self.owner and self.owner == name then
  75. if self.order == 'follow' then
  76. self.order = 'stand'
  77. minetest.chat_send_player(name, ('Dog holding ground.'))
  78. else
  79. self.order = 'follow'
  80. minetest.chat_send_player(name, ('Dog following you.'))
  81. end
  82. mobs:capture_mob(self, clicker, 20, 0, 100, false, nil)
  83. end
  84. end,
  85. on_spawn = function(self)
  86. local pos = self.object:get_pos()
  87. local objs = minetest.get_objects_inside_radius(pos, 4)
  88. for _, obj in pairs(objs) do
  89. if obj:is_player() then
  90. local owner = obj:get_player_name()
  91. self.type = 'npc'
  92. self.owner_loyal = true
  93. self.pathfinding = true
  94. self.owner = owner
  95. end
  96. end
  97. return true
  98. end,
  99. do_custom = function(self, dtime) --Thanks to IhrFussel for many ideas used in this code block.
  100. local pet_pos = self.object:get_pos()
  101. local owner = minetest.get_player_by_name(self.owner) or false
  102. if owner and self.order == 'follow' then --and self.state == "walk
  103. self.dtime = (self.dtime or 0) + dtime
  104. if self.dtime > 5 then
  105. local distance = get_distance(owner:get_pos(), pet_pos)
  106. if distance > 1000 then --should teleport to player
  107. self.object:set_pos(owner:get_pos())
  108. end
  109. self.dtime = 0
  110. end
  111. end
  112. end,
  113. })
  114. mobs:spawn({
  115. name = 'farm_mobs:german_shepherd',
  116. nodes = {'default:dirt_with_coniferous_litter'},
  117. min_height = -15,
  118. max_height = 300,
  119. interval = 100,
  120. chance = 8000,
  121. active_object_count = 3,
  122. })
  123. minetest.register_craftitem('farm_mobs:dog_treat', {
  124. description = 'Dog Treat',
  125. inventory_image = 'farm_mobs_dog_treat.png'
  126. })
  127. stations.dual_register_recipe('food_prep', {
  128. input = {
  129. ['group:food_flour'] = 3,
  130. ['mobs:egg'] = 3,
  131. ['farming:pumpkin_slice'] = 1,
  132. ['farming:hemp_oil'] = 1,
  133. ['default:apple'] = 1,
  134. ['mobs:honey'] = 1
  135. },
  136. output = 'farm_mobs:dog_treat 6',
  137. })
  138. mobs:register_egg("farm_mobs:german_shepherd", "German Shepherd", "default_grass.png", 1)