From 7b17e756f9a84c4438f3aa0afe11ebcbd77293cc Mon Sep 17 00:00:00 2001 From: kepler155c Date: Thu, 29 Nov 2018 15:13:36 -0500 Subject: [PATCH] farm chorus fruit --- farms/farmer.lua | 31 ++++++++++++++++++++++++++--- milo/core/listing.lua | 45 +++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/farms/farmer.lua b/farms/farmer.lua index 877d1a0..fd888e6 100644 --- a/farms/farmer.lua +++ b/farms/farmer.lua @@ -9,7 +9,8 @@ local os = _G.os local peripheral = _G.peripheral local turtle = _G.turtle -local CONFIG_FILE = 'usr/config/farm' +local CONFIG_FILE = 'usr/config/farmer' +local STARTUP_FILE = 'usr/autorun/farmer.lua' local scanner = device['plethora:scanner'] or turtle.equip('right', 'plethora:module:2') and device['plethora:scanner'] or @@ -27,16 +28,25 @@ local crops = Util.readTable(CONFIG_FILE) or { ['minecraft:cocoa'] = { seed = 'minecraft:dye:3', mature = 8, action = 'pick' }, ['minecraft:reeds'] = { action = 'bash' }, + ['minecraft:chorus_flower'] = { action = 'bash' }, + ['minecraft:chorus_plant'] = + { seed = 'minecraft:chorus_flower', mature = 0, action = 'bash-smash', }, ['minecraft:melon_block'] = { action = 'smash' }, ['minecraft:pumpkin'] = { action = 'smash' }, ['minecraft:chest'] = { action = 'drop' }, - ['minecraft:cactus'] = { action = 'bump' }, + ['minecraft:cactus'] = { action = 'smash' }, } if not fs.exists(CONFIG_FILE) then Util.writeTable(CONFIG_FILE, crops) end +if not fs.exists(STARTUP_FILE) then + Util.writeFile(STARTUP_FILE, + [[os.sleep(1) +shell.openForegroundTab('packages/farms/farmer.lua')]]) +end + local retain = Util.transpose { "minecraft:diamond_pickaxe", "plethora:module:2", @@ -70,6 +80,16 @@ local function scan() if b.action == 'drop' then return doDropOff and b.y == -1 end + if b.action == 'bash-smash' then + if b.y == -1 then + b.action = 'smash' + end + if b.y == 0 then + b.action = 'bash' + end + return b.action ~= 'bash-smash' + end + if b.action == 'smash' then return b.y == -1 end @@ -128,7 +148,12 @@ local function harvest(blocks) end elseif b.action == 'smash' then - turtle.digDownAt(b) + if turtle.digDownAt(b) then + if crops[b.name].seed then + turtle.placeDown(crops[b.name].seed) + turtle.select(1) + end + end elseif b.action == 'plant' then if turtle.digDownAt(b) then diff --git a/milo/core/listing.lua b/milo/core/listing.lua index fe678fc..22141ed 100644 --- a/milo/core/listing.lua +++ b/milo/core/listing.lua @@ -1,5 +1,4 @@ local Craft = require('craft2') -local itemDB = require('itemDB') local Event = require('event') local Milo = require('milo') local Sound = require('sound') @@ -14,35 +13,12 @@ local string = _G.string local displayModes = { [0] = { text = 'A', help = 'Showing all items' }, [1] = { text = 'I', help = 'Showing inventory items' }, - [2] = { text = 'C', help = 'Showing craftable items' }, } -local function filterItems(t, filter) - if filter or displayMode > 0 then - local r = { } - if filter then - filter = filter:lower() - end - for _,v in pairs(t) do - if not filter or string.find(v.lname, filter, 1, true) then - if not displayMode or - displayMode == 0 or - displayMode == 1 and v.count > 0 or - displayMode == 2 and v.has_recipe then - table.insert(r, v) - end - end - end - return r - end - return t -end - local listingPage = UI.Page { menuBar = UI.MenuBar { buttons = { { text = 'Learn', event = 'learn' }, - --{ text = 'Forget', event = 'forget' }, { text = 'Craft', event = 'craft' }, { text = 'Edit', event = 'details' }, { text = 'Refresh', event = 'refresh', x = -12 }, @@ -222,7 +198,7 @@ function listingPage:eventHandler(event) self:setFocus(self.statusBar.filter) elseif event.type == 'toggle_display' then - displayMode = (displayMode + 1) % 3 + displayMode = (displayMode + 1) % 2 Util.merge(event.button, displayModes[displayMode]) event.button:draw() self:applyFilter() @@ -308,6 +284,25 @@ function listingPage:refresh(force) end function listingPage:applyFilter() + local function filterItems(t, filter) + if filter or displayMode > 0 then + local r = { } + if filter then + filter = filter:lower() + end + for _,v in pairs(t) do + if not filter or string.find(v.lname, filter, 1, true) then + if displayMode == 0 or + displayMode == 1 and v.count > 0 then + table.insert(r, v) + end + end + end + return r + end + return t + end + local t = filterItems(self.allItems, self.filter) self.grid:setValues(t) end