1 --License for code WTFPL and otherwise stated in readmes
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
15 elseif string.sub(itemstring
, 1, 6) == "group:" and minetest
.get_item_group(itemstring
, string.sub(itemstring
, 7, -1)) ~= 0 then
30 collisionbox
= {-0.3, -0.01, -0.3, 0.3, 0.84, 0.3},
32 mesh
= "mobs_mc_wolf.b3d",
36 visual_size
= {x
=3, y
=3},
37 makes_footstep_sound
= true,
39 war_cry
= "mobs_wolf_attack",
45 walk_chance
= default_walk_chance
,
51 attack_type
= "dogfight",
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()
62 if tool
:get_name() == mobs_mc
.items
.bone
then
64 if not minetest
.settings
:get_bool("creative_mode") then
66 clicker
:set_wielded_item(tool
)
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")
73 ent
= dog
:get_luaentity()
74 ent
.owner
= clicker
:get_player_name()
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,
86 attacks_monsters
= true,
87 attack_animals
= true,
88 specific_attack
= { "player", "mobs_mc:sheep" },
91 mobs
:register_mob("mobs_mc:wolf", wolf
)
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)"}
124 -- Tamed wolf (aka “dog”)
125 local dog
= table.copy(wolf
)
129 -- Tamed wolf texture + red collar
130 dog
.textures
= get_dog_textures("unicolor_red")
132 -- TODO: Start sitting by default
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
145 elseif item
:get_name() ~= "" and mobs
:capture_mob(self
, clicker
, 0, 2, 80, false, nil) then
147 elseif is_food(item
:get_name()) then
148 -- Feed to increase health
149 local hp
= self
.health
151 -- Use eatable group to determine health boost
152 local eatable
= minetest
.get_item_group(item
, "eatable")
155 elseif item
:get_name() == mobs_mc
.items
.rotten_flesh
then
160 local new_hp
= hp
+ hp_add
161 if new_hp
> self
.hp_max
then
164 if not minetest
.settings
:get_bool("creative_mode") then
166 clicker
:set_wielded_item(item
)
170 elseif minetest
.get_item_group(item
:get_name(), "dye") == 1 then
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
176 local tex
= get_dog_textures(group
)
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
184 clicker
:set_wielded_item(item
)
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
200 self
.walk_chance
= default_walk_chance
203 -- TODO: Add sitting model
211 mobs
:register_mob("mobs_mc:dog", dog
)
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
)
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")