This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
interface212's profile picture

Auto Item Smelter (Basic, UNDER 50 LINES) | Efficient way to smelt lots of items

Started by interface212, 17 April 2017 - 10:04 AM
interface212 #1
Posted 17 April 2017 - 12:04 PM
Auto Item Smelter (Basic, UNDER 50 LINES)

This started as a 250+ line program I made to smelt items from one chest into another, but then I started getting rid of alot of the functionality to drastically reduce it's line count and efficiency, it's now under 50 lines and has support for a variable amount of furnaces and different fuels.

If one furnace is done before the other however it cannot re-task it until all the furnaces are done which I cannot see an easy way to do without timers and tables containing how much time each one has left etc…

Pastebin: https://pastebin.com/x7FVCisU

Code:
Spoilerlocal efficiency = 8 –the amount of items each fuel item can smelt
local furnaces = 8 –the amount of furnaces the chef has (MAX 8)
local amounts = {}
function selectNext()
for i = 1, 16 do
if turtle.getItemCount(i) ~= 0 then
turtle.select(i)
return true
end
end
return false
end
while turtle.suck() do
for i = 2, furnaces do
table.insert(amounts, 0)
if not turtle.suck() then break end
end
for k, v in pairs(amounts) do
turtle.back()
amounts[k] = turtle.getItemCount()
turtle.dropDown()
end
while turtle.forward() do end
turtle.select(1)
turtle.down()
for k, v in pairs(amounts) do
turtle.suck(math.ceil(v/8))
end
turtle.down()
local biggestStack = 0
for k, v in pairs(amounts) do
if v > biggestStack then
biggestStack = v
end
turtle.back()
turtle.dropUp(math.ceil(v/8))
end
sleep(biggestStack*10)
for k, v in pairs(amounts) do
turtle.suckUp()
turtle.forward()
end
while selectNext() do turtle.drop() end
turtle.up()
turtle.up()
turtle.select(1)
end

Usage:
SpoilerPut three chests above eachother with the turtle facing the middle one, the put up to 8 furnaces behind the turtle.
Move the turtle up one space and run the program AFTER putting all the fuel + ore into the middle and top chest respectively. (SHOWN BELOW)
eniallator #2
Posted 24 April 2017 - 10:04 PM
First of all, nice program - looks good.

Next, since Lua does not have significant whitespace, the code can be minified to 1 line e.g using this minifier so having the program under 50 lines isn't necessarily good. For instance most of the time you trade readability for shorter code which isn't that great of a coding practice since code readability is pretty essential for working in teams (if you ever do).

Anyways, like i said it's a good program and for this instance it's quite readable so good job there. However you might want to skip a line every so often e.g if you want to see my code - here's my collision file from my game.