Disable villager trading again
[MineClone/MineClone2.git] / mods / ENTITIES / mobs_mc / wolf.lua
blob056f3437b68aa9dd4fc370c025fa64bab9fc8dea
1 --License for code WTFPL and otherwise stated in readmes
3 -- intllib
4 local MP = minetest.get_modpath(minetest.get_current_modname())
5 local S, NS = dofile(MP.."/intllib.lua")
7 local default_walk_chance = 50
9 local pr = PseudoRandom(os.time()*10)
11 local is_food = function(itemstring)
12 for f=1, #mobs_mc.follow.dog do
13 if itemstring == mobs_mc.follow.dog[f] then
14 return true
15 elseif string.sub(itemstring, 1, 6) == "group:" and minetest.get_item_group(itemstring, string.sub(itemstring, 7, -1)) ~= 0 then
16 return true
17 end
18 end
19 return false
20 end
22 -- Wolf
23 local wolf = {
24 type = "animal",
26 hp_min = 8,
27 hp_max = 8,
28 passive = false,
29 group_attack = true,
30 collisionbox = {-0.3, -0.01, -0.3, 0.3, 0.84, 0.3},
31 visual = "mesh",
32 mesh = "mobs_mc_wolf.b3d",
33 textures = {
34 {"mobs_mc_wolf.png"},
36 visual_size = {x=3, y=3},
37 makes_footstep_sound = true,
38 sounds = {
39 war_cry = "mobs_wolf_attack",
40 distance = 16,
42 pathfinding = 1,
43 floats = 1,
44 view_range = 16,
45 walk_chance = default_walk_chance,
46 walk_velocity = 2,
47 run_velocity = 3,
48 stepheight = 1.1,
49 damage = 4,
50 reach = 2,
51 attack_type = "dogfight",
52 fear_height = 4,
53 water_damage = 0,
54 lava_damage = 4,
55 light_damage = 0,
56 follow = mobs_mc.follow.wolf,
57 on_rightclick = function(self, clicker)
58 -- Try to tame wolf (intentionally does NOT use mobs:feed_tame)
59 local tool = clicker:get_wielded_item()
61 local dog, ent
62 if tool:get_name() == mobs_mc.items.bone then
64 if not minetest.settings:get_bool("creative_mode") then
65 tool:take_item()
66 clicker:set_wielded_item(tool)
67 end
68 -- 1/3 chance of getting tamed
69 if pr:next(1, 3) == 1 then
70 local yaw = self.object:get_yaw()
71 dog = minetest.add_entity(self.object:getpos(), "mobs_mc:dog")
72 dog:set_yaw(yaw)
73 ent = dog:get_luaentity()
74 ent.owner = clicker:get_player_name()
75 self.object:remove()
76 end
77 end
78 end,
79 animation = {
80 speed_normal = 50, speed_run = 100,
81 stand_start = 40, stand_end = 45,
82 walk_start = 0, walk_end = 40,
83 run_start = 0, run_end = 40,
85 jump = true,
86 attacks_monsters = true,
87 attack_animals = true,
88 specific_attack = { "player", "mobs_mc:sheep" },
91 mobs:register_mob("mobs_mc:wolf", wolf)
93 -- Tamed wolf
95 -- Collar colors
96 local colors = {
97 ["unicolor_black"] = "#000000",
98 ["unicolor_blue"] = "#0000BB",
99 ["unicolor_dark_orange"] = "#663300", -- brown
100 ["unicolor_cyan"] = "#01FFD8",
101 ["unicolor_dark_green"] = "#005B00",
102 ["unicolor_grey"] = "#C0C0C0",
103 ["unicolor_darkgrey"] = "#303030",
104 ["unicolor_green"] = "#00FF01",
105 ["unicolor_red_violet"] = "#FF05BB", -- magenta
106 ["unicolor_orange"] = "#FF8401",
107 ["unicolor_light_red"] = "#FF65B5", -- pink
108 ["unicolor_red"] = "#FF0000",
109 ["unicolor_violet"] = "#5000CC",
110 ["unicolor_white"] = "#FFFFFF",
111 ["unicolor_yellow"] = "#FFFF00",
113 ["unicolor_light_blue"] = "#B0B0FF",
116 local get_dog_textures = function(color)
117 if colors[color] then
118 return {"mobs_mc_wolf_tame.png^(mobs_mc_wolf_collar.png^[colorize:"..colors[color]..":192)"}
119 else
120 return nil
124 -- Tamed wolf (aka “dog”)
125 local dog = table.copy(wolf)
126 dog.passive = true
127 dog.hp_min = 20
128 dog.hp_max = 20
129 -- Tamed wolf texture + red collar
130 dog.textures = get_dog_textures("unicolor_red")
131 dog.owner = ""
132 -- TODO: Start sitting by default
133 dog.order = "roam"
134 dog.owner_loyal = true
135 -- Automatically teleport dog to owner
136 dog.do_custom = mobs_mc.make_owner_teleport_function(12)
137 dog.follow = mobs_mc.follow.dog
138 dog.attack_animals = nil
139 dog.specific_attack = nil
140 dog.on_rightclick = function(self, clicker)
141 local item = clicker:get_wielded_item()
143 if mobs:protect(self, clicker) then
144 return
145 elseif item:get_name() ~= "" and mobs:capture_mob(self, clicker, 0, 2, 80, false, nil) then
146 return
147 elseif is_food(item:get_name()) then
148 -- Feed to increase health
149 local hp = self.health
150 local hp_add = 0
151 -- Use eatable group to determine health boost
152 local eatable = minetest.get_item_group(item, "eatable")
153 if eatable > 0 then
154 hp_add = eatable
155 elseif item:get_name() == mobs_mc.items.rotten_flesh then
156 hp_add = 4
157 else
158 hp_add = 4
160 local new_hp = hp + hp_add
161 if new_hp > self.hp_max then
162 new_hp = self.hp_max
164 if not minetest.settings:get_bool("creative_mode") then
165 item:take_item()
166 clicker:set_wielded_item(item)
168 self.health = new_hp
169 return
170 elseif minetest.get_item_group(item:get_name(), "dye") == 1 then
171 -- Dye (if possible)
172 for group, _ in pairs(colors) do
173 -- Check if color is supported
174 if minetest.get_item_group(item:get_name(), group) == 1 then
175 -- Dye collar
176 local tex = get_dog_textures(group)
177 if tex then
178 self.base_texture = tex
179 self.object:set_properties({
180 textures = self.base_texture
182 if not minetest.settings:get_bool("creative_mode") then
183 item:take_item()
184 clicker:set_wielded_item(item)
186 break
190 else
191 -- Toggle sitting order
193 if not self.owner or self.owner == "" then
194 -- Huh? This wolf has no owner? Let's fix this! This should never happen.
195 self.owner = clicker:get_player_name()
198 if not self.order or self.order == "" or self.order == "sit" then
199 self.order = "roam"
200 self.walk_chance = default_walk_chance
201 self.jump = true
202 else
203 -- TODO: Add sitting model
204 self.order = "sit"
205 self.walk_chance = 0
206 self.jump = false
211 mobs:register_mob("mobs_mc:dog", dog)
213 -- Spawn
214 mobs:spawn_specific("mobs_mc:wolf", mobs_mc.spawn.wolf, {"air"}, 0, minetest.LIGHT_MAX+1, 30, 9000, 20, mobs_mc.spawn_height.water+3, mobs_mc.spawn_height.overworld_max)
216 -- Compatibility
217 mobs:alias_mob("mobs:wolf", "mobs_mc:wolf")
218 mobs:alias_mob("mobs:dog", "mobs_mc:dog")
219 mobs:alias_mob("esmobs:wolf", "mobs_mc:wolf")
220 mobs:alias_mob("esmobs:dog", "mobs_mc:dog")
222 mobs:register_egg("mobs_mc:wolf", S("Wolf"), "mobs_mc_spawn_icon_wolf.png", 0)
224 if minetest.settings:get_bool("log_mods") then
225 minetest.log("action", "MC Wolf loaded")