From 924d3680c5a886e884a812ab22f243144781c2a9 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 20 Feb 2017 01:51:09 +0100 Subject: [PATCH] Improve spawning of 4 chicks by eggs a bit --- mods/ITEMS/mcl_throwing/throwable.lua | 46 ++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_throwing/throwable.lua b/mods/ITEMS/mcl_throwing/throwable.lua index 105e9f0cc1..70ce9d65c2 100644 --- a/mods/ITEMS/mcl_throwing/throwable.lua +++ b/mods/ITEMS/mcl_throwing/throwable.lua @@ -103,8 +103,8 @@ local pearl_ENTITY={ _thrower = nil, -- Player ObjectRef of the player who threw the ender pearl } --- Snowball and egg entity on_step()--> called when snowball is moving. -local on_step = function(self, dtime) +-- Snowball on_step()--> called when snowball is moving. +local snowball_on_step = function(self, dtime) self.timer=self.timer+dtime local pos = self.object:getpos() local node = minetest.get_node(pos) @@ -120,6 +120,44 @@ local on_step = function(self, dtime) self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set _lastpos-->Node will be added at last pos outside the node end +-- Movement function of egg +local egg_on_step = function(self, dtime) + self.timer=self.timer+dtime + local pos = self.object:getpos() + local node = minetest.get_node(pos) + local def = minetest.registered_nodes[node.name] + + -- Destroy when hitting a solid node + if self._lastpos.x~=nil then + if (def and def.walkable) or not def then + -- 1/8 chance to spawn a chick + -- FIXME: Spawn chicks instead of chickens + -- FIXME: Chicks have a quite good chance to spawn in walls + local r = math.random(1,8) + if r == 1 then + minetest.add_entity(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 + local offsets = { + { x=0.7, y=0, z=0 }, + { x=-0.7, y=0, z=-0.7 }, + { x=-0.7, y=0, z=0.7 }, + } + for o=1, 3 do + local pos = vector.add(self._lastpos, offsets[o]) + minetest.add_entity(pos, "mobs_mc:chicken") + end + end + end + self.object:remove() + 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 +end + -- Movement function of ender pearl local pearl_on_step = function(self, dtime) self.timer=self.timer+dtime @@ -143,8 +181,8 @@ local pearl_on_step = function(self, dtime) self._lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node end -snowball_ENTITY.on_step = on_step -egg_ENTITY.on_step = on_step +snowball_ENTITY.on_step = snowball_on_step +egg_ENTITY.on_step = egg_on_step pearl_ENTITY.on_step = pearl_on_step minetest.register_entity("mcl_throwing:snowball_entity", snowball_ENTITY)