diff --git a/mods/mobs/README.txt b/mods/mobs/README.txt index 29fb7b39..123623a1 100755 --- a/mods/mobs/README.txt +++ b/mods/mobs/README.txt @@ -28,6 +28,7 @@ This mod contains the following additions: Changelog: +1.21- Added some more error checking to reduce serialize.h error and added height checks for falling off cliffs (thanks cmdskp) 1.20- Error checking added to remove bad mobs, out of map limit mobs and stop serialize.h error 1.19- Chickens now drop egg items instead of placing the egg, also throwing eggs result in 1/8 chance of spawning chick 1.18- Added docile_by_day flag so that monsters will not attack automatically during daylight hours unless hit first diff --git a/mods/mobs/api.lua b/mods/mobs/api.lua index df623245..4baf403e 100755 --- a/mods/mobs/api.lua +++ b/mods/mobs/api.lua @@ -1,4 +1,4 @@ --- Mobs Api (15th December 2015) +-- Mobs Api (18th December 2015) mobs = {} mobs.mod = "redo" @@ -234,6 +234,30 @@ function within_limits(pos, radius) return false -- beyond limits end +-- is mob facing a cliff +local function is_at_cliff(self) + + if self.fear_height == 0 then -- if 0, no falling protection! + return false + end + + local yaw = self.object:getyaw() + local dir_x = -math.sin(yaw) * (self.collisionbox[4] + 0.5) + local dir_z = math.cos(yaw) * (self.collisionbox[4] + 0.5) + local pos = self.object:getpos() + 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 + -- environmental damage (water, lava, fire, light) do_env_damage = function(self) @@ -307,9 +331,10 @@ do_jump = function(self) end local pos = self.object:getpos() + local temp_Y = pos.y -- what is mob standing on? - pos.y = (pos.y + self.collisionbox[2]) - 0.2 + pos.y = (temp_Y + self.collisionbox[2]) - 0.2 local nod = node_ok(pos) @@ -340,6 +365,9 @@ do_jump = function(self) local v = self.object:getvelocity() + -- move back a bit - allows jump velocity to carry it forward and succeed better + self.object:setpos({x=pos.x - self.direction.x/2, y=temp_Y, z=pos.z - self.direction.z/2}) + v.y = self.jump_height + 1 v.x = v.x * 2.2 v.z = v.z * 2.2 @@ -619,6 +647,8 @@ minetest.register_entity(name, { stepheight = def.stepheight or 0.6, name = name, + type = def.type, + attack_type = def.attack_type, fly = def.fly, fly_in = def.fly_in or "air", owner = def.owner or "", @@ -650,8 +680,6 @@ minetest.register_entity(name, { drops = def.drops or {}, armor = def.armor, on_rightclick = def.on_rightclick, - type = def.type, - attack_type = def.attack_type, arrow = def.arrow, shoot_interval = def.shoot_interval, sounds = def.sounds or {}, @@ -688,6 +716,7 @@ minetest.register_entity(name, { child_texture = def.child_texture, docile_by_day = def.docile_by_day or false, time_of_day = 0.5, + fear_height = def.fear_height or 0, on_step = function(self, dtime) @@ -1102,15 +1131,12 @@ minetest.register_entity(name, { set_animation(self, "stand") -- npc's ordered to stand stay standing - if self.type == "npc" - and self.order == "stand" then + if self.type ~= "npc" + or self.order ~= "stand" then - set_velocity(self, 0) - self.state = "stand" - set_animation(self, "stand") - else if self.walk_chance ~= 0 - and math.random(1, 100) <= self.walk_chance then + and math.random(1, 100) <= self.walk_chance + and is_at_cliff(self) == false then set_velocity(self, self.walk_velocity) self.state = "walk" @@ -1168,8 +1194,13 @@ minetest.register_entity(name, { self.object:setyaw(yaw) end + -- stand for great fall in front + local temp_is_cliff = is_at_cliff(self) + -- jump when walking comes to a halt - if self.jump and get_velocity(self) <= 0.5 + if temp_is_cliff == false + and self.jump + and get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then self.direction = { @@ -1181,14 +1212,15 @@ minetest.register_entity(name, { do_jump(self) end - set_velocity(self, self.walk_velocity) - set_animation(self, "walk") - - if math.random(1, 100) <= 30 then + if temp_is_cliff + or math.random(1, 100) <= 30 then set_velocity(self, 0) self.state = "stand" set_animation(self, "stand") + else + set_velocity(self, self.walk_velocity) + set_animation(self, "walk") end -- attack routines (explode, dogfight, shoot, dogshoot) @@ -1406,8 +1438,14 @@ minetest.register_entity(name, { do_jump(self) end - set_velocity(self, self.run_velocity) - set_animation(self, "run") + if is_at_cliff(self) then + + set_velocity(self, 0) + set_animation(self, "stand") + else + set_velocity(self, self.run_velocity) + set_animation(self, "run") + end else diff --git a/mods/mobs/bunny.lua b/mods/mobs/bunny.lua index b03b374e..701740c1 100755 --- a/mods/mobs/bunny.lua +++ b/mods/mobs/bunny.lua @@ -35,12 +35,16 @@ mobs:register_mob("mobs:bunny", { water_damage = 1, lava_damage = 4, light_damage = 0, + fear_height = 2, -- model animation animation = { speed_normal = 15, - stand_start = 1, stand_end = 15, - walk_start = 16, walk_end = 24, - punch_start = 16, punch_end = 24, + stand_start = 1, + stand_end = 15, + walk_start = 16, + walk_end = 24, + punch_start = 16, + punch_end = 24, }, -- follows carrot from farming redo follow = {"farming:carrot", "farming_plus:carrot_item"}, diff --git a/mods/mobs/chicken.lua b/mods/mobs/chicken.lua index 237211ba..b502f882 100755 --- a/mods/mobs/chicken.lua +++ b/mods/mobs/chicken.lua @@ -157,7 +157,7 @@ local mobs_shoot_egg = function (item, player, pointed_thing) local ent = obj:get_luaentity() local dir = player:get_look_dir() ent.velocity = egg_VELOCITY -- needed for api internal timing - ent.switch = 1 + ent.switch = 1 -- needed so that egg doesn't despawn straight away obj:setvelocity({ x = dir.x * egg_VELOCITY, y = dir.y * egg_VELOCITY, diff --git a/mods/mobs/cow.lua b/mods/mobs/cow.lua index 18b02009..b9e9beb7 100755 --- a/mods/mobs/cow.lua +++ b/mods/mobs/cow.lua @@ -64,6 +64,7 @@ mobs:register_mob("mobs:cow", { replace_rate = 10, replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"}, replace_with = "air", + fear_height = 2, on_rightclick = function(self, clicker) if not mobs:feed_tame(self, clicker, 8, true, true) then local tool = clicker:get_wielded_item() diff --git a/mods/mobs/creeper.lua b/mods/mobs/creeper.lua index 2a4615dd..bcd2827c 100755 --- a/mods/mobs/creeper.lua +++ b/mods/mobs/creeper.lua @@ -45,11 +45,16 @@ mobs:register_mob("mobs:creeper", { light_damage = 0, -- model animation animation = { - stand_start = 0, stand_end = 24, - walk_start = 25, walk_end = 47, - run_start = 48, run_end = 62, - punch_start = 48, punch_end = 62, - speed_normal = 15, speed_run = 15, + stand_start = 0, + stand_end = 24, + walk_start = 25, + walk_end = 47, + run_start = 48, + run_end = 62, + punch_start = 48, + punch_end = 62, + speed_normal = 15, + speed_run = 15, }, }) mobs:spawn_specific("mobs:creeper", {"default:dirt_with_grass"}, {"air"}, 8, 20, 30, 20000, 1, -31000, 31000, false) diff --git a/mods/mobs/dirtmonster.lua b/mods/mobs/dirtmonster.lua index c3a8a7a8..05476153 100755 --- a/mods/mobs/dirtmonster.lua +++ b/mods/mobs/dirtmonster.lua @@ -42,15 +42,22 @@ mobs:register_mob("mobs:dirt_monster", { water_damage = 1, lava_damage = 5, light_damage = 2, + fear_height = 3, -- model animation animation = { - speed_normal = 15, speed_run = 15, - stand_start = 0, stand_end = 14, - walk_start = 15, walk_end = 38, - run_start = 40, run_end = 63, - punch_start = 40, punch_end = 63, + speed_normal = 15, + speed_run = 15, + stand_start = 0, + stand_end = 14, + walk_start = 15, + walk_end = 38, + run_start = 40, + run_end = 63, + punch_start = 40, + punch_end = 63, }, }) + -- spawn on dirt_with_grass and drygrass between -1 and 5 light, 1 in 10000 change, 1 dirt monster in area up to 31000 in height mobs:spawn_specific("mobs:dirt_monster", {"default:dirt_with_grass", "default:dirt_with_dry_grass"}, {"air"}, -1, 5, 30, 10000, 1, -31000, 31000, false) -- register spawn egg diff --git a/mods/mobs/dungeonmaster.lua b/mods/mobs/dungeonmaster.lua index c18f622a..658affbd 100755 --- a/mods/mobs/dungeonmaster.lua +++ b/mods/mobs/dungeonmaster.lua @@ -60,12 +60,17 @@ mobs:register_mob("mobs:dungeon_master", { water_damage = 1, lava_damage = 1, light_damage = 0, + fear_height = 3, -- model animation animation = { - stand_start = 0, stand_end = 19, - walk_start = 20, walk_end = 35, - punch_start = 36, punch_end = 48, - speed_normal = 15, speed_run = 15, + stand_start = 0, + stand_end = 19, + walk_start = 20, + walk_end = 35, + punch_start = 36, + punch_end = 48, + speed_normal = 15, + speed_run = 15, }, }) -- spawn on stone between 20 and -1 light, 1 in 7000 chance, 1 dungeon master in area starting at -100 and below diff --git a/mods/mobs/kitten.lua b/mods/mobs/kitten.lua index b1f9e290..6fcd254f 100755 --- a/mods/mobs/kitten.lua +++ b/mods/mobs/kitten.lua @@ -36,11 +36,14 @@ mobs:register_mob("mobs:kitten", { -- damaged by water_damage = 1, lava_damage = 5, + fear_height = 3, -- model animation animation = { speed_normal = 42, - stand_start = 97, stand_end = 192, - walk_start = 0, walk_end = 96, + stand_start = 97, + stand_end = 192, + walk_start = 0, + walk_end = 96, }, -- follows Rat and Raw Fish follow = {"mobs:rat", "ethereal:fish_raw"}, diff --git a/mods/mobs/lava_flan.lua b/mods/mobs/lava_flan.lua index 5ff7203e..83466150 100755 --- a/mods/mobs/lava_flan.lua +++ b/mods/mobs/lava_flan.lua @@ -45,11 +45,16 @@ mobs:register_mob("mobs:lava_flan", { light_damage = 0, -- model animation animation = { - speed_normal = 15, speed_run = 15, - stand_start = 0, stand_end = 8, - walk_start = 10, walk_end = 18, - run_start = 20, run_end = 28, - punch_start = 20, punch_end = 28, + speed_normal = 15, + speed_run = 15, + stand_start = 0, + stand_end = 8, + walk_start = 10, + walk_end = 18, + run_start = 20, + run_end = 28, + punch_start = 20, + punch_end = 28, }, -- do things when die on_die = function(self, pos) diff --git a/mods/mobs/npc.lua b/mods/mobs/npc.lua index 20681268..dac2c58d 100755 --- a/mods/mobs/npc.lua +++ b/mods/mobs/npc.lua @@ -65,16 +65,23 @@ mobs:register_mob("mobs:npc", { -- set owner and order owner = "", order = "follow", + fear_height = 3, -- model animation animation = { - speed_normal = 30, speed_run = 30, - stand_start = 0, stand_end = 79, - walk_start = 168, walk_end = 187, - run_start = 168, run_end = 187, - punch_start = 200, punch_end = 219, + speed_normal = 30, + speed_run = 30, + stand_start = 0, + stand_end = 79, + walk_start = 168, + walk_end = 187, + run_start = 168, + run_end = 187, + punch_start = 200, + punch_end = 219, }, -- right clicking with "cooked meat" or "bread" will give npc more health on_rightclick = function(self, clicker) + local item = clicker:get_wielded_item() local name = clicker:get_player_name() if item:get_name() == "default:diamond" then --/MFF (Crabman|07/14/2015) tamed with diamond @@ -102,7 +109,7 @@ mobs:register_mob("mobs:npc", { local pos = self.object:getpos() pos.y = pos.y + 0.5 minetest.add_item(pos, { - name = mobs.npc_drops[math.random(1,#mobs.npc_drops)] + name = mobs.npc_drops[math.random(1, #mobs.npc_drops)] }) return -- if owner switch between follow and stand diff --git a/mods/mobs/npc_female.lua b/mods/mobs/npc_female.lua index 130b9a48..ab0318be 100755 --- a/mods/mobs/npc_female.lua +++ b/mods/mobs/npc_female.lua @@ -69,16 +69,23 @@ mobs:register_mob("mobs:npc_female", { -- set owner and order owner = "", order = "follow", + fear_height = 3, -- model animation animation = { - speed_normal = 30, speed_run = 30, - stand_start = 0, stand_end = 79, - walk_start = 168, walk_end = 187, - run_start = 168, run_end = 187, - punch_start = 200, punch_end = 219, + speed_normal = 30, + speed_run = 30, + stand_start = 0, + stand_end = 79, + walk_start = 168, + walk_end = 187, + run_start = 168, + run_end = 187, + punch_start = 200, + punch_end = 219, }, -- right clicking with "cooked meat" or "bread" will give npc more health on_rightclick = function(self, clicker) + local item = clicker:get_wielded_item() local name = clicker:get_player_name() if item:get_name() == "default:diamond" then --/MFF (Crabman|07/14/2015) tamed with diamond @@ -105,7 +112,9 @@ mobs:register_mob("mobs:npc_female", { end local pos = self.object:getpos() pos.y = pos.y + 0.5 - minetest.add_item(pos, {name = mobs.npc_drops[math.random(1,#mobs.npc_drops)]}) + minetest.add_item(pos, { + name = mobs.npc_drops[math.random(1, #mobs.npc_drops)] + }) return -- if owner switch between follow and stand elseif self.owner and self.owner == clicker:get_player_name() then diff --git a/mods/mobs/oerkki.lua b/mods/mobs/oerkki.lua index 34eb53aa..e8f4a02a 100755 --- a/mods/mobs/oerkki.lua +++ b/mods/mobs/oerkki.lua @@ -46,11 +46,16 @@ mobs:register_mob("mobs:oerkki", { light_damage = 1, -- model animation animation = { - stand_start = 0, stand_end = 23, - walk_start = 24, walk_end = 36, - run_start = 37, run_end = 49, - punch_start = 37, punch_end = 49, - speed_normal = 15, speed_run = 15, + stand_start = 0, + stand_end = 23, + walk_start = 24, + walk_end = 36, + run_start = 37, + run_end = 49, + punch_start = 37, + punch_end = 49, + speed_normal = 15, + speed_run = 15, }, -- replace torch with air (remove) replace_rate = 50, diff --git a/mods/mobs/rat.lua b/mods/mobs/rat.lua index 747fdbda..4cdb24b1 100755 --- a/mods/mobs/rat.lua +++ b/mods/mobs/rat.lua @@ -33,6 +33,7 @@ mobs:register_mob("mobs:rat", { water_damage = 0, lava_damage = 4, light_damage = 0, + fear_height = 2, -- right click to pick up rat on_rightclick = function(self, clicker) mobs:capture_mob(self, clicker, 25, 80, 0, true, nil) diff --git a/mods/mobs/sandmonster.lua b/mods/mobs/sandmonster.lua index 950fc7c8..335a0d68 100755 --- a/mods/mobs/sandmonster.lua +++ b/mods/mobs/sandmonster.lua @@ -43,13 +43,19 @@ mobs:register_mob("mobs:sand_monster", { water_damage = 3, lava_damage = 4, light_damage = 0, + fear_height = 3, -- model animation animation = { - speed_normal = 15, speed_run = 15, - stand_start = 0, stand_end = 39, - walk_start = 41, walk_end = 72, - run_start = 74, run_end = 105, - punch_start = 74, punch_end = 105, + speed_normal = 15, + speed_run = 15, + stand_start = 0, + stand_end = 39, + walk_start = 41, + walk_end = 72, + run_start = 74, + run_end = 105, + punch_start = 74, + punch_end = 105, }, }) -- spawns on desert sand between -1 and 20 light, 1 in 15000 chance, 1 sand monster in area up to 31000 in height diff --git a/mods/mobs/sheep.lua b/mods/mobs/sheep.lua index 160f5c19..7cd349d8 100755 --- a/mods/mobs/sheep.lua +++ b/mods/mobs/sheep.lua @@ -18,7 +18,8 @@ for _, col in ipairs(all_colours) do hp_max = 15, armor = 200, -- textures and model - collisionbox = {-0.4, -1, -0.4, 0.4, 0.3, 0.4}, + --collisionbox = {-0.4, -1, -0.4, 0.4, 0.3, 0.4}, + collisionbox = {-0.5, -1, -0.5, 0.5, 0.3, 0.5}, visual = "mesh", mesh = "mobs_sheep.b3d", textures = { @@ -49,9 +50,12 @@ for _, col in ipairs(all_colours) do light_damage = 0, -- model animation animation = { - speed_normal = 15, speed_run = 15, - stand_start = 0, stand_end = 80, - walk_start = 81, walk_end = 100, + speed_normal = 15, + speed_run = 15, + stand_start = 0, + stand_end = 80, + walk_start = 81, + walk_end = 100, }, follow = {"farming:wheat", "default:grass_5"}, view_range = 8, @@ -61,6 +65,7 @@ for _, col in ipairs(all_colours) do replace_with = "air", -- right click sheep to shear sheep and get wood, feed 8 wheat for wool to grow back replace_offset = -1, + fear_height = 3, on_rightclick = function(self, clicker) local shpcolor = string.split(self.name,"_")[2] if shpcolor =="dark" then @@ -89,7 +94,7 @@ for _, col in ipairs(all_colours) do if minetest.get_modpath("wool") then local pos = self.object:getpos() pos.y = pos.y + 0.5 - local obj = minetest.add_item(pos, ItemStack("wool:"..shpcolor.." "..math.random(2,3))) + local obj = minetest.add_item(pos, ItemStack("wool:"..shpcolor.." "..math.random(1,3))) if obj then obj:setvelocity({ x = math.random(-1,1), diff --git a/mods/mobs/spider.lua b/mods/mobs/spider.lua index 323f44c0..00f8fd07 100755 --- a/mods/mobs/spider.lua +++ b/mods/mobs/spider.lua @@ -20,7 +20,7 @@ mobs:register_mob("mobs:spider", { textures = { {"mobs_spider.png"}, }, - visual_size = {x=7,y=7}, + visual_size = {x = 7, y = 7}, blood_texture = "mobs_blood.png", -- sounds makes_footstep_sound = true, @@ -37,7 +37,7 @@ mobs:register_mob("mobs:spider", { view_range = 16, floats = 0, -- drops string with a chance of sandstone or crystal spike if Ethereal installed - drops = { + drops = { {name = "farming:string", chance = 2, min = 1, max = 3,}, {name = "mobs:meat_raw", @@ -51,11 +51,16 @@ mobs:register_mob("mobs:spider", { light_damage = 0, -- model animation animation = { - speed_normal = 15, speed_run = 15, - stand_start = 1, stand_end = 1, - walk_start = 20, walk_end = 40, - run_start = 20, run_end = 40, - punch_start = 50, punch_end = 90, + speed_normal = 15, + speed_run = 15, + stand_start = 1, + stand_end = 1, + walk_start = 20, + walk_end = 40, + run_start = 20, + run_end = 40, + punch_start = 50, + punch_end = 90, }, }) -- spawn on jungleleaves/jungletree, between 0 and 5 light, 1 in 10000 chance, 1 in area up to 31000 in height diff --git a/mods/mobs/stonemonster.lua b/mods/mobs/stonemonster.lua index f1147289..3f58b167 100755 --- a/mods/mobs/stonemonster.lua +++ b/mods/mobs/stonemonster.lua @@ -50,11 +50,16 @@ mobs:register_mob("mobs:stone_monster", { light_damage = 0, -- model animation animation = { - speed_normal = 15, speed_run = 15, - stand_start = 0, stand_end = 14, - walk_start = 15, walk_end = 38, - run_start = 40, run_end = 63, - punch_start = 40, punch_end = 63, + speed_normal = 15, + speed_run = 15, + stand_start = 0, + stand_end = 14, + walk_start = 15, + walk_end = 38, + run_start = 40, + run_end = 63, + punch_start = 40, + punch_end = 63, }, }) -- spawns on stone between -1 and 5 light, 1 in 7000 chance, 1 in area below -25 diff --git a/mods/mobs/treemonster.lua b/mods/mobs/treemonster.lua index 9717b0e5..1e5a2f64 100755 --- a/mods/mobs/treemonster.lua +++ b/mods/mobs/treemonster.lua @@ -51,11 +51,16 @@ mobs:register_mob("mobs:tree_monster", { fall_damage = 0, -- model animation animation = { - speed_normal = 15, speed_run = 15, - stand_start = 0, stand_end = 24, - walk_start = 25, walk_end = 47, - run_start = 48, run_end = 62, - punch_start = 48, punch_end = 62, + speed_normal = 15, + speed_run = 15, + stand_start = 0, + stand_end = 24, + walk_start = 25, + walk_end = 47, + run_start = 48, + run_end = 62, + punch_start = 48, + punch_end = 62, }, }) -- spawn on leaves and beech_leaves, between 0 and 5 light, 1 in 8000 chance, 1 in area up to 31000 in height diff --git a/mods/mobs/warthog.lua b/mods/mobs/warthog.lua index c36cc16c..9b9241b5 100755 --- a/mods/mobs/warthog.lua +++ b/mods/mobs/warthog.lua @@ -47,12 +47,16 @@ mobs:register_mob("mobs:pumba", { water_damage = 1, lava_damage = 5, light_damage = 0, + fear_height = 2, -- model animation animation = { speed_normal = 15, - stand_start = 25, stand_end = 55, - walk_start = 70, walk_end = 100, - punch_start = 70, punch_end = 100, + stand_start = 25, + stand_end = 55, + walk_start = 70, + walk_end = 100, + punch_start = 70, + punch_end = 100, }, -- can be tamed by feeding 8 wheat (will not attack when tamed) on_rightclick = function(self, clicker)