Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jelly = "forestry:royal_jelly"
- wax = "forestry:beeswax"
- pollen = "forestry:pollen"
- planks = "minecraft:planks"
- waxCount = 0
- pollenCount = 0
- jellyCount = 0
- planksCount = 0
- totalPossible = 0
- craftAmountPerCarpenter = 27
- craftAmountRemaining = 0;
- carpentersArray = {}
- turtlePosition = 1
- currentCarpenter = 1
- realPositions = {}
- chest = peripheral.wrap("bottom")
- carpentersthiscycle = 0
- function main()
- while true do
- os.sleep(1)
- if next(chest.list()) ~= nil then
- os.sleep(20)
- processOneCraftingJob()
- end
- end
- end
- function processOneCraftingJob()
- setupArray()
- fillInventory()
- countItems()
- while true do
- if carpentersthiscycle == 8 then
- carpentersthiscycle = 0
- countItems()
- end
- currentCarpenter = findEmptiestCarpenter()
- if(craftAmountRemaining == 0) then
- restock();
- if(craftAmountRemaining == 0) then
- dumpInventory()
- break
- end
- end
- goToCarpenter(currentCarpenter)
- local itemsToCraftInThis = craftAmountPerCarpenter
- if itemsToCraftInThis > craftAmountRemaining then
- itemsToCraftInThis = craftAmountRemaining
- end
- print("crafting " .. itemsToCraftInThis .. " in carpenter " .. currentCarpenter)
- pushItems(itemsToCraftInThis,currentCarpenter)
- carpentersthiscycle = carpentersthiscycle + 1
- end
- end
- function findEmptiestCarpenter()
- emptiest = 1
- lowestAmount = 10000
- for i=1,8,1 do
- if carpentersArray[i] < lowestAmount then
- emptiest = i
- lowestAmount = carpentersArray[i]
- if lowestAmount == 0 then
- break
- end
- end
- end
- return emptiest
- end
- function goToCarpenter(carpenterNumber)
- carpenterNumber = realPositions[carpenterNumber]
- if turtlePosition > carpenterNumber then
- turtle.turnLeft();
- while turtlePosition > carpenterNumber do
- turtle.forward();
- turtlePosition = turtlePosition - 1
- end
- turtle.turnRight();
- end
- if turtlePosition < carpenterNumber then
- turtle.turnRight();
- while turtlePosition < carpenterNumber do
- turtle.forward();
- turtlePosition = turtlePosition + 1
- end
- turtle.turnLeft();
- end
- end
- function restock()
- goToCarpenter(1)
- fillInventory()
- countItems()
- carpentersthiscycle = 0
- end
- function setupArray()
- for i=1,8,1 do
- carpentersArray[i] = 0
- end
- realPositions[5] = 0
- realPositions[6] = -1
- realPositions[7] = -2
- realPositions[8] = -3
- realPositions[1] = 1
- realPositions[2] = 2
- realPositions[3] = 3
- realPositions[4] = 4
- end
- function countItems()
- waxCount = 0
- pollenCount = 0
- jellyCount = 0
- planksCount = 0
- for i=1,16,1 do
- local meta = turtle.getItemDetail(i)
- if(meta ~= nil and meta.name == jelly) then
- jellyCount = jellyCount + meta.count
- end
- if(meta ~= nil and meta.name == wax) then
- waxCount = waxCount + meta.count
- end
- if(meta ~= nil and meta.name == pollen) then
- pollenCount = pollenCount + meta.count
- end
- if(meta ~= nil and meta.name == planks) then
- planksCount = planksCount + meta.count
- end
- end
- totalPossible = jellyCount
- if totalPossible > pollenCount then
- totalPossible = pollenCount
- end
- if totalPossible > (math.floor(waxCount / 2)) then
- totalPossible = (math.floor(waxCount / 2))
- end
- if totalPossible > (math.floor(planksCount / 3)) then
- totalPossible = (math.floor(planksCount / 3))
- end
- craftAmountRemaining = totalPossible
- print ("craftAmountRemaining: " .. craftAmountRemaining)
- craftAmountPerCarpenter = math.floor(craftAmountRemaining / 8)
- if craftAmountPerCarpenter == 0 then
- craftAmountPerCarpenter = 1
- end
- print ("craftAmountPerCarpenter: " .. craftAmountPerCarpenter)
- end
- function fillInventory()
- for i=1,16,1 do
- turtle.select(i)
- turtle.suckDown()
- end
- end
- function dumpInventory()
- for i=1,16,1 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- function findJelly()
- for i=1,16,1 do
- local meta = turtle.getItemDetail(i)
- if(meta ~= nil and meta.name == jelly) then
- return i
- end
- end
- end
- function findWax()
- for i=1,16,1 do
- local meta = turtle.getItemDetail(i)
- if(meta ~= nil and meta.name == wax) then
- return i
- end
- end
- end
- function findPollen()
- for i=1,16,1 do
- local meta = turtle.getItemDetail(i)
- if(meta ~= nil and meta.name == pollen) then
- return i
- end
- end
- end
- function findPlanks()
- for i=1,16,1 do
- local meta = turtle.getItemDetail(i)
- if(meta ~= nil and meta.name == planks) then
- return i
- end
- end
- end
- function pushJelly(amountToCraft)
- local targetAmount = amountToCraft
- while targetAmount > 0 do
- local slot = findJelly()
- turtle.select(slot)
- local currentStack = turtle.getItemCount()
- if currentStack > targetAmount then
- currentStack = targetAmount
- end
- turtle.drop(currentStack)
- targetAmount = targetAmount - currentStack
- end
- end
- function pushPollen(amountToCraft)
- local targetAmount = amountToCraft
- while targetAmount > 0 do
- local slot = findPollen()
- turtle.select(slot)
- local currentStack = turtle.getItemCount()
- if currentStack > targetAmount then
- currentStack = targetAmount
- end
- turtle.drop(currentStack)
- targetAmount = targetAmount - currentStack
- end
- end
- function pushWax(amountToCraft)
- local targetAmount = amountToCraft * 2
- while targetAmount > 0 do
- local slot = findWax()
- turtle.select(slot)
- local currentStack = turtle.getItemCount()
- if currentStack > targetAmount then
- currentStack = targetAmount
- end
- turtle.drop(currentStack)
- targetAmount = targetAmount - currentStack
- end
- end
- function pushPlanks(amountToCraft)
- local targetAmount = amountToCraft * 3
- while targetAmount > 0 do
- local slot = findPlanks()
- turtle.select(slot)
- local currentStack = turtle.getItemCount()
- if currentStack > targetAmount then
- currentStack = targetAmount
- end
- turtle.drop(currentStack)
- targetAmount = targetAmount - currentStack
- end
- end
- function pushItems(amountToCraft, carpenterNumber)
- pushJelly(amountToCraft)
- pushPlanks(amountToCraft)
- pushPollen(amountToCraft)
- pushWax(amountToCraft)
- carpentersArray[carpenterNumber] = carpentersArray[carpenterNumber] + amountToCraft
- print ("set carpenter " .. carpenterNumber .. " to " .. carpentersArray[carpenterNumber].. " items completed")
- craftAmountRemaining = craftAmountRemaining - amountToCraft
- print ("craftAmountRemaining: " .. craftAmountRemaining)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement