-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsheep.lua
More file actions
304 lines (259 loc) · 8.01 KB
/
Copy pathsheep.lua
File metadata and controls
304 lines (259 loc) · 8.01 KB
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
local S = mobs.intllib_animal
local random = math.random
local all_colours = {
{ "black", S("Black"), "#000000b0" },
{ "blue", S("Blue"), "#015dbb70" },
{ "brown", S("Brown"), "#663300a0" },
{ "cyan", S("Cyan"), "#01ffd870" },
{ "dark_green", S("Dark Green"), "#005b0770" },
{ "dark_grey", S("Dark Grey"), "#303030b0" },
{ "green", S("Green"), "#61ff0170" },
{ "grey", S("Grey"), "#5b5b5bb0" },
{ "magenta", S("Magenta"), "#ff05bb70" },
{ "orange", S("Orange"), "#ff840170" },
{ "pink", S("Pink"), "#ff65b570" },
{ "red", S("Red"), "#ff0000a0" },
{ "violet", S("Violet"), "#2000c970" },
{ "white", S("White"), "#abababc0" },
{ "yellow", S("Yellow"), "#e3ff0070" }
}
-- Sheep by PilzAdam/K Pavel, texture converted to minetest by AMMOnym from Summerfield pack
for _, col in ipairs(all_colours) do
local drops_normal = {
{ name = "mobs:mutton_raw", chance = 1, min = 1, max = 2 },
{ name = "wool:" .. col[1], chance = 1, min = 1, max = 1 }
}
local drops_gotten = {
{ name = "mobs:mutton_raw", chance = 1, min = 1, max = 2 }
}
mobs:register_mob("mobs_animal:sheep_" .. col[1], {
stay_near = { "farming:straw", 10 },
stepheight = 0.6,
type = "animal",
passive = true,
hp_min = 8,
hp_max = 10,
armor = 200,
collisionbox = { -0.5, -1, -0.5, 0.5, 0.3, 0.5 },
visual = "mesh",
mesh = "mobs_sheep.b3d",
textures = {
{ "mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:" .. col[3] .. ")" }
},
gotten_texture = { "mobs_sheep_shaved.png" },
gotten_mesh = "mobs_sheep_shaved.b3d",
makes_footstep_sound = true,
sounds = {
random = "mobs_sheep"
},
walk_velocity = 1,
run_velocity = 2,
runaway = true,
jump = true,
jump_height = 6,
pushable = true,
drops = drops_normal,
water_damage = 0.01,
lava_damage = 5,
light_damage = 0,
animation = {
speed_normal = 15,
speed_run = 15,
stand_start = 0,
stand_end = 80,
walk_start = 81,
walk_end = 100,
die_start = 1, -- we dont have a specific death animation so we will
die_end = 2, -- re-use 2 standing frames at a speed of 1 fps and
die_speed = 1, -- have mob rotate when dying.
die_loop = false,
die_rotate = true
},
follow = {
"farming:wheat", "default:grass_1", "farming:barley",
"farming:oat", "farming:rye"
},
view_range = 8,
replace_rate = 10,
replace_what = {
{ "group:grass", "air", -1 },
{ "default:dirt_with_grass", "default:dirt", -2 }
},
fear_height = 3,
on_replace = function(self, pos, oldnode, newnode)
self.food = (self.food or 0) + 1
-- if sheep replaces 8x grass then it regrows wool
if self.food >= 8 then
self.food = 0
self.gotten = false
self.drops = drops_normal
self.object:set_properties({
textures = {
"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:"
.. col[3] .. ")"
},
mesh = "mobs_sheep.b3d",
})
end
end,
on_rightclick = function(self, clicker)
--are we feeding?
if mobs:feed_tame(self, clicker, 8, true, true) then
--if fed 7 times then sheep regrows wool
if self.food and self.food > 6 then
self.gotten = false
self.drops = drops_normal
self.object:set_properties({
textures = {
"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:"
.. col[3] .. ")"
},
mesh = "mobs_sheep.b3d"
})
end
return
end
local item = clicker:get_wielded_item()
local itemname = item:get_name()
local name = clicker:get_player_name()
--are we giving a haircut>
if itemname == "mobs:shears" then
if self.gotten ~= false
or self.child ~= false
or name ~= self.owner
or not minetest.get_modpath("wool") then
return
end
self.gotten = true -- shaved
self.drops = drops_gotten
local obj = minetest.add_item(
self.object:get_pos(),
ItemStack("wool:" .. col[1] .. " " .. random(3))
)
if obj then
obj:set_velocity({
x = random(-1, 1),
y = 5,
z = random(-1, 1)
})
end
item:add_wear(650) -- 100 uses
clicker:set_wielded_item(item)
self.object:set_properties({
textures = { "mobs_sheep_shaved.png" },
mesh = "mobs_sheep_shaved.b3d"
})
return
end
--are we coloring?
if itemname:find("dye:") then
if self.gotten == false
and self.child == false
and self.tamed == true
and name == self.owner then
local colr = string.split(itemname, ":")[2]
for _, c in pairs(all_colours) do
if c[1] == colr then
local pos = self.object:get_pos()
self.object:remove()
local mob = minetest.add_entity(pos, "mobs_animal:sheep_" .. colr)
local ent = mob:get_luaentity()
ent.owner = name
ent.tamed = true
ent.protected = self.protected
ent.fire_damage = self.fire_damage
-- take item
if not mobs.is_creative(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end
break
end
end
end
return
end
-- protect mod with mobs:protector item
if mobs:protect(self, clicker) then return end
--are we capturing?
if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
end
})
-- spawn egg
mobs:register_egg("mobs_animal:sheep_" .. col[1], S("@1 Sheep", col[2]),
"wool_" .. col[1] .. ".png^mobs_sheep_inv.png")
-- compatibility
mobs:alias_mob("mobs:sheep_" .. col[1], "mobs_animal:sheep_" .. col[1])
end
if not mobs.custom_spawn_animal then
mobs:spawn({
name = "mobs_animal:sheep_white",
nodes = { "default:dirt_with_grass", "ethereal:green_dirt" },
neighbors = { "group:grass" },
min_light = 14,
interval = 60,
chance = 8000,
min_height = 0,
max_height = 200,
day_toggle = true,
active_object_count = 3,
-- custom function to spawn sheep herds around main mob
on_spawn = function(self, pos)
local nods = minetest.find_nodes_in_area_under_air(
{ x = pos.x - 4, y = pos.y - 3, z = pos.z - 4 },
{ x = pos.x + 4, y = pos.y + 3, z = pos.z + 4 },
{ "default:dirt_with_grass", "ethereal:green_dirt" })
if nods and #nods > 0 then
-- min herd of 3
local iter = math.min(#nods, 3)
-- print("--- sheep at", minetest.pos_to_string(pos), iter)
for n = 1, iter do
-- 1/8 chance of black sheep, 1/4 chance of baby sheep
local pos2 = nods[random(#nods)]
local type = random(8) == 1 and "_black" or "_white"
local kid = random(4) == 1 and true or nil
pos2.y = pos2.y + 2
if minetest.get_node(pos2).name == "air" then
mobs:add_mob(pos2, {
name = "mobs_animal:sheep" .. type, child = kid })
end
end
end
end
})
end
mobs:alias_mob("mobs:sheep", "mobs_animal:sheep_white") -- compatibility
-- raw mutton
minetest.register_craftitem(":mobs:mutton_raw", {
description = S("Raw Mutton") .. '\n' ..
minetest.colorize('#DEB887', S('Hunger') .. ': 2'),
inventory_image = "mobs_mutton_raw.png",
on_use = function(itemstack, user, pointed_thing)
local hunger_amount = minetest.get_item_group(itemstack:get_name(), "hunger_amount") or 0
if hunger_amount == 0 then
return itemstack
end
return minetest.item_eat(hunger_amount)(itemstack, user, pointed_thing)
end,
groups = { food_meat_raw = 1, food_mutton_raw = 1, flammable = 2, hunger_amount = 2 }
})
-- cooked mutton
minetest.register_craftitem(":mobs:mutton_cooked", {
description = S("Cooked Mutton") .. '\n' ..
minetest.colorize('#DEB887', S('Hunger') .. ': 6'),
inventory_image = "mobs_mutton_cooked.png",
on_use = function(itemstack, user, pointed_thing)
local hunger_amount = minetest.get_item_group(itemstack:get_name(), "hunger_amount") or 0
if hunger_amount == 0 then
return itemstack
end
return minetest.item_eat(hunger_amount)(itemstack, user, pointed_thing)
end,
groups = { food_meat = 1, food_mutton = 1, flammable = 2, hunger_amount = 6 }
})
minetest.register_craft({
type = "cooking",
output = "mobs:mutton_cooked",
recipe = "mobs:mutton_raw",
cooktime = 5
})