mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-25 03:51:05 +01:00
Make eggs spawn chicks when hitting entities (#4484)
Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/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
1 changed files with 26 additions and 34 deletions
|
@ -123,7 +123,7 @@ local function snowball_on_step(self, dtime)
|
|||
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
|
||||
self._lastpos = pos -- Set _lastpos-->Node will be added at last pos outside the node
|
||||
end
|
||||
|
||||
-- Movement function of egg
|
||||
|
@ -133,19 +133,19 @@ local function egg_on_step(self, dtime)
|
|||
local node = minetest.get_node(pos)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
|
||||
-- Destroy when hitting a solid node with chance to spawn chicks
|
||||
if self._lastpos.x then
|
||||
if (def and def.walkable) or not def then
|
||||
-- Destroy when hitting a solid node or entity, with chance to spawn chicks
|
||||
if (def and def.walkable) or not def or check_object_hit(self, pos, 0) 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
|
||||
-- FIXME: Chicks have a quite good chance to spawn in walls
|
||||
local r = math.random(1,8)
|
||||
|
||||
if r == 1 then
|
||||
if math.random(1,8) == 1 then
|
||||
mcl_mobs.spawn_child(self._lastpos, "mobs_mc:chicken")
|
||||
|
||||
-- BONUS ROUND: 1/32 chance to spawn 3 additional chicks
|
||||
local r = math.random(1,32)
|
||||
if r == 1 then
|
||||
if math.random(1,32) == 1 then
|
||||
local offsets = {
|
||||
{ x=0.7, y=0, z=0 },
|
||||
{ x=-0.7, y=0, z=-0.7 },
|
||||
|
@ -164,16 +164,8 @@ local function egg_on_step(self, dtime)
|
|||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Destroy when hitting a mob or player (no chick spawning)
|
||||
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
|
||||
self._lastpos = pos -- Set lastpos-->Node will be added at last pos outside the node
|
||||
end
|
||||
|
||||
-- Movement function of ender pearl
|
||||
|
@ -272,7 +264,7 @@ local function pearl_on_step(self, dtime)
|
|||
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
|
||||
|
||||
snowball_ENTITY.on_step = snowball_on_step
|
||||
|
|
Loading…
Reference in a new issue