farms - improvements
This commit is contained in:
@@ -4,8 +4,20 @@
|
|||||||
icon = "\030 \031f \0305 \030 \030d \030 \
|
icon = "\030 \031f \0305 \030 \030d \030 \
|
||||||
\0305\031f \030d \030 \030d \0305 \030d \
|
\0305\031f \030d \030 \030d \0305 \030d \
|
||||||
\030 \031f \030c \030 \0304 \030 \030c \030 ",
|
\030 \031f \030c \030 \0304 \030 \030c \030 ",
|
||||||
category = "Apps",
|
category = "Farms",
|
||||||
run = "treefarm.lua",
|
run = "treefarm.lua",
|
||||||
requires = "turtle",
|
requires = "turtle",
|
||||||
},
|
},
|
||||||
|
[ "ff892e4e9538168021ccf2c7add8a46bf97fb180" ] = {
|
||||||
|
title = "Rancher",
|
||||||
|
category = "Farms",
|
||||||
|
run = "rancher.lua",
|
||||||
|
requires = "turtle",
|
||||||
|
},
|
||||||
|
[ "e5c4e470299e30c9eea1e25de228c14db8c1fd40" ] = {
|
||||||
|
title = "Farmer",
|
||||||
|
category = "Farms",
|
||||||
|
run = "farmer.lua",
|
||||||
|
requires = "turtle",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
_G.requireInjector(_ENV)
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
local InventoryAdapter = require('chestAdapter18')
|
local Adapter = require('chestAdapter18')
|
||||||
local Peripheral = require('peripheral')
|
local Peripheral = require('peripheral')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
local fs = _G.fs
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
|
local STARTUP_FILE = 'usr/autorun/rancher.lua'
|
||||||
|
|
||||||
local retain = Util.transpose {
|
local retain = Util.transpose {
|
||||||
'minecraft:shears',
|
'minecraft:shears',
|
||||||
'minecraft_wheat',
|
'minecraft:wheat',
|
||||||
'minecraft:diamond_sword',
|
'minecraft:diamond_sword',
|
||||||
'plethora:module:3',
|
'plethora:module:3',
|
||||||
}
|
}
|
||||||
@@ -21,9 +24,56 @@ local config = {
|
|||||||
}
|
}
|
||||||
Config.load('rancher', config)
|
Config.load('rancher', config)
|
||||||
|
|
||||||
local sensor = device['plethora:sensor'] or
|
local ANIMALS = {
|
||||||
turtle.equip('right', 'plethora:module:3') and device['plethora:sensor'] or
|
Pig = { min = 0, food = 'minecraft:carrot' },
|
||||||
error('Plethora sensor required')
|
Sheep = { min = .5, food = 'minecraft:wheat' },
|
||||||
|
Cow = { min = .5, food = 'minecraft:wheat' },
|
||||||
|
}
|
||||||
|
|
||||||
|
local animal = ANIMALS[config.animal]
|
||||||
|
|
||||||
|
local function equip(side, item, rawName)
|
||||||
|
local equipped = Peripheral.lookup('side/' .. side)
|
||||||
|
|
||||||
|
if equipped and equipped.type == item then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if not turtle.equip(side, rawName or item) then
|
||||||
|
if not turtle.selectSlotWithQuantity(0) then
|
||||||
|
error('No slots available')
|
||||||
|
end
|
||||||
|
turtle.equip(side)
|
||||||
|
if not turtle.equip(side, item) then
|
||||||
|
error('Unable to equip ' .. item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
turtle.select(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getLocalName()
|
||||||
|
if not device.wired_modem then
|
||||||
|
error('wired modem or chest not found')
|
||||||
|
end
|
||||||
|
return device.wired_modem.getNameLocal()
|
||||||
|
end
|
||||||
|
|
||||||
|
equip('left', 'minecraft:diamond_sword')
|
||||||
|
equip('right', 'plethora:sensor', 'plethora:module:3')
|
||||||
|
|
||||||
|
local sensor = device['plethora:sensor']
|
||||||
|
local c = Peripheral.lookup('type/minecraft:chest') or error('Missing chest')
|
||||||
|
|
||||||
|
local directions = { top = 'down', bottom = 'up' }
|
||||||
|
local direction = directions[c.side] or getLocalName()
|
||||||
|
local chest = Adapter({ side = c.side, direction = direction }) or error('missing chest')
|
||||||
|
_G._p = chest
|
||||||
|
if not fs.exists(STARTUP_FILE) then
|
||||||
|
Util.writeFile(STARTUP_FILE,
|
||||||
|
[[os.sleep(1)
|
||||||
|
shell.openForegroundTab('packages/farms/rancher.lua')]])
|
||||||
|
end
|
||||||
|
|
||||||
local dispenser = Peripheral.lookup('type/minecraft:dispenser')
|
local dispenser = Peripheral.lookup('type/minecraft:dispenser')
|
||||||
local integrator = Peripheral.lookup('type/redstone_integrator')
|
local integrator = Peripheral.lookup('type/redstone_integrator')
|
||||||
@@ -87,8 +137,7 @@ local function butcher()
|
|||||||
|
|
||||||
turtle.eachFilledSlot(function(slot)
|
turtle.eachFilledSlot(function(slot)
|
||||||
if not retain[slot.name] then
|
if not retain[slot.name] then
|
||||||
turtle.select(slot.index)
|
chest:insert(slot.index, 64)
|
||||||
turtle.dropUp()
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -109,9 +158,6 @@ local function breed()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local chest = InventoryAdapter({ side = 'top', direction = 'down' }) or
|
|
||||||
error('missing chest above')
|
|
||||||
|
|
||||||
local s, m = turtle.run(function()
|
local s, m = turtle.run(function()
|
||||||
turnOffWater()
|
turnOffWater()
|
||||||
|
|
||||||
@@ -120,9 +166,10 @@ local s, m = turtle.run(function()
|
|||||||
if animalCount > config.max_animals then
|
if animalCount > config.max_animals then
|
||||||
turtle.setStatus('Butchering')
|
turtle.setStatus('Butchering')
|
||||||
butcher()
|
butcher()
|
||||||
elseif turtle.getItemCount('minecraft:wheat') == 0 then
|
elseif turtle.getItemCount(animal.food) == 0 then
|
||||||
if chest:provide({ name = 'minecraft:wheat' }, 64) == 0 then
|
if chest:provide({ name = animal.food, damage = 0 }, 64) == 0 then
|
||||||
turtle.setStatus('Out of wheat')
|
print('Out of ' .. animal.food)
|
||||||
|
turtle.setStatus('Out of food')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
turtle.setStatus('Breeding')
|
turtle.setStatus('Breeding')
|
||||||
|
|||||||
@@ -23,10 +23,13 @@ _G.requireInjector()
|
|||||||
local Point = require('point')
|
local Point = require('point')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
|
local fs = _G.fs
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local read = _G.read
|
local read = _G.read
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
|
local STARTUP_FILE = 'usr/autorun/treefarm.lua'
|
||||||
|
|
||||||
local FUEL_BASE = 0
|
local FUEL_BASE = 0
|
||||||
local FUEL_DIRE = FUEL_BASE + 10
|
local FUEL_DIRE = FUEL_BASE + 10
|
||||||
local FUEL_GOOD = FUEL_BASE + 2000
|
local FUEL_GOOD = FUEL_BASE + 2000
|
||||||
@@ -75,6 +78,12 @@ local state = Util.readTable('usr/config/treefarm') or {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if not fs.exists(STARTUP_FILE) then
|
||||||
|
Util.writeFile(STARTUP_FILE,
|
||||||
|
[[os.sleep(1)
|
||||||
|
shell.openForegroundTab('packages/farms/treefarm.lua')]])
|
||||||
|
end
|
||||||
|
|
||||||
local clock = os.clock()
|
local clock = os.clock()
|
||||||
|
|
||||||
local function inspect(fn)
|
local function inspect(fn)
|
||||||
|
|||||||
Reference in New Issue
Block a user