Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.

Commit 1f02cee

Browse files
committed
update mobs, readd cow replace with dung
1 parent 7f60711 commit 1f02cee

File tree

8 files changed

+105
-61
lines changed

8 files changed

+105
-61
lines changed

mods/mobs/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This mod contains the following additions:
2828

2929
Changelog:
3030

31+
1.27- Added new sheep, lava flan and spawn egg textures. New Lava Pick tool smelts what you dig. New atan checking function.
3132
1.26- Pathfinding feature added thanks to rnd, when monsters attack they become scary smart in finding you :) also, beehive produces honey now :)
3233
1.25- Mobs no longer spawn within 12 blocks of player or despawn within same range, spawners now have player detection, Code tidy and tweak.
3334
1.24- Added feature where certain animals run away when punched (runaway = true in mob definition)

mods/mobs/api.lua

Lines changed: 102 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Mobs Api (17th February 2016)
1+
-- Mobs Api (4th March 2016)
22
mobs = {}
33
mobs.mod = "redo"
44

@@ -20,6 +20,16 @@ local stuck_path_timeout = 10 -- how long will mob follow path before giving up
2020

2121
local pi = math.pi
2222
local square = math.sqrt
23+
local atan = function(x)
24+
25+
if x ~= x then
26+
--error("atan bassed NaN")
27+
print ("atan based NaN")
28+
return 0
29+
else
30+
return math.atan(x)
31+
end
32+
end
2333

2434
do_attack = function(self, player)
2535

@@ -129,6 +139,34 @@ set_animation = function(self, type)
129139
end
130140
end
131141

142+
-- check line of sight for walkers and swimmers alike
143+
function line_of_sight_water(self, pos1, pos2, stepsize)
144+
145+
local s, pos_w = minetest.line_of_sight(pos1, pos2, stepsize)
146+
147+
-- normal walking and flying mobs can see you through air
148+
if s == true then
149+
return true
150+
end
151+
152+
-- swimming mobs can see you through water
153+
if s == false
154+
and self.fly
155+
and self.fly_in == "default:water_source" then
156+
157+
local nod = minetest.get_node(pos_w).name
158+
159+
if nod == "default:water_source"
160+
or nod == "default:water_flowing" then
161+
162+
return true
163+
end
164+
end
165+
166+
return false
167+
168+
end
169+
132170
-- particle effects
133171
function effect(pos, amount, texture, max_size)
134172

@@ -285,6 +323,24 @@ local function is_at_cliff(self)
285323
return false
286324
end
287325

326+
-- get node but use fallback for nil or unknown
327+
local function node_ok(pos, fallback)
328+
329+
fallback = fallback or "default:dirt"
330+
331+
local node = minetest.get_node_or_nil(pos)
332+
333+
if not node then
334+
return minetest.registered_nodes[fallback]
335+
end
336+
337+
if minetest.registered_nodes[node.name] then
338+
return node
339+
end
340+
341+
return minetest.registered_nodes[fallback]
342+
end
343+
288344
-- environmental damage (water, lava, fire, light)
289345
do_env_damage = function(self)
290346

@@ -315,15 +371,16 @@ do_env_damage = function(self)
315371
effect(pos, 5, "tnt_smoke.png")
316372
end
317373

374+
-- what is mob standing in?
375+
pos.y = pos.y + self.collisionbox[2] + 0.1 -- foot level
376+
self.standing_in = node_ok(pos, "air").name
377+
--print ("standing in " .. self.standing_in)
378+
318379
if self.water_damage ~= 0
319380
or self.lava_damage ~= 0 then
320381

321-
pos.y = pos.y + self.collisionbox[2] + 0.1 -- foot level
382+
local nodef = minetest.registered_nodes[self.standing_in]
322383

323-
local nod = node_ok(pos, "air") ; --print ("standing in "..nod.name)
324-
local nodef = minetest.registered_nodes[nod.name]
325-
326-
if not nodef then return end --MFF fix crash
327384
pos.y = pos.y + 1
328385

329386
-- water
@@ -338,8 +395,8 @@ do_env_damage = function(self)
338395
-- lava or fire
339396
if self.lava_damage ~= 0
340397
and (nodef.groups.lava
341-
or nod.name == "fire:basic_flame"
342-
or nod.name == "fire:permanent_flame") then
398+
or self.standing_in == "fire:basic_flame"
399+
or self.standing_in == "fire:permanent_flame") then
343400

344401
self.object:set_hp(self.object:get_hp() - self.lava_damage)
345402

@@ -462,24 +519,6 @@ function entity_physics(pos, radius, self) --/MFF (Crabman|06/23/2015)add self t
462519
end
463520
end
464521

465-
-- get node but use fallback for nil or unknown
466-
function node_ok(pos, fallback)
467-
468-
fallback = fallback or "default:dirt"
469-
470-
local node = minetest.get_node_or_nil(pos)
471-
472-
if not node then
473-
return minetest.registered_nodes[fallback]
474-
end
475-
476-
if minetest.registered_nodes[node.name] then
477-
return node
478-
end
479-
480-
return minetest.registered_nodes[fallback]
481-
end
482-
483522
-- should mob follow what I'm holding ?
484523
function follow_holding(self, clicker)
485524

@@ -1117,7 +1156,8 @@ minetest.register_entity(name, {
11171156
-- field of view check goes here
11181157

11191158
-- choose closest player to attack
1120-
if minetest.line_of_sight(sp, p, 2) == true
1159+
--if minetest.line_of_sight(sp, p, 2) == true
1160+
if line_of_sight_water(self, sp, p, 2) == true
11211161
and dist < min_dist then
11221162
min_dist = dist
11231163
min_player = player
@@ -1246,7 +1286,7 @@ minetest.register_entity(name, {
12461286
if vec.x ~= 0
12471287
and vec.z ~= 0 then
12481288

1249-
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
1289+
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
12501290

12511291
if p.x > s.x then
12521292
yaw = yaw + pi
@@ -1283,6 +1323,19 @@ minetest.register_entity(name, {
12831323
end
12841324
end
12851325

1326+
-- water swimmers flop when on land
1327+
if self.fly
1328+
and self.fly_in == "default:water_source"
1329+
and self.standing_in ~= self.fly_in then
1330+
1331+
self.state = "flop"
1332+
self.object:setvelocity({x = 0, y = -5, z = 0})
1333+
1334+
set_animation(self, "stand")
1335+
1336+
return
1337+
end
1338+
12861339
if self.state == "stand" then
12871340

12881341
if math.random(1, 4) == 1 then
@@ -1315,7 +1368,7 @@ minetest.register_entity(name, {
13151368
if vec.x ~= 0
13161369
and vec.z ~= 0 then
13171370

1318-
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
1371+
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
13191372

13201373
if lp.x > s.x then
13211374
yaw = yaw + pi
@@ -1350,22 +1403,6 @@ minetest.register_entity(name, {
13501403
local s = self.object:getpos()
13511404
local lp = minetest.find_node_near(s, 1, {"group:water"})
13521405

1353-
-- water swimmers cannot move out of water
1354-
if self.fly
1355-
and self.fly_in == "default:water_source"
1356-
and not lp then
1357-
1358-
--print ("out of water")
1359-
1360-
set_velocity(self, 0)
1361-
1362-
-- change to undefined state so nothing more happens
1363-
self.state = "flop"
1364-
set_animation(self, "stand")
1365-
1366-
return
1367-
end
1368-
13691406
-- if water nearby then turn away
13701407
if lp then
13711408

@@ -1378,7 +1415,7 @@ minetest.register_entity(name, {
13781415
if vec.x ~= 0
13791416
and vec.z ~= 0 then
13801417

1381-
yaw = math.atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
1418+
yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
13821419

13831420
if lp.x > s.x then
13841421
yaw = yaw + pi
@@ -1480,7 +1517,7 @@ minetest.register_entity(name, {
14801517
if vec.x ~= 0
14811518
and vec.z ~= 0 then
14821519

1483-
yaw = math.atan(vec.z / vec.x) + pi / 2 - self.rotate
1520+
yaw = atan(vec.z / vec.x) + pi / 2 - self.rotate
14841521

14851522
if p.x > s.x then
14861523
yaw = yaw + pi
@@ -1657,7 +1694,7 @@ minetest.register_entity(name, {
16571694
if vec.x ~= 0
16581695
and vec.z ~= 0 then
16591696

1660-
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
1697+
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
16611698

16621699
if p.x > s.x then
16631700
yaw = yaw + pi
@@ -1720,7 +1757,8 @@ minetest.register_entity(name, {
17201757
p2.y = p2.y + 1.5
17211758
s2.y = s2.y + 1.5
17221759

1723-
if minetest.line_of_sight(p2, s2) == true then
1760+
--if minetest.line_of_sight(p2, s2) == true then
1761+
if line_of_sight_water(self, p2, s2) == true then
17241762

17251763
-- play attack sound
17261764
if self.sounds.attack then
@@ -1756,7 +1794,7 @@ minetest.register_entity(name, {
17561794
if vec.x ~= 0
17571795
and vec.z ~= 0 then
17581796

1759-
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
1797+
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
17601798

17611799
if p.x > s.x then
17621800
yaw = yaw + pi
@@ -1868,7 +1906,8 @@ minetest.register_entity(name, {
18681906
local up = 2
18691907

18701908
-- if already in air then dont go up anymore when hit
1871-
if v.y > 0 then
1909+
if v.y > 0
1910+
or self.fly then
18721911
up = 0
18731912
end
18741913

@@ -1896,7 +1935,7 @@ minetest.register_entity(name, {
18961935
if vec.x ~= 0
18971936
and vec.z ~= 0 then
18981937

1899-
local yaw = math.atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
1938+
local yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
19001939

19011940
if lp.x > s.x then
19021941
yaw = yaw + pi
@@ -1912,14 +1951,13 @@ minetest.register_entity(name, {
19121951

19131952
-- attack puncher and call other mobs for help
19141953
if self.passive == false
1954+
and self.state ~= "flop"
19151955
and self.child == false
19161956
and hitter:get_player_name() ~= self.owner then
19171957

1918-
--if self.state ~= "attack" then
1919-
-- attack whoever punched mob
1920-
self.state = ""
1921-
do_attack(self, hitter)
1922-
--end
1958+
-- attack whoever punched mob
1959+
self.state = ""
1960+
do_attack(self, hitter)
19231961

19241962
-- alert others to the attack
19251963
local obj = nil
@@ -2031,6 +2069,7 @@ minetest.register_entity(name, {
20312069
self.mesh = mesh
20322070
self.collisionbox = colbox
20332071
self.visual_size = vis_size
2072+
self.standing_in = ""
20342073

20352074
-- set anything changed above
20362075
self.object:set_properties(self)
@@ -2266,6 +2305,11 @@ function mobs:explosion(pos, radius, fire, smoke, sound)
22662305
and data[vi] ~= c_chest then
22672306

22682307
local n = node_ok(p).name
2308+
local on_blast = minetest.registered_nodes[n].on_blast
2309+
2310+
if on_blast then
2311+
return on_blast(p)
2312+
end
22692313

22702314
if not minetest.is_protected(p, "") --/MFF (Crabman|06/23/2015) re-added node protected in areas
22712315
and minetest.get_item_group(n, "unbreakable") ~= 1
@@ -2419,7 +2463,7 @@ function mobs:register_egg(mob, desc, background, addegg)
24192463
local invimg = background
24202464

24212465
if addegg == 1 then
2422-
invimg = invimg .. "^mobs_chicken_egg.png"
2466+
invimg = invimg .. "^mobs_chicken_egg.png" -- MFF
24232467
end
24242468

24252469
minetest.register_craftitem(mob, {

mods/mobs/cow.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ mobs:register_mob("mobs:cow", {
6060
view_range = 7,
6161
replace_rate = 10,
6262
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
63-
replace_with = "air",
63+
replace_with = "mobs:dung",
6464
fear_height = 2,
6565
on_rightclick = function(self, clicker)
6666

mods/mobs/sheep.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ local all_colours = {
2222
for _, col in pairs(all_colours) do
2323

2424
mobs:register_mob("mobs:sheep_"..col[1], {
25-
2625
-- animal, monster, npc, barbarian
2726
type = "animal",
2827
-- not aggressive
@@ -36,7 +35,7 @@ for _, col in pairs(all_colours) do
3635
visual = "mesh",
3736
mesh = "mobs_sheep.b3d",
3837
textures = {
39-
{"mobs_sheep_wool.png^[colorize:" .. col[3] .. "^mobs_sheep_base.png"},
38+
{"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:" .. col[3] .. ")"},
4039
},
4140
-- specific texture and mesh for gotten
4241
gotten_texture = {"mobs_sheep_shaved.png"},

mods/mobs/textures/mobs_sheep_base.png

100755100644
-14 Bytes
Loading

mods/mobs/textures/mobs_sheep_shaved.png

100755100644
56 Bytes
Loading
3.15 KB
Loading

mods/mobs/textures/mobs_sheep_wool.png

100755100644
-33 Bytes
Loading

0 commit comments

Comments
 (0)