mc-scripts/stoneblock-3-chicken-breeder/betterbreeder.lua

123 lines
3.1 KiB
Lua
Raw Normal View History

2023-12-01 11:33:56 -06:00
-- See README for usage info
2023-12-01 11:34:59 -06:00
-- https://git.desu.ltd/salt/mc-scripts/src/branch/master/stoneblock-3-chicken-breeder/README.md
2023-12-01 11:33:56 -06:00
function placeBreeder()
print('Initializing breeder...')
breeder = peripheral.wrap('top')
-- First, we nab the new chicken in slot 1
turtle.select(1)
2023-12-01 12:14:25 -06:00
-- Check to see if this iteration obtained a new chicken
if turtle.suckUp() then
-- Then, we destroy the breeder
2023-12-01 17:00:25 -06:00
print('Placing breeder with new chicken')
2023-12-01 12:14:25 -06:00
turtle.select(2)
turtle.digUp()
-- We are now in a position where we have:
-- 1: Good chicken
-- 2: Inferior chicken
-- 3: Seeds/second inferior chicken
-- 4: Breeder/seeds
-- 5: Null/breeder
-- In any case, discarding 1 item in slot 2 will eliminate poor genes
--turtle.select(2) -- Unnecessary due to previous instr
turtle.dropDown(1)
else
-- Just pop the breeder for consistency
2023-12-01 17:00:25 -06:00
print('Placing breeder from scratch')
2023-12-01 12:14:25 -06:00
turtle.select(2)
turtle.digUp()
end
-- Now we re set-up the breeder
2023-12-01 11:33:56 -06:00
selectItem('chickens:breeder')
turtle.placeUp()
selectItem('minecraft:wheat_seeds')
turtle.dropUp()
pushBestChickens()
end
function selectItem(name)
for i = 1, 16, 1 do
if turtle.getItemDetail(i) then
if turtle.getItemDetail(i).name == name then
turtle.select(i)
return i
end
end
end
end
function pushBestChickens()
print('Selecting best chickens...')
chickens = 0
index = nil
for i = 16, 1, -1 do
print('Checking index ' .. i)
item = turtle.getItemDetail(i)
if item then
turtle.select(i)
if not i == 1 then
print('Discarding twin from breeding pair')
turtle.dropDown(item.count - 1)
end
if item.name == 'chickens:chicken_item' then
if item.count >= 16 then error('Done!') end
for i = 1, item.count, 1 do
if chickens == 0 then
print('Inserting first chicken')
turtle.dropUp(1)
chickens = chickens + 1
elseif chickens == 1 then
print('Inserting second chicken')
buffer = peripheral.wrap('front')
turtle.drop(1)
buffer.pushItems('top', 1, 16, 2)
chickens = chickens + 1
else
print('Discarding chicken')
turtle.dropDown()
end
end
end
end
end
end
function checkIfDone()
output = peripheral.wrap('bottom')
for i = 1, output.size(), 1 do
if output.getItemDetail(i) then
item = output.getItemDetail(i)
2023-12-01 18:57:09 -06:00
-- Magic number 3 here is determined as follows:
-- 1 from the offspring of this new generation
-- 2 from the breeding pair
if item.count == item.maxCount - 3 then
2023-12-01 11:33:56 -06:00
return true
end
end
end
return false
end
2023-12-01 17:00:25 -06:00
function cleanup()
print('Cleaning up...')
turtle.digUp()
for i = 1, 16, 1 do
turtle.select(i)
turtle.dropDown()
end
print('Cleanup complete')
end
2023-12-01 11:33:56 -06:00
local function main()
print('Initializing...')
while not checkIfDone() do
print('Iterating...')
placeBreeder()
sleep()
while peripheral.wrap('top').getItemDetail(4) == nil do sleep() end
end
2023-12-01 17:38:13 -06:00
cleanup()
2023-12-01 11:33:56 -06:00
print('Breeding complete')
end
main()