Last active
February 13, 2023 22:02
-
-
Save FederAndInk/a86514baa0fe91c3cd3468df2dc343dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---select the first non empty slot that is not bone_meal | |
local function first_nonempty_slot() | |
local i = 1 | |
while i <= 16 and (turtle.getItemCount(i) == 0) do | |
i = i + 1 | |
end | |
if i <= 16 then | |
turtle.select(i) | |
end | |
return i <= 16 | |
end | |
--- select first empty slot | |
local function first_empty_slot() | |
local i = 1 | |
while i <= 16 and (turtle.getItemCount(i) ~= 0) do | |
i = i + 1 | |
end | |
if i <= 16 then | |
turtle.select(i) | |
end | |
return i <= 16 | |
end | |
local function pull_items_from_chest() | |
local present, chest = turtle.inspectUp() | |
if not present or chest.name ~= "minecraft:chest" then | |
error("no chest found!") | |
os.exit(1) | |
end | |
while not turtle.suckUp() and not first_nonempty_slot() do | |
print("waiting for petals") | |
sleep(1) | |
end | |
while turtle.suckUp() do | |
end | |
end | |
---select the first slot with item | |
---@return boolean | |
local function select_slot_with(item_name) | |
local i = 1 | |
while i <= 16 and | |
(turtle.getItemCount(i) == 0 or turtle.getItemDetail(i).name ~= item_name) do | |
i = i + 1 | |
end | |
if i <= 16 then | |
turtle.select(i) | |
end | |
return i <= 16 | |
end | |
---@return string | |
local function front_block_name() | |
local here, b = turtle.inspect() | |
if here then | |
if type(b) == type({}) then | |
b = b.name | |
end | |
return b | |
end | |
end | |
-- local shears_side = "left" | |
local bonemeal_side = "right" | |
while true do | |
pull_items_from_chest() | |
while (first_nonempty_slot()) do | |
print(("processing %s"):format(turtle.getItemDetail().name)) | |
turtle.place() | |
local placed_block = front_block_name() | |
redstone.setOutput(bonemeal_side, true) | |
while placed_block == front_block_name() do | |
sleep(0.02) | |
end | |
redstone.setOutput(bonemeal_side, false) | |
placed_block = front_block_name() | |
first_empty_slot() | |
turtle.dig() | |
-- redstone.setOutput(shears_side, true) | |
while placed_block == front_block_name() do | |
sleep(0.02) | |
end | |
turtle.dropDown() | |
-- redstone.setOutput(shears_side, false) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment