Compare commits

...

17 Commits

Author SHA1 Message Date
8a3bd602c8 Initial commit 2020-12-20 21:58:06 +00:00
da931b0e3d Initial Commit 2020-12-20 21:57:38 +00:00
7d6f7a4085 Another small change in my puke function. It should work now 2020-12-20 17:22:58 +00:00
f988e1fd10 Used wrong Call on puke function 2020-12-20 16:37:00 +00:00
4b2201e544 Fixing wrong function calls 2020-12-20 16:21:40 +00:00
55ef03625a Inital Commit of mining_lane.lua 2020-12-20 16:20:49 +00:00
d7226d2cac Bugfixes and print for puke function 2020-12-20 16:19:52 +00:00
e8d03a1211 added sort_items and code cleanup 2020-12-20 13:33:25 +00:00
21b3cce893 Added modules.lua and check fuel
The app now checks, if it has enough fuel, before doing any movement.
2020-12-20 13:33:01 +00:00
591b06aa19 Updated the file to support modules.lua and check fuel
The app now checks if it has enough fuel and if not, it asks for more.
Additionally it digs everythin in front of it, except for the last block.
2020-12-20 13:31:55 +00:00
58f282e0bf Changed the mining room script. 2020-11-22 10:16:27 +01:00
a1a3673536 worked on mining room app. But isn't finished yet 2020-11-21 22:25:41 +01:00
69e0a4555a Added a mining app which mines a room 2020-11-21 20:44:27 +01:00
8e92de7a16 Merge branch 'master' of http://tea.irgendwasmit.it:3000/sascham/ComputerCraft 2020-11-21 16:49:06 +01:00
d6e6f6b850 Merge branch 'master' of http://tea.irgendwasmit.it:3000/sascham/ComputerCraft 2020-11-20 14:54:42 +01:00
68fa543ca7 Merge branch 'master' of http://tea.irgendwasmit.it:3000/sascham/ComputerCraft
Keine Ahnung was hier los ist
2020-11-14 13:47:40 +01:00
df7f7bbb7e Added digtunnel Script 2020-11-07 23:44:09 +01:00
8 changed files with 503 additions and 66 deletions

103
Mining_Things/digtunnel.lua Normal file
View File

@ -0,0 +1,103 @@
--[[digtunnel program from Sascha
Dig a tunnel until bedrock]]
os.loadAPI('hare')
isBedrock = false
level = 0
function comming_back(distance)
for i = 1, distance do
turtle.up()
end
end
function dig_around()
if is_bedrock() then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.dig()
turtle.turnLeft()
if is_bedrock() == true then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.dig()
turtle.turnRight()
turtle.turnRight()
if is_bedrock() then
print('Found Bedrock comming back')
comming_back(level)
error('done')
end
turtle.dig()
turtle.turnLeft()
end
function is_bedrock()
-- Check if we have Bedrock in Front
-- or underneath of us
local success, item = turtle.inspect()
if success == true and item['name'] == 'minecraft:bedrock' then
isBedrock = true
return true
else
return false
end
local success, item = turtle.inspectDown()
if success == true and item['name'] == 'minecraft;bedrock' then
isBedrock = true
else
return false
end
end
while isBedrock == false do
-- Dig one level down
if is_bedrock() then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.digDown()
turtle.down()
level = level + 1
-- Dig a 3x3 Tunnel
dig_around()
turtle.forward()
dig_around()
turtle.forward()
turtle.turnLeft()
if is_bedrock() then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.dig()
turtle.turnRight()
turtle.turnRight()
if is_bedrock() then
print('Found Bedrock. Comming back')
comming_back(level)
error('Done')
end
turtle.dig()
turtle.turnLeft()
-- place a ladder
local success, item = turtle.inspect()
if not success then
hare.selectItem('minecraft:cobblestone')
turtle.place()
end
turtle.back()
hare.selectItem('minecraft:ladder')
turtle.place()
hare.selectEmptySlot()
-- Go back to Start Position
turtle.back()
end

View File

