Posted 11 July 2014 - 07:21 PM
Hi, this is my first LUA program as well as the first time I'm using ComputerCraft.
(I used to use RP2 Computers back in 1.2.5, though I haven't played since then since RP2 was my favorite mod so there was no point playing Minecraft without it given Eloraam's lack of [significant] updates since then.. But RP3 is being worked on, so rejoice! :P/>)
As such my programming is EXTREMELY rusty, and my long-term memory is reproachable, so if I made any mistakes feel free to let me know/correct them. ^.^
So what this program is meant to do, is have a Mining Turtle indefinitely mine and deposit it's yield into an Ender Chest in its Inventory. I'd have a Chunk Loader Module on it, or a separate Turtle with one tailing it. (I plan to start with 3 of these Turtles, for an even 9x9 mining path.)
Setup: There will be a logistics system in my base constantly keeping an Ender Chest supplied with exactly 32 pieces of Coal (half a Stack.)
Turtle Inventory (by slotNum):
1) Coal
2) Coal Ender Chest
3) Mining Deposit Ender Chest
What it does: Basically it mines up, down, and in front of it, depositing into the corresponding Ender Chest when an Item is placed into the 13th Inventory Slot (I chose that Slot because at maximum, if the Turtle was to mine 3 unique Items that wouldn't stack, or any other prior stacks of them were full, it'd get 3 Slots filled up mining up/down/front making it full.)
Once the Fuel level reaches below 10 (an arbitrary number I chose, but it should be fine, I think..) and if the Coal in Slot 1 has run out (become 1, so that there is always one there to keep the Slot occupied.) the Turtle will attempt to pull 32 Coal from the corresponding Ender Chest, and if it cannot, it will Sleep for 5 minutes (hopefully to give the Logistics system back at the base time to restock the Coal.)
And without further ado, here is the code (It will be in the startup, so that it can run/pick up where it left off after the World/Chunk comes back up):
Pastebin: http://pastebin.com/6p3fEx3L
Feel free to tell me what you think, and if there are any corrections or improvements you might have.
Thanks. ^.^
(I used to use RP2 Computers back in 1.2.5, though I haven't played since then since RP2 was my favorite mod so there was no point playing Minecraft without it given Eloraam's lack of [significant] updates since then.. But RP3 is being worked on, so rejoice! :P/>)
As such my programming is EXTREMELY rusty, and my long-term memory is reproachable, so if I made any mistakes feel free to let me know/correct them. ^.^
So what this program is meant to do, is have a Mining Turtle indefinitely mine and deposit it's yield into an Ender Chest in its Inventory. I'd have a Chunk Loader Module on it, or a separate Turtle with one tailing it. (I plan to start with 3 of these Turtles, for an even 9x9 mining path.)
Setup: There will be a logistics system in my base constantly keeping an Ender Chest supplied with exactly 32 pieces of Coal (half a Stack.)
Turtle Inventory (by slotNum):
1) Coal
2) Coal Ender Chest
3) Mining Deposit Ender Chest
What it does: Basically it mines up, down, and in front of it, depositing into the corresponding Ender Chest when an Item is placed into the 13th Inventory Slot (I chose that Slot because at maximum, if the Turtle was to mine 3 unique Items that wouldn't stack, or any other prior stacks of them were full, it'd get 3 Slots filled up mining up/down/front making it full.)
Once the Fuel level reaches below 10 (an arbitrary number I chose, but it should be fine, I think..) and if the Coal in Slot 1 has run out (become 1, so that there is always one there to keep the Slot occupied.) the Turtle will attempt to pull 32 Coal from the corresponding Ender Chest, and if it cannot, it will Sleep for 5 minutes (hopefully to give the Logistics system back at the base time to restock the Coal.)
And without further ado, here is the code (It will be in the startup, so that it can run/pick up where it left off after the World/Chunk comes back up):
Pastebin: http://pastebin.com/6p3fEx3L
Spoiler
function digCheck()
if turtle.detect() == true then
turtle.dig()
end
end
function digCheckUp()
if turtle.detectUp() == true then
turtle.digUp()
end
end
function digCheckDown()
if turtle.detectDown() == true then
turtle.digDown()
end
end
function gravCheck()
repeat
digCheck()
sleep(1)
until turtle.detect() == false
end
function mobCheck()
while not turtle.forward() do
sleep(1)
if turtle.detect() == false then
turtle.attack()
else
gravCheck()
end
end
end
function getCoal()
gravCheck()
turtle.select(2)
turtle.place()
turtle.suck()
turtle.dig()
end
function resupply()
if turtle.getFuelLevel() <= 10 then
if turtle.getSelectedSlot(1) == 1 then
getCoal()
while turtle.getSelectedSlot(1) < 33 do
sleep(300)
getCoal()
end
end
turtle.select(1)
turtle.refuel(32)
end
end
function deposit()
gravCheck()
turtle.select(3)
turtle.place()
for i = 4, 16 do
turtle.select(i)
turtle.drop()
end
turtle.dig()
end
function invCheck()
if turtle.getItemCount(13) >= 1 then
deposit()
end
end
function mine()
gravCheck()
digCheckUp()
digCheckDown()
mobCheck()
end
while true do
resupply()
invCheck()
mine()
end
Feel free to tell me what you think, and if there are any corrections or improvements you might have.
Thanks. ^.^
Edited on 11 July 2014 - 05:53 PM