Skip to content

Instantly share code, notes, and snippets.

@danielevans
Last active December 18, 2015 18:49
Show Gist options
  • Save danielevans/5828524 to your computer and use it in GitHub Desktop.
Save danielevans/5828524 to your computer and use it in GitHub Desktop.
A Crafty Turtle script designed for use with Equivalent Exchange to compress large amounts of material.
-- CRAFTY TURTLE + EQUIVALENT EXCHANGE COMPRESSION SCRIPT
-- 0.4.1
-- DANIEL EVANS
-- LATEST VERSION AT https://gist.github.com/danielevans/5828524
-----------------------------------
-- CONFIGURATION
-----------------------------------
local InSlots = {1,2,5,6}
local InDirection = "down"; -- "up" || "down" || "forward"
local OutDirection = "forward"; -- "up" || "down" || "forward"
-- probably don't need to change these
local OutSlot = 16
local KillSlots = {4, 8, 12, 13, 14, 15} -- anything in these slots will cause the turtle to stop and the program to exit
-----------------------------------
-- CODE
-----------------------------------
print("Starting Up")
local shouldQuit = function ()
for i=1,#KillSlots do
if turtle.getItemCount(KillSlots[i]) >= 1 then
print("Exit Condition Detected on Slot: " .. KillSlots[i])
return true
end
end
end
local suck = function ()
s = {
["up"] = function () turtle.suckUp(); end,
["down"] = function () turtle.suckDown(); end,
["forward"] = function () turtle.suck(); end
}
s[InDirection]()
end
local drop = function ()
d = {
["up"] = function () turtle.dropUp(); end,
["down"] = function () turtle.dropDown(); end,
["forward"] = function () turtle.drop(); end
}
d[OutDirection]()
end
while true do
if shouldQuit() then
return
end
-- suck in all the required slots
for i=1,#InSlots do
turtle.select(InSlots[i])
while turtle.getItemCount(InSlots[i]) == 0 do
suck()
end
end
turtle.select(OutSlot)
local keepCrafting = true
while keepCrafting do
if shouldQuit() then
return
end
-- make sure we have all the input items
-- prevents "sub" recipes from being crafted
for i=1,#InSlots do
keepCrafting = keepCrafting and turtle.getItemCount(InSlots[i]) > 0
end
-- try to dump the crafted item to the output chest.
keepCrafting = keepCrafting and turtle.craft()
while keepCrafting and turtle.getItemCount(OutSlot) > 0 do
drop()
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment