tweaks + simplify rancher (no xp collection)
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local Adapter = require('chestAdapter18')
|
local Adapter = require('chestAdapter18')
|
||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
local Peripheral = require('peripheral')
|
local Peripheral = require('peripheral')
|
||||||
@@ -52,22 +50,12 @@ local function equip(side, item, rawName)
|
|||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
end
|
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('left', 'minecraft:diamond_sword')
|
||||||
equip('right', 'plethora:sensor', 'plethora:module:3')
|
equip('right', 'plethora:sensor', 'plethora:module:3')
|
||||||
|
|
||||||
local sensor = device['plethora:sensor']
|
local sensor = device['plethora:sensor']
|
||||||
local c = Peripheral.lookup('type/minecraft:chest') or error('Missing chest')
|
|
||||||
|
|
||||||
local directions = { top = 'down', bottom = 'up' }
|
local chest = Adapter({ side = 'bottom', direction = 'up' }) or error('missing chest')
|
||||||
local direction = directions[c.side] or getLocalName()
|
|
||||||
local chest = Adapter({ side = c.side, direction = direction }) or error('missing chest')
|
|
||||||
|
|
||||||
if not fs.exists(STARTUP_FILE) then
|
if not fs.exists(STARTUP_FILE) then
|
||||||
Util.writeFile(STARTUP_FILE,
|
Util.writeFile(STARTUP_FILE,
|
||||||
@@ -76,53 +64,23 @@ shell.openForegroundTab('rancher.lua')]])
|
|||||||
print('Autorun program created: ' .. STARTUP_FILE)
|
print('Autorun program created: ' .. STARTUP_FILE)
|
||||||
end
|
end
|
||||||
|
|
||||||
local dispenser = Peripheral.lookup('type/minecraft:dispenser')
|
|
||||||
local integrator = Peripheral.lookup('type/redstone_integrator')
|
|
||||||
|
|
||||||
local function pulse()
|
|
||||||
integrator.setOutput('north', true)
|
|
||||||
os.sleep(.25)
|
|
||||||
integrator.setOutput('north', false)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function turnOffWater()
|
|
||||||
if dispenser then
|
|
||||||
local list = dispenser.list()
|
|
||||||
if list[1].name == 'minecraft:bucket' then
|
|
||||||
pulse()
|
|
||||||
os.sleep(2)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function turnOnWater()
|
|
||||||
if dispenser then
|
|
||||||
if dispenser.list()[1].name == 'minecraft:water_bucket' then
|
|
||||||
pulse()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function getAnimalCount()
|
local function getAnimalCount()
|
||||||
local blocks = sensor.sense()
|
local blocks = sensor.sense()
|
||||||
|
|
||||||
local grown = 0
|
local grown = 0
|
||||||
local babies = 0
|
local babies = 0
|
||||||
local xpCount = 0
|
|
||||||
|
|
||||||
Util.filterInplace(blocks, function(v)
|
Util.filterInplace(blocks, function(v)
|
||||||
if v.name == config.animal then
|
if v.name == config.animal then
|
||||||
if v.y > -.5 then grown = grown + 1 end
|
if v.y > -.5 then grown = grown + 1 end
|
||||||
if v.y < -.5 then babies = babies + 1 end
|
if v.y < -.5 then babies = babies + 1 end
|
||||||
return v.y > -.5
|
return v.y > -.5
|
||||||
elseif v.name == 'XPOrb' then
|
|
||||||
xpCount = xpCount + 1
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Util.print('%d grown, %d babies, %d xp', grown, babies, xpCount)
|
Util.print('%d grown, %d babies', grown, babies)
|
||||||
|
|
||||||
return #blocks, xpCount
|
return #blocks
|
||||||
end
|
end
|
||||||
|
|
||||||
local function butcher()
|
local function butcher()
|
||||||
@@ -160,10 +118,10 @@ local function breed()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local s, m = turtle.run(function()
|
local s, m = turtle.run(function()
|
||||||
turnOffWater()
|
print('Configured animal: ' .. config.animal)
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
local animalCount, xpCount = getAnimalCount()
|
local animalCount = getAnimalCount()
|
||||||
if animalCount > config.max_animals then
|
if animalCount > config.max_animals then
|
||||||
turtle.setStatus('Butchering')
|
turtle.setStatus('Butchering')
|
||||||
butcher()
|
butcher()
|
||||||
@@ -176,11 +134,6 @@ local s, m = turtle.run(function()
|
|||||||
turtle.setStatus('Breeding')
|
turtle.setStatus('Breeding')
|
||||||
breed()
|
breed()
|
||||||
end
|
end
|
||||||
if xpCount > 2 then
|
|
||||||
turnOnWater()
|
|
||||||
os.sleep(8)
|
|
||||||
turnOffWater()
|
|
||||||
end
|
|
||||||
os.sleep(5)
|
os.sleep(5)
|
||||||
until turtle.isAborted()
|
until turtle.isAborted()
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ local function findDroppedSaplings()
|
|||||||
local sensed = Util.reduce(raw, function(acc, b)
|
local sensed = Util.reduce(raw, function(acc, b)
|
||||||
Point.rotate(b, state.home.heading)
|
Point.rotate(b, state.home.heading)
|
||||||
b.x = Util.round(b.x) + turtle.point.x
|
b.x = Util.round(b.x) + turtle.point.x
|
||||||
b.y = math.floor(b.y) + turtle.point.y
|
b.y = math.ceil(b.y) + turtle.point.y
|
||||||
b.z = Util.round(b.z) + turtle.point.z
|
b.z = Util.round(b.z) + turtle.point.z
|
||||||
if b.y == 0 and string.find(b.displayName, 'sapling', 1, true) then
|
if b.y == 0 and string.find(b.displayName, 'sapling', 1, true) then
|
||||||
b.sapling = true
|
b.sapling = true
|
||||||
|
|||||||
@@ -57,17 +57,15 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
function craftTask:cycle()
|
function craftTask:cycle()
|
||||||
local playSound = true
|
|
||||||
|
|
||||||
for _,key in pairs(Util.keys(context.craftingQueue)) do
|
for _,key in pairs(Util.keys(context.craftingQueue)) do
|
||||||
local item = context.craftingQueue[key]
|
local item = context.craftingQueue[key]
|
||||||
if item.requested - item.crafted > 0 then
|
if item.requested - item.crafted > 0 then
|
||||||
local recipe = Craft.findRecipe(key)
|
local recipe = Craft.findRecipe(key)
|
||||||
if recipe then
|
if recipe then
|
||||||
|
|
||||||
if playSound then
|
if not item.playedSound then
|
||||||
Sound.play('entity.experience_orb.pickup')
|
Sound.play('entity.experience_orb.pickup')
|
||||||
playSound = false
|
item.playedSound = true
|
||||||
end
|
end
|
||||||
|
|
||||||
self:craft(recipe, item)
|
self:craft(recipe, item)
|
||||||
|
|||||||
Reference in New Issue
Block a user