Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the slot in the turtle's inventory to use for placing blocks
- local blockSlot = 1 -- Change this to the slot number where the block to place is stored
- -- Function to print debug messages (toggle debugMode to enable/disable)
- local debugMode = true
- local function debugPrint(message)
- if debugMode then
- print(message)
- end
- end
- -- Function to check if there is a redstone signal on any side of the turtle
- local function isRedstoneActive()
- return redstone.getInput("front") or redstone.getInput("back") or
- redstone.getInput("left") or redstone.getInput("right") or
- redstone.getInput("top") or redstone.getInput("bottom")
- end
- -- Main function to break and replace the block in front of the turtle
- local function breakAndReplace()
- while true do
- if isRedstoneActive() then
- debugPrint("Redstone signal detected.")
- -- Break the block in front
- if turtle.dig() then
- debugPrint("Block in front broken.")
- else
- debugPrint("No block to break.")
- end
- -- Select the block slot and place it in front
- turtle.select(blockSlot)
- if turtle.place() then
- debugPrint("Block placed in front.")
- else
- debugPrint("Failed to place block.")
- end
- -- Wait until the redstone signal is no longer detected
- while isRedstoneActive() do
- os.sleep(0.1) -- Small delay to avoid looping too quickly
- end
- debugPrint("Redstone signal turned off.")
- end
- os.sleep(0.1) -- Check again after a short delay
- end
- end
- -- Run the main function
- breakAndReplace()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement