Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle-Programm für cc:tweaked
- -- Konfiguration
- local INPUT_CHEST = "right" -- Einzahlungskiste
- local DEPOT_CHEST = "bottom" -- Depotkiste
- local PRICE_CHEST = "back" -- Preiskiste
- local OUTPUT_CHEST = "left" -- Auszahlungskiste
- local MAX_ITEMS = 16 -- Maximale Anzahl der Preise pro Transaktion
- -- Erweiterte Peripherie für Chat-Nachrichten
- local chat = peripheral.find("chatBox")
- -- Hilfsfunktionen
- local function selectItem(name)
- for i = 1, 16 do
- turtle.select(i)
- local detail = turtle.getItemDetail()
- if detail and detail.name == name then
- return true
- end
- end
- return false
- end
- local function dropAll(direction)
- for i = 1, 16 do
- turtle.select(i)
- if direction == "up" then
- turtle.dropUp()
- elseif direction == "down" then
- turtle.dropDown()
- elseif direction == "forward" then
- turtle.drop()
- end
- end
- end
- local function countItems(itemName)
- local count = 0
- for i = 1, 16 do
- local detail = turtle.getItemDetail(i)
- if detail and detail.name == itemName then
- count = count + detail.count
- end
- end
- return count
- end
- local function sendMessage(message)
- if chat then
- chat.sendMessage(message)
- else
- print(message)
- end
- end
- -- Hauptlogik
- local function processTransaction()
- turtle.turnRight()
- while turtle.suck() do
- -- Solange Items in der Einzahlungskiste sind, einsammeln
- end
- local diamonds = countItems("minecraft:diamond")
- local emeralds = countItems("minecraft:emerald")
- local totalItems = diamonds + emeralds
- if totalItems > 0 then
- -- Lege Diamanten und Emeralds ins Depot
- if diamonds > 0 then
- selectItem("minecraft:diamond")
- dropAll("down")
- end
- if emeralds > 0 then
- selectItem("minecraft:emerald")
- dropAll("down")
- end
- sendMessage("Es wurden " .. totalItems .. " Diamanten/Emeralds eingezahlt.")
- -- Preise aus Preiskiste entnehmen und in Auszahlungskiste legen
- local itemsToGive = math.min(totalItems, MAX_ITEMS)
- turtle.turnRight()
- for i = 1, itemsToGive do
- if not turtle.suck() then
- sendMessage("Preiskiste ist leer. Es konnten nicht genügend Preise bereitgestellt werden.")
- break
- end
- end
- turtle.turnRight()
- dropAll("forward")
- sendMessage("Die Preise wurden in die Auszahlungskiste gelegt.")
- turtle.turnRight()
- else
- -- Falsche Items ins Depot verschieben
- sendMessage("Keine gültigen Items gefunden. Verschiebe fehlerhafte Items ins Depot.")
- dropAll("down")
- redstone.setOutput("front", true)
- sleep(0.5)
- redstone.setOutput("front", false)
- turtle.turnLeft()
- end
- sendMessage("Vielen Dank für ihr Vertrauen - Glückspiel kann süchtig machen!")
- end
- -- Event Listener für Redstone Signal
- while true do
- if redstone.getInput("top") then
- processTransaction()
- while redstone.getInput("top") do
- sleep(0.1) -- Warten bis der Puls endet
- end
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment