1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-12-25 02:00:21 +01:00

added fence check to stop mobs walking forwards

This commit is contained in:
TenPlus1 2017-08-11 10:46:03 +01:00
parent ba167a3451
commit 4d80e58a2c

35
api.lua
View File

@ -1,9 +1,9 @@
-- Mobs Api (7th August 2017) -- Mobs Api (11th August 2017)
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
mobs.version = "20170807" mobs.version = "20170811"
-- Intllib -- Intllib
@ -670,6 +670,8 @@ local do_jump = function(self)
return false return false
end end
self.facing_fence = false
-- something stopping us while moving? -- something stopping us while moving?
if self.state ~= "stand" if self.state ~= "stand"
and get_velocity(self) > 0.5 and get_velocity(self) > 0.5
@ -709,20 +711,24 @@ local do_jump = function(self)
--print ("in front:", nod.name, pos.y + 0.5) --print ("in front:", nod.name, pos.y + 0.5)
if (minetest.registered_items[nod.name].walkable if self.walk_chance == 0
and not nod.name:find("fence") or minetest.registered_items[nod.name].walkable then
and not nod.name:find("gate"))
or self.walk_chance == 0 then
local v = self.object:getvelocity() if not nod.name:find("fence")
and not nod.name:find("gate") then
v.y = self.jump_height local v = self.object:getvelocity()
set_animation(self, "jump") -- only when defined v.y = self.jump_height
self.object:setvelocity(v) set_animation(self, "jump") -- only when defined
mob_sound(self, self.sounds.jump) self.object:setvelocity(v)
mob_sound(self, self.sounds.jump)
else
self.facing_fence = true
end
return true return true
end end
@ -753,7 +759,7 @@ local entity_physics = function(pos, radius)
objs[n]:punch(objs[n], 1.0, { objs[n]:punch(objs[n], 1.0, {
full_punch_interval = 1.0, full_punch_interval = 1.0,
damage_groups = {fleshy = damage}, damage_groups = {fleshy = damage},
}, pos) -- was nil }, pos)
end end
end end
@ -1491,6 +1497,7 @@ local do_states = function(self, dtime)
or self.order ~= "stand" then or self.order ~= "stand" then
if self.walk_chance ~= 0 if self.walk_chance ~= 0
and self.facing_fence ~= true
and random(1, 100) <= self.walk_chance and random(1, 100) <= self.walk_chance
and is_at_cliff(self) == false then and is_at_cliff(self) == false then
@ -1590,7 +1597,8 @@ local do_states = function(self, dtime)
-- stand for great fall in front -- stand for great fall in front
local temp_is_cliff = is_at_cliff(self) local temp_is_cliff = is_at_cliff(self)
if temp_is_cliff if self.facing_fence == true
or temp_is_cliff
or random(1, 100) <= 30 then or random(1, 100) <= 30 then
set_velocity(self, 0) set_velocity(self, 0)
@ -2676,6 +2684,7 @@ minetest.register_entity(name, {
attack_animals = def.attack_animals or false, attack_animals = def.attack_animals or false,
specific_attack = def.specific_attack, specific_attack = def.specific_attack,
owner_loyal = def.owner_loyal, owner_loyal = def.owner_loyal,
facing_fence = false,
_cmi_is_mob = true, _cmi_is_mob = true,
on_blast = def.on_blast or do_tnt, on_blast = def.on_blast or do_tnt,