@ -0,0 +1,70 @@
os.loadAPI("modules.lua")
-- handle command line arguments
local cliArgs = {...}
local length = tonumber(cliArgs[1])
local height = tonumber(cliArgs[2])
if length == nil or height == nil or cliArgs[1] == '?' then
print('Usage: mining_lane <length> <height>')
print('length = How wide the turtle should dig.')
print('height = How high the turtle should dig.')
return
end
-- Check if we have enough fuel.
local fuelNeeded = (height + 1) * (length + 1)
while (turtle.getFuelLevel() < fuelNeeded) do
local missingFuel = fuelNeeded - turtle.getFuelLevel()
print("Not enough fuel. Put items in slot 1 in the equivalent of " .. missingFuel .. " fuel")
read()
turtle.select(1)
turtle.refuel()
end
local front = true
-- Main Loop. Dig your tunnel
for j = 1, height do
for k = 1, length do
modules.check_fuel()
turtle.dig()
turtle.forward()
end
if j < height then
print('executing digup')
turtle.digUp()
modules.check_fuel()
turtle.up()
end
turtle.turnLeft()
turtle.turnLeft()
front = not front
end
-- Go all the way down
for tdown = 1, height-1 do
modules.check_fuel()
turtle.down()
end
-- If we are away from our starting point go back to your starting point
if not front then
for tfront = 1, length do
modules.check_fuel()
turtle.forward()
end
else
turtle.turnLeft()
turtle.turnLeft()
end
-- Puke everything in your inventory out
modules.puke()
-- Turn left to set the turtle to the starting positin
turtle.turnLeft()
turtle.turnLeft()

View File

@ -0,0 +1,49 @@
os.loadAPI("modules.lua")
function mine_line(length, height)
local front = true
-- Check if the user enters only 1 length or height.
-- This is too short
if length == 1 or height == 1 then
print('Please choose a number higher than 1 for length and height.')
return false
end
for i = 1, height do
for j = 1, length do
modules.check_fuel()
turtle.dig()
turtle.forward()
end
-- Check if this is the last round to prevent digging up
if i ~= height then
modules.check_fuel()
turtle.digUp()
turtle.up()
end
turtle.turnLeft()
turtle.turnLeft()
front = not front
end
-- Everything finisehd, go back to start
if not front then
for i = 1, length do
turtle.forward()
end
end
for i = 1, height - 1 do
turtle.down()
end
end
print("How long should I dig?")
local length = read()
print("How wide should I dig?")
local width = read()
print("How high should I dig?")
local height = read()
mine_line(length, height)

View File

