mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 02:21:06 +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()
|
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,47 +133,39 @@ 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
|
||||||
-- 1/8 chance to spawn a chick
|
if not self._lastpos.x then
|
||||||
-- FIXME: Chicks have a quite good chance to spawn in walls
|
self._lastpos = pos
|
||||||
local r = math.random(1,8)
|
end
|
||||||
|
-- 1/8 chance to spawn a chick
|
||||||
|
-- FIXME: Chicks have a quite good chance to spawn in walls
|
||||||
|
if math.random(1,8) == 1 then
|
||||||
|
mcl_mobs.spawn_child(self._lastpos, "mobs_mc:chicken")
|
||||||
|
|
||||||
if r == 1 then
|
-- BONUS ROUND: 1/32 chance to spawn 3 additional chicks
|
||||||
mcl_mobs.spawn_child(self._lastpos, "mobs_mc:chicken")
|
if math.random(1,32) == 1 then
|
||||||
|
local offsets = {
|
||||||
-- BONUS ROUND: 1/32 chance to spawn 3 additional chicks
|
{ x=0.7, y=0, z=0 },
|
||||||
local r = math.random(1,32)
|
{ x=-0.7, y=0, z=-0.7 },
|
||||||
if r == 1 then
|
{ x=-0.7, y=0, z=0.7 },
|
||||||
local offsets = {
|
}
|
||||||
{ x=0.7, y=0, z=0 },
|
for o=1, 3 do
|
||||||
{ x=-0.7, y=0, z=-0.7 },
|
local pos = vector.add(self._lastpos, offsets[o])
|
||||||
{ x=-0.7, y=0, z=0.7 },
|
mcl_mobs.spawn_child(pos, "mobs_mc:chicken")
|
||||||
}
|
|
||||||
for o=1, 3 do
|
|
||||||
local pos = vector.add(self._lastpos, offsets[o])
|
|
||||||
mcl_mobs.spawn_child(pos, "mobs_mc:chicken")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.sound_play("mcl_throwing_egg_impact", { pos = self.object:get_pos(), max_hear_distance=10, gain=0.5 }, true)
|
|
||||||
self.object:remove()
|
|
||||||
if mod_target and node.name == "mcl_target:target_off" then
|
|
||||||
mcl_target.hit(vector.round(pos), 0.4) --4 redstone ticks
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
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)
|
minetest.sound_play("mcl_throwing_egg_impact", { pos = self.object:get_pos(), max_hear_distance=10, gain=0.5 }, true)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
if mod_target and node.name == "mcl_target:target_off" then
|
||||||
|
mcl_target.hit(vector.round(pos), 0.4) --4 redstone ticks
|
||||||
|
end
|
||||||
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 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 a new issue