APIs and examples and more item moving logic

master
zaners123 2022-01-04 00:05:24 -08:00
parent 33feb94d5c
commit 5d38b83af6
3 changed files with 30 additions and 32 deletions

6
API.md
View File

@ -74,7 +74,7 @@ The reason can be any string, and is visible in debug.txt (can turn on/off debug
The turtle will mine the block next to it and take the items of the block. It will take items from chests, too
They return true if the block was removed
### `turtle:build[direction](turtleslot)
### `turtle:build[direction](turtleslot)`
- Returns true if built
Places the block that's in the turtleslot.
@ -82,7 +82,7 @@ Places the block that's in the turtleslot.
Example: `turtle:buildForward(1)` builds the item in the top-left slot right in front of the turtle
### `turtle:scan[direction]()
### `turtle:scan[direction]()`
- Returns scan result
Returns the node at the given position as table in the format`{name="node_name", param1=0, param2=0}`
@ -105,7 +105,7 @@ Takes fuel from this turtleslot and increases the turtle's fuel
Moves one block in that direction, yields, and consumes fuel
### `turtle:itemPush[direction](filterList, isWhitelist, listname)
### `turtle:itemPush[direction](filterList, isWhitelist, listname)`
The opposite of itemSuck. Push everything from the turtle's inventory that matches some filter into the nearby block inventory
Example: `turtle:itemPushRight({"default:coal_lump","wood","tree"},true,'fuel')` takes all coal lumps,wood-group, or tree-group items from the turtle. Puts them into the furnace-to-the-right's fuel slot.

View File

@ -1,29 +0,0 @@
---Dumps everything from the turtle forward if it's in the list
--- @param list - Something like {"default:stone","default:dirt"}
--- @param isWhitelist - If true, only dump things in list.
--- If false, dump everything EXCEPT the items in the list
--- @param listname @see itemPush
--- @return boolean true unless any items can't fit
local function itemPushForwardFiltered(turtle, list, isWhitelist, listname)
local success = true
local function intable(item)
for _,x in pairs(list) do
if item==x then return true end
end
return false
end
for turtleslot = 1, 16 do
if intable(turtle:itemGet(turtleslot):get_name()) == isWhitelist then
success = success and turtle:itemPushForward(turtleslot,listname)
end
end
return success
end
function init(turtle)
while true do
itemPushForwardFiltered(turtle,{"default:cobble","default:sand"}, true, "src")
itemPushForwardFiltered(turtle,{"default:coal_lump"}, true, "fuel")
turtle:itemSuckForward({"default:stone","default:glass"},true,"dst")
turtle:yield("Waiting")
end
end

27
examples/debug.nogit.lua Normal file
View File

@ -0,0 +1,27 @@
--Have logs in slot 1, and all other slots clear
function craftPick(turtle)
turtle:itemSplitTurtleslot(1,2)
turtle:itemCraft(5)--craft 4 planks -> 5
turtle:itemSplitTurtleslot(5,2,2)
turtle:itemCraft(9)--craft 4 sticks -> 9
turtle:itemSplitTurtleslot(5,2)
turtle:itemSplitTurtleslot(5,3)
turtle:itemSplitTurtleslot(5,4)
turtle:itemSplitTurtleslot(9,7)
turtle:itemSplitTurtleslot(9,11)
turtle:itemCraft(13)
turtle:itemCraft(14)
end
function init(turtle)
while true do
turtle:moveForward()
craftPick(turtle)
--turtle:itemPushForward()
turtle:yield("Waiting 1")
--turtle:itemSuckForward()
turtle:moveBackward()
turtle:itemSuckLeft ({"default:cobble","default:dirt"},true)
turtle:itemPushRight({"default:coal_lump","wood","tree"},true,'fuel')
turtle:yield("Waiting")
end
end