Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local component = require("component")
- local sides = require("sides")
- local ic = component.inventory_controller
- local crafting = component.crafting
- local sideChest = sides.front
- local sideTrash = sides.down
- local maximumWaste = 1.20
- local isRepairable = {
- ["minecraft:chainmail_helmet"] = true, ["minecraft:chainmail_chestplate"] = true, ["minecraft:chainmail_leggings"] = true,
- ["minecraft:iron_helmet"] = true, ["minecraft:iron_chestplate"] = true, ["minecraft:iron_leggings"] = true,
- ["minecraft:golden_helmet"] = true, ["minecraft:golden_chestplate"] = true, ["minecraft:golden_leggings"] = true,
- ["minecraft:diamond_helmet"] = true, ["minecraft:diamond_chestplate"] = true, ["minecraft:diamond_leggings"] = true,
- ["minecraft:iron_sword"] = true, ["minecraft:golden_sword"] = true, ["minecraft:diamond_sword"] = true,
- ["minecraft:iron_shovel"] = true, ["minecraft:iron_pickaxe"] = true, ["minecraft:iron_axe"] = true,
- ["minecraft:golden_shovel"] = true, ["minecraft:golden_pickaxe"] = true, ["minecraft:golden_axe"] = true,
- ["minecraft:diamond_shovel"] = true, ["minecraft:diamond_pickaxe"] = true, ["minecraft:diamond_axe"] = true,
- }
- local isTrash = { ["minecraft:bow"] = true, ["minecraft:arrow"] = true, ["minecraft:bone"] = true, ["minecraft:rotten_flesh"] = true, ["minecraft:spider_eye"] = true, }
- local isFuel = { ["minecraft:coal"] = true }
- local sizeChest = ic.getInventorySize(sideChest)
- local currentSlot = 1
- local trashItem = function(inSlot)
- robot.select(1)
- ic.suckFromSlot(sideChest, inSlot)
- robot.dropDown()
- end
- local addFuel = function(inSlot, theItem)
- end
- local durabilityAcceptable = function(item1, item2)
- return true
- -- local d1 = item1.maxDamage - item1.damage
- -- local d2 = item2.maxDamage - item2.damage
- -- return ((d1 + d2) / item1.maxDamage) <= maximumWaste
- end
- local tryRepairItem = function(inSlot, baseItem)
- local other
- for slot = 1,sizeChest do
- if (slot ~= inSlot) then
- other = ic.getStackInSlot(sideChest, slot)
- if ((other ~= nil) and (other.damage > 0) and (other.name == baseItem.name) and durabilityAcceptable(baseItem, other)) then
- robot.select(1)
- ic.suckFromSlot(sideChest, inSlot)
- robot.select(2)
- ic.suckFromSlot(sideChest, slot)
- crafting.craft()
- robot.drop()
- robot.select(1)
- robot.drop()
- return true
- end
- end
- end
- end
- local running = true
- local item
- while (running) do
- item = ic.getStackInSlot(sideChest, currentSlot)
- if (item ~= nil) then
- print("Found:", item.name, "in slot", currentSlot)
- if (isTrash[item.name]) then
- print("Trashing...")
- trashItem(currentSlot)
- elseif (isFuel[item.name]) then
- print("Taking as fuel...")
- addFuel(currentSlot, item)
- elseif (isRepairable[item.name] and (item.damage > 0)) then
- print("Try to repair...")
- tryRepairItem(currentSlot, item)
- end
- end
- currentSlot = currentSlot + 1
- if currentSlot > sizeChest then
- currentSlot = 1
- print("Sleeping for 5 seconds...")
- os.sleep(5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement