Advertisement
TwoThe

OC LootCombiner

Jul 11th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. local robot = require("robot")
  2. local component = require("component")
  3. local sides = require("sides")
  4. local ic = component.inventory_controller
  5. local crafting = component.crafting
  6.  
  7. local sideChest = sides.front
  8. local sideTrash = sides.down
  9. local maximumWaste = 1.20
  10.  
  11. local isRepairable = {
  12.     ["minecraft:chainmail_helmet"] = true, ["minecraft:chainmail_chestplate"] = true, ["minecraft:chainmail_leggings"] = true,
  13.     ["minecraft:iron_helmet"] = true, ["minecraft:iron_chestplate"] = true, ["minecraft:iron_leggings"] = true,
  14.     ["minecraft:golden_helmet"] = true, ["minecraft:golden_chestplate"] = true, ["minecraft:golden_leggings"] = true,
  15.     ["minecraft:diamond_helmet"] = true, ["minecraft:diamond_chestplate"] = true, ["minecraft:diamond_leggings"] = true,
  16.     ["minecraft:iron_sword"] = true, ["minecraft:golden_sword"] = true, ["minecraft:diamond_sword"] = true,
  17.     ["minecraft:iron_shovel"] = true, ["minecraft:iron_pickaxe"] = true, ["minecraft:iron_axe"] = true,
  18.     ["minecraft:golden_shovel"] = true, ["minecraft:golden_pickaxe"] = true, ["minecraft:golden_axe"] = true,
  19.     ["minecraft:diamond_shovel"] = true, ["minecraft:diamond_pickaxe"] = true, ["minecraft:diamond_axe"] = true,
  20. }
  21. local isTrash = { ["minecraft:bow"] = true, ["minecraft:arrow"] = true,  ["minecraft:bone"] = true, ["minecraft:rotten_flesh"] = true, ["minecraft:spider_eye"] = true, }
  22. local isFuel = { ["minecraft:coal"] = true }
  23.  
  24. local sizeChest = ic.getInventorySize(sideChest)
  25. local currentSlot = 1
  26.  
  27. local trashItem = function(inSlot)
  28.   robot.select(1)
  29.   ic.suckFromSlot(sideChest, inSlot)
  30.   robot.dropDown()
  31. end
  32.  
  33. local addFuel = function(inSlot, theItem)
  34. end
  35.  
  36. local durabilityAcceptable = function(item1, item2)
  37.   return true
  38. --  local d1 = item1.maxDamage - item1.damage
  39. --  local d2 = item2.maxDamage - item2.damage
  40. --  return ((d1 + d2) / item1.maxDamage) <= maximumWaste
  41. end
  42.  
  43. local tryRepairItem = function(inSlot, baseItem)
  44.   local other
  45.   for slot = 1,sizeChest do
  46.     if (slot ~= inSlot) then
  47.       other = ic.getStackInSlot(sideChest, slot)
  48.       if ((other ~= nil) and (other.damage > 0) and (other.name == baseItem.name) and durabilityAcceptable(baseItem, other)) then
  49.         robot.select(1)
  50.         ic.suckFromSlot(sideChest, inSlot)
  51.         robot.select(2)
  52.         ic.suckFromSlot(sideChest, slot)
  53.         crafting.craft()
  54.         robot.drop()
  55.         robot.select(1)
  56.         robot.drop()
  57.         return true
  58.       end
  59.     end
  60.   end
  61. end
  62.  
  63. local running = true
  64. local item
  65.  
  66. while (running) do
  67.   item = ic.getStackInSlot(sideChest, currentSlot)
  68.   if (item ~= nil) then
  69.     print("Found:", item.name, "in slot", currentSlot)
  70.     if (isTrash[item.name]) then
  71.       print("Trashing...")
  72.       trashItem(currentSlot)
  73.     elseif (isFuel[item.name]) then
  74.       print("Taking as fuel...")
  75.       addFuel(currentSlot, item)
  76.     elseif (isRepairable[item.name] and (item.damage > 0)) then
  77.       print("Try to repair...")
  78.       tryRepairItem(currentSlot, item)
  79.     end
  80.   end
  81.   currentSlot = currentSlot + 1
  82.   if currentSlot > sizeChest then
  83.     currentSlot = 1
  84.     print("Sleeping for 5 seconds...")
  85.     os.sleep(5)
  86.   end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement