Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Chicken Cross Breeder
- Author - u/MistbornKnives
- Creates all possible chicken breeds from craftable chickens
- --]]
- local recipies = {
- ['String'] = {'Ink Black', 'Log'},
- ['Orange'] = {'Red', 'Yellow'},
- ['Cyan'] = {'Lapis Lazuli', 'Cactus Green'},
- ['Lead'] = {'Iron', 'Cyan'},
- ['Coal'] = {'Flint', 'Log'},
- ['Snowball'] = {'Lapis Lazuli', 'Log'},
- ['Nether Wart'] = {'Cocoa Brown', 'Glowstone'},
- ['Ender Pearl'] = {'Diamond', 'Nether Wart'},
- ['Zinc'] = {'Iron', 'Cactus Green'},
- ['Light Blue'] = {'Bone Meal', 'Lapis Lazuli'},
- ['Glass'] = {'Nether Quartz', 'Redstone'},
- ['Magenta'] = {'Purple', 'Pink'},
- ['Ghast Tear'] = {'Bone Meal', 'Blaze Rod'},
- ['Blaze Rod'] = {'Gold', 'Lava'},
- ['Nickel'] = {'Bone Meal', 'Cactus Green'},
- ['Gunpowder'] = {'Sand', 'Flint'},
- ['Uranium'] = {'Redstone', 'Ender Pearl'},
- ['Lime'] = {'Cactus Green', 'Bone Meal'},
- ['Netherite'] = {'Cobalt', 'Gold'},
- ['Magma Cream'] = {'Slime', 'Blaze Rod'},
- ['Copper'] = {'Yellow', 'Cocoa Brown'},
- ['Obsidian'] = {'Water','Lava'},
- ['Glowstone'] = {'Nether Quartz', 'Yellow'},
- ['Light Gray'] = {'Gray', 'Bone Meal'},
- ['Pink'] = {'Red', 'Bone Meal'},
- ['Prismarine Shard'] = {'Water', 'Lapis Lazuli'},
- ['Water'] = {'Gunpowder', 'Snowball'},
- ['Gray'] = {'Ink Black', 'Bone Meal'},
- ['Tin'] = {'Bone Meal', 'Clay'},
- ['Aluminum'] = {'Flint', 'Iron'},
- ['Osmium'] = {'Iron', 'Nether Quartz'},
- ['Redstone'] = {'Red', 'Sand'},
- ['Slime'] = {'Clay', 'Cactus Green'},
- ['Emerald'] = {'Diamond', 'Cactus Green'},
- ['Cocoa Brown'] = {'Red', 'Cactus Green'},
- ['Purple'] = {'Lapis Lazuli', 'Red'},
- ['Cobalt'] = {'Nether Wart', 'Ghast Tear'},
- ['Silver'] = {'Iron', 'Bone Meal'},
- ['Lava'] = {'Coal', 'Nether Quartz'},
- ['Prismarine Crystal'] = {'Water', 'Emerald'},
- ['Gold'] = {'Iron', 'Yellow'},
- ['Leather'] = {'String', 'Cocoa Brown'},
- ['Iron'] = {'Flint', 'Bone Meal'},
- ['Clay'] = {'Snowball', 'Sand'},
- ['Diamond'] = {'Glass', 'Gold'},
- }
- local elementaries = {
- 'Cactus Green',
- 'Bone Meal',
- 'Red',
- 'Flint',
- 'Soul Sand',
- 'Lapis Lazuli',
- 'Yellow',
- 'Nether Quartz',
- 'Log',
- 'Sand',
- 'Ink Black',
- }
- local seeds = {
- 'Wheat Seeds',
- 'Pumpkin Seeds',
- 'Melon Seeds',
- 'Beetroot Seeds',
- 'Industrial Hemp Seeds',
- 'Cabbage Seeds',
- 'Tomato Seeds',
- 'Flax Seeds',
- 'Rice',
- 'Magebloom Seed'
- }
- local seeds = {
- 'minecraft:wheat_seeds',
- 'minecraft:pumpkin_seeds',
- 'minecraft:melon_seeds',
- 'minecraft:beetroot_seeds',
- 'immersiveengineering:seed',
- 'farmersdelight:cabbage_seeds',
- 'farmersdelight:tomato_seeds',
- 'supplementaries:flax_seeds',
- 'farmersdelight:rice',
- 'ars_nouveau:magebloom_crop'
- }
- local completed_chickens = {}
- breeder = peripheral.wrap('top')
- function main(target)
- term.clear()
- inventory_scan()
- reset()
- warn()
- if target then breed(target) end
- for k, _ in pairs(recipies) do
- if not valueExistsArray(completed_chickens, k) then
- breed(k)
- end
- end
- reset()
- end
- function inventory_scan()
- completed_chickens = {}
- inventory = peripheral.wrap('front')
- if not inventory then error('Place an inventory in front of turtle') end
- for slot, item in pairs(inventory.list()) do
- local chicken, _ = shorten(inventory.getItemDetail(slot).displayName)
- if item.name == "chickens:chicken_item" and
- (item.count >= 2 or valueExistsArray(elementaries, chicken)) then
- table.insert(completed_chickens, chicken)
- end
- end
- end
- function warn()
- term.setTextColor(colors.orange)
- if inventory.size() < 56 then
- print('Need at least 56 inventory slots to fit all chickens')
- end
- missing_warning()
- term.setTextColor(colors.white)
- end
- function reset()
- local _, reason = turtle.digUp()
- if reason == "No tool to dig with" then
- error("Turtle needs an equiped pickaxe")
- end
- if turtle.select_item('chickens:breeder') == nil then
- error('Missing Breeder')
- end
- while not turtle.placeUp() do os.sleep() end
- os.sleep()
- breeder = nil
- while breeder == nil do
- breeder = peripheral.wrap('top')
- end
- if breeder.getItemDetail(3) == nil then
- insert_seeds()
- end
- while turtle.select_item('chickens:chicken_item') do
- turtle.drop()
- end
- -- for i=16, 1, -1 do
- -- turtle.drop()
- -- end
- end
- function missing_warning()
- local missing = {}
- for _, chicken in ipairs(elementaries) do
- if not valueExistsArray(completed_chickens, chicken) then
- table.insert(missing, chicken)
- end
- end
- if #missing ~= 0 then
- io.write('Missing:\n')
- for _, value in ipairs(missing) do
- io.write(value .. ', ')
- end
- io.write('\n')
- end
- end
- function breed(target)
- reset()
- print(target)
- for _, parent in ipairs(recipies[target]) do
- if not pushItems(parent) then
- if valueExistsArray(elementaries, parent) then
- print('Missing ' .. parent)
- return false
- else
- if not breed(parent) then
- return false
- end
- return breed(target)
- end
- end
- end
- local success_count = 0
- repeat
- while turtle.getItemCount(turtle.getSelectedSlot()) ~= 0 do
- turtle.select(turtle.getSelectedSlot() % 16 + 1)
- end
- if breeder.getItemDetail(3) == nil then
- if not insert_seeds() then
- print('Waiting for seeds')
- end
- while breeder.getItemDetail(3) == nil do
- insert_seeds()
- sleep()
- end
- end
- while turtle.getItemCount(turtle.getSelectedSlot()) == 0 do
- turtle.suckUp()
- sleep()
- end
- local detail = turtle.getItemDetail(turtle.getSelectedSlot(), true)
- if shorten(detail.displayName) == target then
- success_count = success_count + 1
- else
- turtle.dropUp()
- turtle.dropDown()
- end
- until success_count >= 2
- table.insert(completed_chickens, target)
- return true
- end
- function insert_seeds()
- for _, seed in ipairs(seeds) do
- if turtle.select_item(seed) then
- turtle.dropUp()
- return true
- else
- if pushItems(seed) then
- return true
- end
- end
- end
- return false
- end
- function valueExistsArray(table, value)
- for _, v in ipairs(table) do
- if v == value then
- return true
- end
- end
- return false
- end
- function turtle.select_item(name)
- for i = 1, 16 do
- local detail = turtle.getItemDetail(i)
- if detail then
- if detail.name == name then
- turtle.select(i)
- return i
- end
- end
- end
- end
- function shorten(displayName)
- chicken_type, _ = string.gsub(displayName, ' Chicken', '')
- return chicken_type
- end
- function sleep()
- os.sleep(0.05)
- end
- function pushItems(name)
- for slot, item in pairs(inventory.list()) do
- if shorten(inventory.getItemDetail(slot).displayName) == name or
- item.name == name then
- return inventory.pushItems('top', slot) > 0
- end
- end
- return false
- end
- main(({...})[1])
Add Comment
Please, Sign In to add comment