From 72bf4d89ba53cb658735dd918d03bbe00cb35289 Mon Sep 17 00:00:00 2001 From: kepler155c Date: Wed, 17 Oct 2018 20:13:32 -0400 Subject: [PATCH] new cow breeder app --- apps/cows.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/cows.lua b/apps/cows.lua index 393c0f2..03fb319 100644 --- a/apps/cows.lua +++ b/apps/cows.lua @@ -5,6 +5,7 @@ local Util = require('util') local device = _G.device local os = _G.os +local term = _G.term local turtle = _G.turtle local config = { @@ -19,12 +20,20 @@ local sensor = device['plethora:sensor'] or local function getCowCount() local blocks = sensor.sense() + local grown = 0 + local babies = 0 + Util.filterInplace(blocks, function(v) if v.name == 'Cow' then + grown = grown + (v.y > -.5) and 1 or 0 + babies = babies + (v.y < -.5) and 1 or 0 return v.y > -.5 end end) + term.clearLine() + Util.print('%d grown, %d babies', grown, babies) + return #blocks end