Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define a flag to control debug prints
- local debugMode = true -- Set to 'false' to disable prints
- -- Define slots for each ingredient
- local slots = {
- tomato = 1,
- onion = 2,
- beef_patty = 3,
- cabbage = 5,
- bread = 6
- }
- -- Define item names for easy reference
- local items = {
- tomato = "farmersdelight:tomato",
- onion = "farmersdelight:onion",
- beef_patty = "farmersdelight:beef_patty",
- cabbage = "farmersdelight:cabbage",
- bread = "minecraft:bread",
- hamburger = "farmersdelight:hamburger"
- }
- -- Get Vault
- local modem = peripheral.wrap("front")
- local turtleName = modem.getNameLocal()
- local vault = peripheral.find("create:item_vault")
- -- Function to print messages if debug mode is active
- local function debugPrint(message)
- if debugMode then
- print(message)
- end
- end
- -- Function to check if a slot is full
- local function isSlotFull(slot)
- local itemDetail = turtle.getItemDetail(slot)
- if itemDetail then
- debugPrint("Slot " .. slot .. " contains " .. itemDetail.count .. " items.")
- return itemDetail.count >= 64
- else
- debugPrint("Slot " .. slot .. " is empty.")
- return false
- end
- end
- -- Function to check if a specific item exists in the neighboring inventory
- local function checkNeighborInventory(itemName)
- -- Iterate through the slots in the neighboring inventory
- for i = 1, vault.size() do
- local item = vault.getItemDetail(i)
- if item and item.name == itemName then
- debugPrint("Found " .. itemName .. " in neighbor inventory slot " .. i)
- return true, i
- end
- end
- debugPrint(itemName .. " not found in neighbor inventory.")
- return false, nil
- end
- -- Function to refill turtle's inventory from the neighboring inventory
- local function refillFromNeighbor()
- for item, slot in pairs(slots) do
- if not isSlotFull(slot) then
- local hasItem, neighborSlot = checkNeighborInventory(items[item])
- if hasItem then
- debugPrint("Refilling slot " .. slot .. " with " .. items[item])
- turtle.select(slot)
- local pulledCount = 64 - (turtle.getItemCount(slot) or 0)
- vault.pushItems(turtleName, neighborSlot, pulledCount, slot)
- debugPrint("Pulled " .. pulledCount .. " " .. items[item] .. " into slot " .. slot)
- end
- else
- debugPrint("Slot " .. slot .. " is already full with " .. (turtle.getItemCount(slot) or 0) .. " items.")
- end
- end
- end
- -- Function to craft and store hamburgers back into the neighboring inventory
- local function craftAndStoreHamburgers()
- debugPrint("Attempting to craft hamburger.")
- turtle.craft() -- Attempt to craft
- -- Check for any hamburgers in inventory
- for slot = 1, 16 do
- local itemDetail = turtle.getItemDetail(slot)
- if itemDetail and itemDetail.name == items.hamburger then
- debugPrint("Hamburger found in slot " .. slot)
- turtle.select(slot)
- vault.pullItems(turtleName, slot)
- debugPrint("Dropped hamburger from slot " .. slot .. " to neighbor inventory.")
- end
- end
- end
- -- Main function to run the turtle's operations
- local function runTurtle()
- while true do
- debugPrint("Refilling from neighbor inventory.")
- refillFromNeighbor() -- Refill ingredients if needed
- debugPrint("Crafting and storing hamburgers.")
- craftAndStoreHamburgers() -- Craft and store hamburgers
- os.sleep(5) -- Wait before checking again
- end
- end
- -- Run the turtle's program
- runTurtle()
Add Comment
Please, Sign In to add comment