forked from Athemis/mobs_redo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.lua
3751 lines (2749 loc) · 80.4 KB
/
api.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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Mobs Api
mobs = {}
mobs.mod = "redo"
mobs.version = "20180126"
-- Intllib
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP .. "/intllib.lua")
mobs.intllib = S
-- CMI support check
local use_cmi = minetest.global_exists("cmi")
-- Invisibility mod check
mobs.invis = {}
if minetest.global_exists("invisibility") then
mobs.invis = invisibility
end
-- creative check
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
function mobs.is_creative(name)
return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
end
-- localize math functions
local pi = math.pi
local square = math.sqrt
local sin = math.sin
local cos = math.cos
local abs = math.abs
local min = math.min
local max = math.max
local atann = math.atan
local random = math.random
local floor = math.floor
local atan = function(x)
if not x or x ~= x then
--error("atan bassed NaN")
return 0
else
return atann(x)
end
end
-- Load settings
local damage_enabled = minetest.settings:get_bool("enable_damage")
local mobs_spawn = minetest.settings:get_bool("mobs_spawn") ~= false
local peaceful_only = minetest.settings:get_bool("only_peaceful_mobs")
local disable_blood = minetest.settings:get_bool("mobs_disable_blood")
local mobs_drop_items = minetest.settings:get_bool("mobs_drop_items") ~= false
local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false
local creative = minetest.settings:get_bool("creative_mode")
local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= false
local remove_far = minetest.settings:get_bool("remove_far_mobs")
local difficulty = tonumber(minetest.settings:get("mob_difficulty")) or 1.0
local show_health = minetest.settings:get_bool("mob_show_health") ~= false
local max_per_block = tonumber(minetest.settings:get("max_objects_per_block") or 99)
local mob_chance_multiplier = tonumber(minetest.settings:get("mob_chance_multiplier") or 1)
-- Peaceful mode message so players will know there are no monsters
if peaceful_only then
minetest.register_on_joinplayer(function(player)
minetest.chat_send_player(player:get_player_name(),
S("** Peaceful Mode Active - No Monsters Will Spawn"))
end)
end
-- calculate aoc range for mob count
local aosrb = tonumber(minetest.settings:get("active_object_send_range_blocks"))
local abr = tonumber(minetest.settings:get("active_block_range"))
local aoc_range = max(aosrb, abr) * 16
-- pathfinding settings
local enable_pathfinding = true
local stuck_timeout = 3 -- how long before mob gets stuck in place and starts searching
local stuck_path_timeout = 10 -- how long will mob follow path before giving up
-- default nodes
local node_fire = "fire:basic_flame"
local node_permanent_flame = "fire:permanent_flame"
local node_ice = "default:ice"
local node_snowblock = "default:snowblock"
local node_snow = "default:snow"
mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "default:dirt"
-- play sound
local mob_sound = function(self, sound)
if sound then
minetest.sound_play(sound, {
object = self.object,
gain = 1.0,
max_hear_distance = self.sounds.distance
})
end
end
-- attack player/mob
local do_attack = function(self, player)
if self.state == "attack" then
return
end
self.attack = player
self.state = "attack"
if random(0, 100) < 90 then
mob_sound(self, self.sounds.war_cry)
end
end
-- move mob in facing direction
local set_velocity = function(self, v)
local yaw = (self.object:get_yaw() or 0) + self.rotate
self.object:setvelocity({
x = sin(yaw) * -v,
y = self.object:getvelocity().y,
z = cos(yaw) * v
})
end
-- calculate mob velocity
local get_velocity = function(self)
local v = self.object:getvelocity()
return (v.x * v.x + v.z * v.z) ^ 0.5
end
-- set and return valid yaw
local set_yaw = function(self, yaw)
if not yaw or yaw ~= yaw then
yaw = 0
end
self:setyaw(yaw)
return yaw
end
-- set defined animation
local set_animation = function(self, anim)
if not self.animation
or not anim then return end
self.animation.current = self.animation.current or ""
if anim == self.animation.current
or not self.animation[anim .. "_start"]
or not self.animation[anim .. "_end"] then
return
end
self.animation.current = anim
self.object:set_animation({
x = self.animation[anim .. "_start"],
y = self.animation[anim .. "_end"]},
self.animation[anim .. "_speed"] or self.animation.speed_normal or 15,
0, self.animation[anim .. "_loop"] ~= false)
end
-- above function exported for mount.lua
function mobs:set_animation(self, anim)
set_animation(self, anim)
end
-- calculate distance
local get_distance = function(a, b)
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
return square(x * x + y * y + z * z)
end
-- check line of sight (BrunoMine)
local line_of_sight = function(self, pos1, pos2, stepsize)
stepsize = stepsize or 1
local s, pos = minetest.line_of_sight(pos1, pos2, stepsize)
-- normal walking and flying mobs can see you through air
if s == true then
return true
end
-- New pos1 to be analyzed
local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z}
local r, pos = minetest.line_of_sight(npos1, pos2, stepsize)
-- Checks the return
if r == true then return true end
-- Nodename found
local nn = minetest.get_node(pos).name
-- Target Distance (td) to travel
local td = get_distance(pos1, pos2)
-- Actual Distance (ad) traveled
local ad = 0
-- It continues to advance in the line of sight in search of a real
-- obstruction which counts as 'normal' nodebox.
while minetest.registered_nodes[nn]
and (minetest.registered_nodes[nn].walkable == false
or minetest.registered_nodes[nn].drawtype == "nodebox") do
-- Check if you can still move forward
if td < ad + stepsize then
return true -- Reached the target
end
-- Moves the analyzed pos
local d = get_distance(pos1, pos2)
npos1.x = ((pos2.x - pos1.x) / d * stepsize) + pos1.x
npos1.y = ((pos2.y - pos1.y) / d * stepsize) + pos1.y
npos1.z = ((pos2.z - pos1.z) / d * stepsize) + pos1.z
-- NaN checks
if d == 0
or npos1.x ~= npos1.x
or npos1.y ~= npos1.y
or npos1.z ~= npos1.z then
return false
end
ad = ad + stepsize
-- scan again
r, pos = minetest.line_of_sight(npos1, pos2, stepsize)
if r == true then return true end
-- New Nodename found
nn = minetest.get_node(pos).name
end
return false
end
-- are we flying in what we are suppose to? (taikedz)
local flight_check = function(self, pos_w)
local nod = self.standing_in
local def = minetest.registered_nodes[nod]
if not def then return false end -- nil check
if type(self.fly_in) == "string"
and nod == self.fly_in then
return true
elseif type(self.fly_in) == "table" then
for _,fly_in in pairs(self.fly_in) do
if nod == fly_in then
return true
end
end
end
-- stops mobs getting stuck inside stairs and plantlike nodes
if def.drawtype ~= "airlike"
and def.drawtype ~= "liquid"
and def.drawtype ~= "flowingliquid" then
return true
end
return false
end
-- custom particle effects
local effect = function(pos, amount, texture, min_size, max_size, radius, gravity, glow)
radius = radius or 2
min_size = min_size or 0.5
max_size = max_size or 1
gravity = gravity or -10
glow = glow or 0
minetest.add_particlespawner({
amount = amount,
time = 0.25,
minpos = pos,
maxpos = pos,
minvel = {x = -radius, y = -radius, z = -radius},
maxvel = {x = radius, y = radius, z = radius},
minacc = {x = 0, y = gravity, z = 0},
maxacc = {x = 0, y = gravity, z = 0},
minexptime = 0.1,
maxexptime = 1,
minsize = min_size,
maxsize = max_size,
texture = texture,
glow = glow,
})
end
-- update nametag colour
local update_tag = function(self)
local col = "#00FF00"
local qua = self.hp_max / 4
if self.health <= floor(qua * 3) then
col = "#FFFF00"
end
if self.health <= floor(qua * 2) then
col = "#FF6600"
end
if self.health <= floor(qua) then
col = "#FF0000"
end
self.object:set_properties({
nametag = self.nametag,
nametag_color = col
})
end
-- drop items
local item_drop = function(self, cooked)
-- no drops if disabled by setting
if not mobs_drop_items then return end
-- no drops for child mobs
if self.child then return end
local obj, item, num
local pos = self.object:get_pos()
self.drops = self.drops or {} -- nil check
for n = 1, #self.drops do
if random(1, self.drops[n].chance) == 1 then
num = random(self.drops[n].min or 1, self.drops[n].max or 1)
item = self.drops[n].name
-- cook items when true
if cooked then
local output = minetest.get_craft_result({
method = "cooking", width = 1, items = {item}})
if output and output.item and not output.item:is_empty() then
item = output.item:get_name()
end
end
-- add item if it exists
obj = minetest.add_item(pos, ItemStack(item .. " " .. num))
if obj and obj:get_luaentity() then
obj:setvelocity({
x = random(-10, 10) / 9,
y = 6,
z = random(-10, 10) / 9,
})
elseif obj then
obj:remove() -- item does not exist
end
end
end
self.drops = {}
end
-- check if mob is dead or only hurt
local check_for_death = function(self, cause, cmi_cause)
-- has health actually changed?
if self.health == self.old_health and self.health > 0 then
return
end
self.old_health = self.health
-- still got some health? play hurt sound
if self.health > 0 then
mob_sound(self, self.sounds.damage)
-- make sure health isn't higher than max
if self.health > self.hp_max then
self.health = self.hp_max
end
-- backup nametag so we can show health stats
if not self.nametag2 then
self.nametag2 = self.nametag or ""
end
if show_health
and (cmi_cause and cmi_cause.type == "punch") then
self.htimer = 2
self.nametag = "♥ " .. self.health .. " / " .. self.hp_max
update_tag(self)
end
return false
end
-- dropped cooked item if mob died in lava
if cause == "lava" then
item_drop(self, true)
else
item_drop(self, nil)
end
mob_sound(self, self.sounds.death)
local pos = self.object:get_pos()
-- execute custom death function
if self.on_die then
self.on_die(self, pos)
if use_cmi then
cmi.notify_die(self.object, cmi_cause)
end
self.object:remove()
return true
end
-- default death function and die animation (if defined)
if self.animation
and self.animation.die_start
and self.animation.die_end then
local frames = self.animation.die_end - self.animation.die_start
local speed = self.animation.die_speed or 15
local length = max(frames / speed, 0)
self.attack = nil
self.v_start = false
self.timer = 0
self.blinktimer = 0
self.passive = true
self.state = "die"
set_velocity(self, 0)
set_animation(self, "die")
minetest.after(length, function(self)
if use_cmi then
cmi.notify_die(self.object, cmi_cause)
end
self.object:remove()
end, self)
else
if use_cmi then
cmi.notify_die(self.object, cmi_cause)
end
self.object:remove()
end
effect(pos, 20, "tnt_smoke.png")
return true
end
-- check if within physical map limits (-30911 to 30927)
local within_limits = function(pos, radius)
if (pos.x - radius) > -30913
and (pos.x + radius) < 30928
and (pos.y - radius) > -30913
and (pos.y + radius) < 30928
and (pos.z - radius) > -30913
and (pos.z + radius) < 30928 then
return true -- within limits
end
return false -- beyond limits
end
-- is mob facing a cliff
local is_at_cliff = function(self)
if self.fear_height == 0 then -- 0 for no falling protection!
return false
end
local yaw = self.object:get_yaw()
local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5)
local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5)
local pos = self.object:get_pos()
local ypos = pos.y + self.collisionbox[2] -- just above floor
if minetest.line_of_sight(
{x = pos.x + dir_x, y = ypos, z = pos.z + dir_z},
{x = pos.x + dir_x, y = ypos - self.fear_height, z = pos.z + dir_z}
, 1) then
return true
end
return false
end
-- get node but use fallback for nil or unknown
local node_ok = function(pos, fallback)
fallback = fallback or mobs.fallback_node
local node = minetest.get_node_or_nil(pos)
if node and minetest.registered_nodes[node.name] then
return node
end
return minetest.registered_nodes[fallback] -- {name = fallback}
end
-- environmental damage (water, lava, fire, light etc.)
local do_env_damage = function(self)
-- feed/tame text timer (so mob 'full' messages dont spam chat)
if self.htimer > 0 then
self.htimer = self.htimer - 1
end
-- reset nametag after showing health stats
if self.htimer < 1 and self.nametag2 then
self.nametag = self.nametag2
self.nametag2 = nil
update_tag(self)
end
local pos = self.object:get_pos()
self.time_of_day = minetest.get_timeofday()
-- remove mob if beyond map limits
if not within_limits(pos, 0) then
self.object:remove()
return
end
-- bright light harms mob
if self.light_damage ~= 0
-- and pos.y > 0
-- and self.time_of_day > 0.2
-- and self.time_of_day < 0.8
and (minetest.get_node_light(pos) or 0) > 12 then
self.health = self.health - self.light_damage
effect(pos, 5, "tnt_smoke.png")
if check_for_death(self, "light", {type = "light"}) then return end
end
local y_level = self.collisionbox[2]
if self.child then
y_level = self.collisionbox[2] * 0.5
end
-- what is mob standing in?
pos.y = pos.y + y_level + 0.25 -- foot level
self.standing_in = node_ok(pos, "air").name
-- print ("standing in " .. self.standing_in)
-- don't fall when on ignore, just stand still
if self.standing_in == "ignore" then
self.object:setvelocity({x = 0, y = 0, z = 0})
end
local nodef = minetest.registered_nodes[self.standing_in]
pos.y = pos.y + 1 -- for particle effect position
-- water
if self.water_damage
and nodef.groups.water then
if self.water_damage ~= 0 then
self.health = self.health - self.water_damage
effect(pos, 5, "bubble.png", nil, nil, 1, nil)
if check_for_death(self, "water", {type = "environment",
pos = pos, node = self.standing_in}) then return end
end
-- lava or fire
elseif self.lava_damage
and (nodef.groups.lava
or self.standing_in == node_fire
or self.standing_in == node_permanent_flame) then
if self.lava_damage ~= 0 then
self.health = self.health - self.lava_damage
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
if check_for_death(self, "lava", {type = "environment",
pos = pos, node = self.standing_in}) then return end
end
-- damage_per_second node check
elseif nodef.damage_per_second ~= 0 then
self.health = self.health - nodef.damage_per_second
effect(pos, 5, "tnt_smoke.png")
if check_for_death(self, "dps", {type = "environment",
pos = pos, node = self.standing_in}) then return end
end
--[[
--- suffocation inside solid node
if self.suffocation ~= 0
and nodef.walkable == true
and nodef.groups.disable_suffocation ~= 1
and nodef.drawtype == "normal" then
self.health = self.health - self.suffocation
if check_for_death(self, "suffocation", {type = "environment",
pos = pos, node = self.standing_in}) then return end
end
]]
check_for_death(self, "", {type = "unknown"})
end
-- jump if facing a solid node (not fences or gates)
local do_jump = function(self)
if not self.jump
or self.jump_height == 0
or self.fly
or self.child then
return false
end
self.facing_fence = false
-- something stopping us while moving?
if self.state ~= "stand"
and get_velocity(self) > 0.5
and self.object:getvelocity().y ~= 0 then
return false
end
local pos = self.object:get_pos()
local yaw = self.object:get_yaw()
-- what is mob standing on?
pos.y = pos.y + self.collisionbox[2] - 0.2
local nod = node_ok(pos)
--print ("standing on:", nod.name, pos.y)
if minetest.registered_nodes[nod.name].walkable == false then
return false
end
-- where is front
local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5)
local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5)
-- what is in front of mob?
local nod = node_ok({
x = pos.x + dir_x,
y = pos.y + 0.5,
z = pos.z + dir_z
})
-- thin blocks that do not need to be jumped
if nod.name == node_snow then
return false
end
--print ("in front:", nod.name, pos.y + 0.5)
if self.walk_chance == 0
or minetest.registered_items[nod.name].walkable then
if not nod.name:find("fence")
and not nod.name:find("gate") then
local v = self.object:getvelocity()
v.y = self.jump_height
set_animation(self, "jump") -- only when defined
self.object:setvelocity(v)
if get_velocity(self) > 0 then
mob_sound(self, self.sounds.jump)
end
else
self.facing_fence = true
end
return true
end
return false
end
-- blast damage to entities nearby (modified from TNT mod)
local entity_physics = function(pos, radius)
radius = radius * 2
local objs = minetest.get_objects_inside_radius(pos, radius)
local obj_pos, dist
for n = 1, #objs do
obj_pos = objs[n]:get_pos()
dist = get_distance(pos, obj_pos)
if dist < 1 then dist = 1 end
local damage = floor((4 / dist) * radius)
local ent = objs[n]:get_luaentity()
-- punches work on entities AND players
objs[n]:punch(objs[n], 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = damage},
}, pos)
end
end
-- should mob follow what I'm holding ?
local follow_holding = function(self, clicker)
if mobs.invis[clicker:get_player_name()] then
return false
end
local item = clicker:get_wielded_item()
local t = type(self.follow)
-- single item
if t == "string"
and item:get_name() == self.follow then
return true
-- multiple items
elseif t == "table" then
for no = 1, #self.follow do
if self.follow[no] == item:get_name() then
return true
end
end
end
return false
end
-- find two animals of same type and breed if nearby and horny
local breed = function(self)
-- child takes 240 seconds before growing into adult
if self.child == true then
self.hornytimer = self.hornytimer + 1
if self.hornytimer > 240 then
self.child = false
self.hornytimer = 0
self.object:set_properties({
textures = self.base_texture,
mesh = self.base_mesh,
visual_size = self.base_size,
collisionbox = self.base_colbox,
selectionbox = self.base_selbox,
})
-- custom function when child grows up
if self.on_grown then
self.on_grown(self)
else
-- jump when fully grown so as not to fall into ground
self.object:setvelocity({
x = 0,
y = self.jump_height,
z = 0
})
end
end
return
end
-- horny animal can mate for 40 seconds,
-- afterwards horny animal cannot mate again for 200 seconds
if self.horny == true
and self.hornytimer < 240 then
self.hornytimer = self.hornytimer + 1
if self.hornytimer >= 240 then
self.hornytimer = 0
self.horny = false
end
end
-- find another same animal who is also horny and mate if nearby
if self.horny == true
and self.hornytimer <= 40 then
local pos = self.object:get_pos()
effect({x = pos.x, y = pos.y + 1, z = pos.z}, 8, "heart.png", 3, 4, 1, 0.1)
local objs = minetest.get_objects_inside_radius(pos, 3)
local num = 0
local ent = nil
for n = 1, #objs do
ent = objs[n]:get_luaentity()
-- check for same animal with different colour
local canmate = false
if ent then
if ent.name == self.name then
canmate = true
else
local entname = string.split(ent.name,":")
local selfname = string.split(self.name,":")
if entname[1] == selfname[1] then
entname = string.split(entname[2],"_")
selfname = string.split(selfname[2],"_")
if entname[1] == selfname[1] then
canmate = true
end
end
end
end
if ent
and canmate == true
and ent.horny == true
and ent.hornytimer <= 40 then
num = num + 1
end
-- found your mate? then have a baby
if num > 1 then
self.hornytimer = 41
ent.hornytimer = 41
-- spawn baby
minetest.after(5, function()
-- custom breed function
if self.on_breed then
-- when false skip going any further
if self.on_breed(self, ent) == false then
return
end
else
effect(pos, 15, "tnt_smoke.png", 1, 2, 2, 15, 5)
end
local mob = minetest.add_entity(pos, self.name)
local ent2 = mob:get_luaentity()
local textures = self.base_texture
-- using specific child texture (if found)
if self.child_texture then
textures = self.child_texture[1]
end
-- and resize to half height
mob:set_properties({
textures = textures,
visual_size = {
x = self.base_size.x * .5,
y = self.base_size.y * .5,
},
collisionbox = {
self.base_colbox[1] * .5,
self.base_colbox[2] * .5,
self.base_colbox[3] * .5,
self.base_colbox[4] * .5,
self.base_colbox[5] * .5,
self.base_colbox[6] * .5,
},
selectionbox = {
self.base_selbox[1] * .5,
self.base_selbox[2] * .5,
self.base_selbox[3] * .5,
self.base_selbox[4] * .5,
self.base_selbox[5] * .5,
self.base_selbox[6] * .5,
},
})
-- tamed and owned by parents' owner
ent2.child = true
ent2.tamed = true
ent2.owner = self.owner
end)
num = 0
break
end
end
end
end
-- find and replace what mob is looking for (grass, wheat etc.)
local replace = function(self, pos)
if not mobs_griefing
or not self.replace_rate
or not self.replace_what
or self.child == true
or self.object:getvelocity().y ~= 0
or random(1, self.replace_rate) > 1 then
return
end
local what, with, y_offset