Added fall checks for cliff edges (thanks cmdskp)
parent
69bd7c6bd3
commit
a34bab3c7b
|
@ -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
|
||||
|
|
83
api.lua
83
api.lua
|
@ -1,4 +1,4 @@
|
|||
-- Mobs Api (15th December 2015)
|
||||
-- Mobs Api (18th December 2015)
|
||||
mobs = {}
|
||||
mobs.mod = "redo"
|
||||
|
||||
|
@ -234,6 +234,37 @@ 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
|
||||
|
||||
for height = self.fear_height, 0, -1 do
|
||||
|
||||
local nod = minetest.get_node_or_nil({
|
||||
x = pos.x + dir_x,
|
||||
y = ypos - height,
|
||||
z = pos.z + dir_z
|
||||
})
|
||||
|
||||
if nod
|
||||
and nod.name
|
||||
and nod.name ~= "air" then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- environmental damage (water, lava, fire, light)
|
||||
do_env_damage = function(self)
|
||||
|
||||
|
@ -306,9 +337,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)
|
||||
|
||||
|
@ -339,6 +371,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
|
||||
|
@ -600,6 +635,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 "",
|
||||
|
@ -631,8 +668,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 {},
|
||||
|
@ -668,6 +703,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)
|
||||
|
||||
|
@ -1081,15 +1117,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"
|
||||
|
@ -1147,8 +1180,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 = {
|
||||
|
@ -1160,14 +1198,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)
|
||||
|
@ -1385,8 +1424,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
|
||||
|
||||
|
@ -2217,4 +2262,4 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
|||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
|
@ -29,6 +29,7 @@ mobs:register_mob("mobs:bunny", {
|
|||
water_damage = 1,
|
||||
lava_damage = 4,
|
||||
light_damage = 0,
|
||||
fear_height = 2,
|
||||
animation = {
|
||||
speed_normal = 15,
|
||||
stand_start = 1,
|
||||
|
|
1
cow.lua
1
cow.lua
|
@ -49,6 +49,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()
|
||||
|
|
|
@ -32,6 +32,7 @@ mobs:register_mob("mobs:dirt_monster", {
|
|||
water_damage = 1,
|
||||
lava_damage = 5,
|
||||
light_damage = 2,
|
||||
fear_height = 3,
|
||||
animation = {
|
||||
speed_normal = 15,
|
||||
speed_run = 15,
|
||||
|
|
|
@ -43,6 +43,7 @@ mobs:register_mob("mobs:dungeon_master", {
|
|||
water_damage = 1,
|
||||
lava_damage = 1,
|
||||
light_damage = 0,
|
||||
fear_height = 3,
|
||||
animation = {
|
||||
stand_start = 0,
|
||||
stand_end = 19,
|
||||
|
|
|
@ -29,6 +29,7 @@ mobs:register_mob("mobs:kitten", {
|
|||
},
|
||||
water_damage = 1,
|
||||
lava_damage = 5,
|
||||
fear_height = 3,
|
||||
animation = {
|
||||
speed_normal = 42,
|
||||
stand_start = 97,
|
||||
|
|
1
npc.lua
1
npc.lua
|
@ -46,6 +46,7 @@ mobs:register_mob("mobs:npc", {
|
|||
view_range = 15,
|
||||
owner = "",
|
||||
order = "follow",
|
||||
fear_height = 3,
|
||||
animation = {
|
||||
speed_normal = 30,
|
||||
speed_run = 30,
|
||||
|
|
|
@ -32,6 +32,7 @@ mobs:register_mob("mobs:oerkki", {
|
|||
water_damage = 2,
|
||||
lava_damage = 4,
|
||||
light_damage = 1,
|
||||
fear_height = 3,
|
||||
animation = {
|
||||
stand_start = 0,
|
||||
stand_end = 23,
|
||||
|
|
1
rat.lua
1
rat.lua
|
@ -23,6 +23,7 @@ mobs:register_mob("mobs:rat", {
|
|||
water_damage = 0,
|
||||
lava_damage = 4,
|
||||
light_damage = 0,
|
||||
fear_height = 2,
|
||||
on_rightclick = function(self, clicker)
|
||||
mobs:capture_mob(self, clicker, 25, 80, 0, true, nil)
|
||||
end,
|
||||
|
|
|
@ -32,6 +32,7 @@ mobs:register_mob("mobs:sand_monster", {
|
|||
water_damage = 3,
|
||||
lava_damage = 4,
|
||||
light_damage = 0,
|
||||
fear_height = 3,
|
||||
animation = {
|
||||
speed_normal = 15,
|
||||
speed_run = 15,
|
||||
|
|
|
@ -14,7 +14,8 @@ for _, col in ipairs(all_colours) do
|
|||
hp_min = 8,
|
||||
hp_max = 10,
|
||||
armor = 200,
|
||||
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 = {
|
||||
|
@ -51,6 +52,7 @@ for _, col in ipairs(all_colours) do
|
|||
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
|
||||
replace_with = "air",
|
||||
replace_offset = -1,
|
||||
fear_height = 3,
|
||||
on_rightclick = function(self, clicker)
|
||||
local shpcolor = string.split(self.name,"_")[2]
|
||||
if shpcolor =="dark" then
|
||||
|
@ -170,4 +172,4 @@ minetest.register_entity("mobs:sheep", {
|
|||
end
|
||||
end,
|
||||
|
||||
})
|
||||
})
|
||||
|
|
|
@ -34,6 +34,7 @@ mobs:register_mob("mobs:pumba", {
|
|||
water_damage = 1,
|
||||
lava_damage = 5,
|
||||
light_damage = 0,
|
||||
fear_height = 2,
|
||||
animation = {
|
||||
speed_normal = 15,
|
||||
stand_start = 25,
|
||||
|
|
Loading…
Reference in New Issue