@ -25,7 +25,7 @@ end
function select_emptySlot()
-- loop through all slots
for slot = 1, 16 do
for slot = 1, 16 do
if turtle.getItemCount(slot) == 0 then
turtle.select(slot)
return true
@ -148,7 +148,7 @@ function sweepField(length, width, sweepFunc)
end
end
-- don't turn on the last column
if x ~= width then
-- turn to the next column
@ -195,3 +195,33 @@ function findBlock(name)
end
return false
end
-- puke() puke everything that is in the turtles
-- inventory out in front of it (hopefully there is
-- a chest
function puke()
for i = 1, 16 do
turtle.select(i)
item = turtle.getItemDetail()
if item ~= nil then
print("Puking out: " .. item['name'])
end
turtle.drop()
end
end
-- Check Fuel checks if the turtle has enough fuel.
-- if not, it asks for fuel in slot 1 and refuels.
function check_fuel()
local refueled = false
while not refueled do
if turtle.getFuelLevel() == 0 then
print("Fuel is empty. Please put fuel in slot 1 and press a key.")
read()
turtle.select(1)
turtle.refuel()
else
refueled = true
end
end
end

View File

@ -1,21 +1,24 @@
--[[Tree Chopping program by Sascha
Chops down the tree in front of turtle.]]
os.loadAPI('modules.lua') -- Load the modules module
print('Chopping tree...')
if not turtle.dig() then -- chop base of tree
error('Turtle needs a digging tool!')
end
os.sleep(5) -- Wait until everything droppen from the tree
end
os.sleep(3) -- Wait until everything droppen from the tree
for j = 1, 4 do
for i = 1, 4 do
turtle.suck() -- Suck up everything
turtle.turnLeft()
end
turtle.forward()
for i = 1, 4 do
turtle.suck() -- Suck up everything
turtle.turnLeft()
end
check_fuel()
turtle.forward()
end
for i = 1, 4 do
turtle.back()
check_fuel()
turtle.back()
end

View File

@ -1,71 +1,85 @@
--[[Tree Farming App by Al Sweigart
Plants tree and cuts it down.]]
os.loadAPI('hare.lua') -- Load the hare module
os.loadAPI('modules.lua') -- Load the modules module
local NUM_OF_TREES = 4
local TREE_SAPLING = 'spruce'
local TREE_SAPLING = 'oak'
-- Check if choptree program exists
if not fs.exists('choptree.lua') then
error('You must install choptree app first')
error('You must install choptree app first')
end
while true do
-- First of all, wait a few minutes
os.sleep(300)
-- Check if turtle has enough fuel
if turtle.getFuelLevel() < (2 * (3 * NUM_OF_TREES)) then
hare.selectItem('minecraft:' .. TREE_SAPLING .. 'log')
turtle.refuel(2)
end
-- Empty everything except for the saplings
for i = 1, 16 do
local item = turtle.getItemDetail(i)
-- First of all, wait a few minutes
os.sleep(300)
if item ~= nil and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
turtle.select(i)
turtle.drop()
end
end
-- Sort all Items together
modules.sort_items()
-- Check if we have saplings in our inventory
if not hare.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling') then
error('Out of ' .. TREE_SAPLING .. ' saplings')
end
-- Build a Loop, where we plant and cut trees
for i = 1, NUM_OF_TREES do
turtle.back()
turtle.back()
turtle.back()
turtle.turnRight()
blockExists, item = turtle.inspect()
if blockExists and item['name'] == 'minecraft:' .. TREE_SAPLING .. '_log' then
hare.selectEmtySlot()
shell.run('choptree.lua') -- Run Choptree
elseif blockExists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
print('Error! Wrong block')
elseif not blockExists then
turtle.forward()
local success, underneath = turtle.inspectDown()
if underneath['name'] ~= 'minecraft:dirt' and underneath['name'] ~= 'minecraft:grass_block' then
print('Error. No Dirt or Grass underneath to plant a tree. Found: ' .. underneath['name'])
turtle.back()
else
turtle.back()
hare.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling')
turtle.place()
end
end
turtle.turnLeft()
end
-- Move forward to the chest again
for i = 1, (3 * NUM_OF_TREES) do
turtle.forward()
-- Empty everything except for the saplings
for i = 1, 16 do
local item = turtle.getItemDetail(i)
if item ~= nil and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
turtle.select(i)
print('Dropping ' .. item['name'] .. ' into chest.')
turtle.drop()
end
end
-- Check if we have saplings in our inventory
if not modules.select_item('minecraft:' .. TREE_SAPLING .. '_sapling') then
error('Out of ' .. TREE_SAPLING .. ' saplings')
end
-- Build a Loop, where we plant and cut trees
turtle.turnLeft()
turtle.turnLeft()
for i = 1, NUM_OF_TREES do
for j = 1, 3 do
modules.check_fuel()
if i ~= 3 * NUM_OF_TREES then
turtle.dig()
end
turtle.forward()
end
turtle.turnLeft()
blockExists, item = turtle.inspect()
if blockExists and item['name'] == 'minecraft:' .. TREE_SAPLING .. '_log' then
modules.select_emptySlot()
shell.run('choptree.lua') -- Run Choptree
elseif blockExists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
print('Error! Wrong block. Found ' .. item['name'])
elseif not blockExists then
turtle.forward()
local success, underneath = turtle.inspectDown()
if underneath['name'] ~= 'minecraft:dirt' and underneath['name'] ~= 'minecraft:grass_block' then
print('Error. No Dirt or Grass underneath to plant a tree. Found: ' .. underneath['name'])
turtle.back()
else
turtle.back()
print('Planting seed.')
modules.select_item('minecraft:' .. TREE_SAPLING .. '_sapling')
turtle.place()
end
end
turtle.turnRight()
end
-- Move forward to the chest again
turtle.turnLeft()
turtle.turnLeft()
print('Heading back to chest.')
for i = 1, (3 * NUM_OF_TREES) do
modules.check_fuel()
if i ~= 3 * NUM_OF_TREES then
turtle.dig()
end
turtle.forward()
end
end

View File

@ -0,0 +1,70 @@
--[[
treeautofarm program by The_Lux
This program checks a tree farm with given length and width and
chops the tree down, when it finds one.
]]
-- In which direction should the farm be automated?
DIRECTION = 'right'
NUM_OF_TREES = 9
TREE_SAPLING = 'oak'
TREE_DISTANCE = 3
DISTANCE = 3
WIDTH = 2
-- bring turtle in position
if DIRECTION == 'right' then
turtle.turnRight()
else
turtle.turnLeft()
end
turtle.forward()
if DIRECTION == 'right' then
turtle.turnLeft()
else
turtle.turnRight()
end
while true do
-- Wait a few minutes
os.sleep(300)
for i = 1, WIDTH do
-- Check a line of Trees
shell.run('treeline.lua', NUM_OF_TREES, TREE_DISTANCE, TREE_SAPLING)
-- Go to the next line. But only, if it isn't the last loop
if i < WIDTH then
if DIRECTION == 'right' then
turtle.turnRight()
else
turtle.turnLeft()
end
for j = 1, DISTANCE do
turtle.forward()
end
if DIRECTION == ' right' then
turtle.turnLeft()
else
turtle.turnRight()
end
end
end
-- Go back to start
if DIRECTION == 'right' then
turtle.turnRight()
else
turtle.turnLeft()
end
for i = 1, ((WIDTH - 1) * DISTANCE) do
turtle.forward()
end
if DIRECTION == ' right' then
turtle.turnLeft()
else
turtle.turnRight()
end
end

98
Tree_Farm/treeline.lua Normal file
View File

@ -0,0 +1,98 @@
--[[
treeline program by The_Lux
This program checks a tree farm with given length and chops the tree down
when it finds one.
]]
os.loadAPI('modules.lua') -- Load the modules module
-- Handle command line arguments
local cliArgs = {...}
local num_of_trees = tonumber(cliArgs[1])
local tree_distance = tonumber(cliArgs[2])
local tree_sapling = cliArgs[3]
if num_of_trees == nil or tree_distance == nil or tree_sapling == nil or cliArgs[1] == '?' then
print('Usage: treeline.lua <num_of_trees> <tree_distance> <tree_sapling>')
print('num_of_trees = How many trees a in a line.')
print('tree_distance = How much space (+1) are in between the trees.')
print('tree_sapling = What sapling to use.')
return
end
-- Empty everything except for the saplings
for i = 1, 16 do
local item = turtle.getItemDetail(i)
if item ~= nil and item['name'] ~= 'minecraft:' .. tree_sapling .. '_sapling' then
turtle.select(i)
print('Dropping ' .. item['name'])
turtle.drop()
end
end
-- Check if we have saplings in our inventory
if not modules.select_item('minecraft:' .. tree_sapling .. '_sapling') then
print('Out of ' .. tree_sapling .. ' saplings. Please provide additional saplings')
print('Press Enter when additional sapling are filled.')
read()
end
-- Check if we have enough fuel to make our way and come back to start
needed_fuel = (num_of_trees * tree_distance) * 2
while turtle.getFuelLevel() <= needed_fuel do
print('Not enough fuel to farm and come back.')
print('We need ' .. (needed_fuel - turtle.getFuelLevel()) .. ' additional fuel.')
print('Please put fuel in slot 1 and press a enter.')
read()
turtle.select(1)
turtle.refuel()
end
for i = 1, num_of_trees do
for j = 1, tree_distance do
-- check if something is in your way and dig it up
if i ~= (tree_distance * num_of_trees) then
turtle.dig()
end
turtle.forward()
end
turtle.turnLeft()
blockExists, item = turtle.inspect()
if blockExists and item['name'] == 'minecraft:' .. tree_sapling .. '_log' then
print('Cutting tree...')
turtle.dig()
print('Planting seed.')
modules.select_item('minecraft:' .. tree_sapling .. '_sapling')
turtle.place()
elseif not blockExists then
turtle.forward()
local success, underneath = turtle.inspectDown()
if underneath['name'] ~= 'minecraft:dirt' and underneath['name'] ~= 'minecraft:grass_block' then
print('Error. No Dirt or Grass underneath to plant a tree. Found: ' .. underneath['name'])
turtle.back()
else
turtle.back()
print('Planting seed.')
modules.select_item('minecraft:' .. tree_sapling .. '_sapling')
turtle.place()
end
end
turtle.turnRight()
end
-- Move forward to the chest again
turtle.turnLeft()
turtle.turnLeft()
print('Heading back to start.')
for i = 1, (tree_distance * num_of_trees) do
if i ~= (tree_distance * num_of_trees) then
turtle.dig()
end
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
end