Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local succes = false
- local oldSlot = turtle.getSelectedSlot()
- --Checks for a specific item in current slot and returns succes
- local function checkItem(name)
- if turtle.getItemDetail() ~= nil then
- local data = turtle.getItemDetail()
- if data.name == name then
- return true
- else
- return false
- end
- end
- return false
- end
- --check if item is in inventory and returns succes
- function checkInvetory(name)
- oldSlot = turtle.getSelectedSlot()
- for i = 1,16 do
- turtle.select(i)
- if checkItem(name) then
- turtle.select(oldSlot)
- return true
- end
- end
- turtle.select(oldSlot)
- return false
- end
- --check if item is in inventory and returns numberSlot
- function checkInventorySlot(name)
- oldSlot = turtle.getSelectedSlot()
- for i = 1,16 do
- turtle.select(i)
- if checkItem(name) then
- turtle.select(oldSlot)
- return i
- end
- end
- turtle.select(oldSlot)
- return nil
- end
- --move "amount(int)" of "name(string)" items to slot "slot(int)" and returns succes
- function placeItemInSlot(name, slot, amount)
- if type(name) ~= string or type(slot) ~= number or type(amount) ~= number then
- return false
- else
- numberSlot = placer.checkInventorySlot(name)
- if numberSlot == nil then
- return false
- else
- turtle.select(numberSlot)
- if turtle.transferTo(slot, amount) then
- local succeeded = true
- else
- local succeeded = false
- end
- turtle.select(oldSlot)
- return succeeded
- end
- end
- end
- --places any item in any direction and returns succes
- function place(name ,dir)
- succes = false
- for i = 1,16 do
- turtle.select(i)
- if checkItem(name) then
- succes = true
- end
- end
- if succes then
- if dir == "up" then
- return turtle.placeUp()
- elseif dir == "down" then
- return turtle.placeDown()
- else
- return turtle.place()
- end
- else
- if checkInvetory then
- --print("Could not place any "..name.." "..dir)
- else
- --print("There is no "..name.." in inventory")
- end
- end
- return false
- end
- --just a little example
- for i = 1,10 do
- if place("minecraft:sand","down") then
- sleep(0.5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement