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