Skip to content

Instantly share code, notes, and snippets.

@Kipjr
Created April 17, 2020 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kipjr/fb8642198be612624ef4a97d2173326f to your computer and use it in GitHub Desktop.
Save Kipjr/fb8642198be612624ef4a97d2173326f to your computer and use it in GitHub Desktop.
ComputerCraft/turtle_torch
--[[
Changelog
0.01 - Torch extract from mine.lua
--]]
--[[
--]]
-- Local Variables
-- Starting
local long = 0
local longCount = 0
local totalBlocks = 0
local coalNeeded = 0
local corrent = n
-- Inventory This Will Check At Start Code
local fuelCount = 0
local noFuelNeed = 0 -- if Config has fuel no need on
local error = 0 -- Error Code
local reCheck = 0 -- Recheck Code
local name_to = {"minecraft:torch"}
local name_fu = {"minecraft:coal","railcraft:fuel_coke"}
local item_to = 0
local item_fu = 0
local torchLen = 15 --interval of torches
local debug = 0
--General find function
-- find(name_ch)
-- return INT item_ch
local function find(item_name,item_pos)
if debug==1 then print("find") end
item_pos=item_pos or 0
repeat
--it had previous position
if item_pos~=0 then
if turtle.getItemCount(item_pos) > 2 then
-- nothing
end
-- default / not found
else
for i=1,16,1 do
if turtle.getItemCount(i)>0 then
for _,v in pairs(item_name) do
if turtle.getItemDetail(i).name == v then
item_pos = i
break
end
end
end
end
end
if item_pos == 0 then
print("[" .. table.concat(item_name,",") .. "] item not found")
end
until item_pos ~= 0
return item_pos
end
local function torch()
if debug==1 then print("torch") end
--places torch.
item_to=find(name_to)
if item_to ~=0 then
turtle.select(item_to)
turtle.turnLeft()
turtle.turnLeft()
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
--end
end
end
-- Checking
local function check()
if debug==1 then print("check") end
if noFuelNeed == 0 then
if fuelCount == 0 then
print("Turtle has no fuel")
print("Put fuel in a slot")
error = 1
else
print("Turtle has Fuel")
end
end
if error == 1 then
print("Items are missing please try again")
print("Turtle will recheck in 8 sec")
end
end
-- Recheck if user forget something turtle will check after 6 sec
local function reCheck()
if debug==1 then print("reCheck") end
chest = 0
fuelCount = 0
item_fu=find(name_fu)
if item_fu ~=0 then
fuelCount = turtle.getItemCount(item_fu)
end
error = 0
end
-- Refuel
local function refuel()
if debug==1 then print("refuel") end
if noFuelNeed == 0 then
repeat
if turtle.getFuelLevel() < 160 then
reCheck()
if fuelCount > 0 then
turtle.select(item_fu) --select 0 - out of range error if fuel is empty
turtle.refuel(1)
fuelCount = fuelCount - 1
else
print("out of fuel")
os.shutdown()
end
end
until turtle.getFuelLevel() >= 160
end
end
local function moveLong()
if debug==1 then print("long") end
if turtle.forward() then
longCount = longCount + 1
end
end
local function main()
repeat --Repeat for each level
moveLong()
refuel()
if longCount%torchLen == 1 then
torch()
end
if longCount == long then
print("turtle is Done")
end
end
local function start()
if num_params < 5 or num_params>6 then
print("Welcome To Torch Turtle Program")
print("Fill turtle with coal/charcoal/torches")
print("How long(Lenght) you want")
input = io.read()
print("Debug 1=True, 0=False")
input6 = io.read()
end
long = tonumber(input)
long = long - 1
input6b = tonumber(input6)
if input6b == 1 then
debug = 1
end
print("Check:" .. "Len:" .. (long + 1) .. string.char(10) .. "debug:" .. (debug))
print("Type y Or Y if it is correct and if not then n or N")
corrent = io.read()
if corrent == n or N then
os.reboot()
end
if turtle.getFuelLevel() == "unlimited" then
print("Your turtle config does need fuel")
noFuelNeed = 1
elseif turtle.getFuelLevel() < 160 then
turtle.select(2)
turtle.refuel(2)
end
reCheck()
check()
if error == 1 then
repeat
sleep(6)
reCheck()
check()
until error == 0
end
print("Turtle will now start!")
main()
end
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment