forked from VoxeLibre/VoxeLibre
Make eggs spawn chicks when hitting entities (#4484)
Reviewed-on: VoxeLibre/VoxeLibre#4484 Reviewed-by: Mikita Wiśniewski <rudzik8@protonmail.com> Co-authored-by: WillConker <willconker@noreply.git.minetest.land> Co-committed-by: WillConker <willconker@noreply.git.minetest.land>
This commit is contained in:
parent
9d5b46c28a
commit
ff21d1eab1
|
@ -123,7 +123,7 @@ local function snowball_on_step(self, dtime)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set _lastpos-->Node will be added at last pos outside the node
|
self._lastpos = pos -- Set _lastpos-->Node will be added at last pos outside the node
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Movement function of egg
|
-- Movement function of egg
|
||||||
|
@ -133,19 +133,19 @@ local function egg_on_step(self, dtime)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local def = minetest.registered_nodes[node.name]
|
local def = minetest.registered_nodes[node.name]
|
||||||
|
|
||||||
-- Destroy when hitting a solid node with chance to spawn chicks
|
-- Destroy when hitting a solid node or entity, with chance to spawn chicks
|
||||||
if self._lastpos.x then
|
if (def and def.walkable) or not def or check_object_hit(self, pos, 0) then
|
||||||
if (def and def.walkable) or not def then
|
-- If egg has just been thrown, use current position
|
||||||
|
if not self._lastpos.x then
|
||||||
|
self._lastpos = pos
|
||||||
|
end
|
||||||
-- 1/8 chance to spawn a chick
|
-- 1/8 chance to spawn a chick
|
||||||
-- FIXME: Chicks have a quite good chance to spawn in walls
|
-- FIXME: Chicks have a quite good chance to spawn in walls
|
||||||
local r = math.random(1,8)
|
if math.random(1,8) == 1 then
|
||||||
|
|
||||||
if r == 1 then
|
|
||||||
mcl_mobs.spawn_child(self._lastpos, "mobs_mc:chicken")
|
mcl_mobs.spawn_child(self._lastpos, "mobs_mc:chicken")
|
||||||
|
|
||||||
-- BONUS ROUND: 1/32 chance to spawn 3 additional chicks
|
-- BONUS ROUND: 1/32 chance to spawn 3 additional chicks
|
||||||
local r = math.random(1,32)
|
if math.random(1,32) == 1 then
|
||||||
if r == 1 then
|
|
||||||
local offsets = {
|
local offsets = {
|
||||||
{ x=0.7, y=0, z=0 },
|
{ x=0.7, y=0, z=0 },
|
||||||
{ x=-0.7, y=0, z=-0.7 },
|
{ x=-0.7, y=0, z=-0.7 },
|
||||||
|
@ -164,16 +164,8 @@ local function egg_on_step(self, dtime)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- Destroy when hitting a mob or player (no chick spawning)
|
self._lastpos = pos -- Set lastpos-->Node will be added at last pos outside the node
|
||||||
if check_object_hit(self, pos, 0) then
|
|
||||||
minetest.sound_play("mcl_throwing_egg_impact", { pos = self.object:get_pos(), max_hear_distance=10, gain=0.5 }, true)
|
|
||||||
self.object:remove()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Movement function of ender pearl
|
-- Movement function of ender pearl
|
||||||
|
@ -272,7 +264,7 @@ local function pearl_on_step(self, dtime)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node
|
self._lastpos = pos -- Set lastpos-->Node will be added at last pos outside the node
|
||||||
end
|
end
|
||||||
|
|
||||||
snowball_ENTITY.on_step = snowball_on_step
|
snowball_ENTITY.on_step = snowball_on_step
|
||||||
|
|
Loading…
Reference in New Issue