diff --git a/Modules/modules.lua b/Modules/modules.lua index bff3e69..176f353 100644 --- a/Modules/modules.lua +++ b/Modules/modules.lua @@ -1,6 +1,7 @@ --[[Function Module program by Al Sweigart Provides useful utility functions.]] + -- selectItem() selects the inventory -- slot with the named item, returns -- true if found and false if not @@ -25,7 +26,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 @@ -34,6 +35,7 @@ function select_emptySlot() return false -- couldn't find empty space end + -- countInventory() returns the total -- number of a given minecraft id item in the inventory function count_inventory(minecraft_id, times) @@ -48,6 +50,7 @@ function count_inventory(minecraft_id, times) return total end + -- selectAndPlaceDown() selects a slot with given -- minecraft id and places a block from it under the turtle function select_and_place_down(minecraft_id) @@ -107,6 +110,7 @@ function build_wall(length, height) return true end + -- build_room() constructs four walls -- and a ceiling function build_room(length, width, height) @@ -131,6 +135,7 @@ function build_room(length, width, height) return true end + -- sweepField() moves acress the rows -- and columns of an area in front and -- to the right of the turtle, calling @@ -148,7 +153,7 @@ function sweepField(length, width, sweepFunc) end end - + -- don't turn on the last column if x ~= width then -- turn to the next column @@ -181,6 +186,7 @@ function sweepField(length, width, sweepFunc) return true end + --findBlock() spins around searching --for the named block next to the turtle function findBlock(name) @@ -196,7 +202,8 @@ function findBlock(name) return false end --- puke() puke everything that is in the turtles + +-- puke() puke everything that is in the turtles -- inventory out in front of it (hopefully there is -- a chest function puke() @@ -206,6 +213,7 @@ function puke() 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() @@ -221,3 +229,20 @@ function check_fuel() end end end + +-- sort_items() stacks all items of the same ID +-- into one stack +function sort_items() + for i = 1, 16 do + turtle.select(i) + item1 = turtle.getItemDetail() + for j = i+1, 16 do + item2 = turtle.getItemDetail(j) + if item1 ~= nil and item2 ~= nil and item1['name'] == item2['name'] then + turtle.select(j) + turtle.transferTo(i) + end + end + end + +end \ No newline at end of file