Guest User

startup

a guest
Dec 6th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. -- Turtle-Programm für cc:tweaked
  2.  
  3. -- Konfiguration
  4. local INPUT_CHEST = "right"   -- Einzahlungskiste
  5. local DEPOT_CHEST = "bottom"  -- Depotkiste
  6. local PRICE_CHEST = "back"    -- Preiskiste
  7. local OUTPUT_CHEST = "left"  -- Auszahlungskiste
  8. local MAX_ITEMS = 16           -- Maximale Anzahl der Preise pro Transaktion
  9.  
  10. -- Erweiterte Peripherie für Chat-Nachrichten
  11. local chat = peripheral.find("chatBox")
  12.  
  13. -- Hilfsfunktionen
  14. local function selectItem(name)
  15.     for i = 1, 16 do
  16.         turtle.select(i)
  17.         local detail = turtle.getItemDetail()
  18.         if detail and detail.name == name then
  19.             return true
  20.         end
  21.     end
  22.     return false
  23. end
  24.  
  25. local function dropAll(direction)
  26.     for i = 1, 16 do
  27.         turtle.select(i)
  28.         if direction == "up" then
  29.             turtle.dropUp()
  30.         elseif direction == "down" then
  31.             turtle.dropDown()
  32.         elseif direction == "forward" then
  33.             turtle.drop()
  34.         end
  35.     end
  36. end
  37.  
  38. local function countItems(itemName)
  39.     local count = 0
  40.     for i = 1, 16 do
  41.         local detail = turtle.getItemDetail(i)
  42.         if detail and detail.name == itemName then
  43.             count = count + detail.count
  44.         end
  45.     end
  46.     return count
  47. end
  48.  
  49. local function sendMessage(message)
  50.     if chat then
  51.         chat.sendMessage(message)
  52.     else
  53.         print(message)
  54.     end
  55. end
  56.  
  57. -- Hauptlogik
  58. local function processTransaction()
  59.     turtle.turnRight()
  60.  
  61.     while turtle.suck() do
  62.         -- Solange Items in der Einzahlungskiste sind, einsammeln
  63.     end
  64.  
  65.     local diamonds = countItems("minecraft:diamond")
  66.     local emeralds = countItems("minecraft:emerald")
  67.     local totalItems = diamonds + emeralds
  68.  
  69.     if totalItems > 0 then
  70.         -- Lege Diamanten und Emeralds ins Depot
  71.         if diamonds > 0 then
  72.             selectItem("minecraft:diamond")
  73.             dropAll("down")
  74.         end
  75.  
  76.         if emeralds > 0 then
  77.             selectItem("minecraft:emerald")
  78.             dropAll("down")
  79.         end
  80.  
  81.         sendMessage("Es wurden " .. totalItems .. " Diamanten/Emeralds eingezahlt.")
  82.  
  83.         -- Preise aus Preiskiste entnehmen und in Auszahlungskiste legen
  84.         local itemsToGive = math.min(totalItems, MAX_ITEMS)
  85.         turtle.turnRight()
  86.         for i = 1, itemsToGive do
  87.             if not turtle.suck() then
  88.                 sendMessage("Preiskiste ist leer. Es konnten nicht genügend Preise bereitgestellt werden.")
  89.                 break
  90.             end
  91.         end
  92.         turtle.turnRight()
  93.         dropAll("forward")
  94.         sendMessage("Die Preise wurden in die Auszahlungskiste gelegt.")
  95.          turtle.turnRight()
  96.     else
  97.         -- Falsche Items ins Depot verschieben
  98.         sendMessage("Keine gültigen Items gefunden. Verschiebe fehlerhafte Items ins Depot.")
  99.         dropAll("down")
  100.         redstone.setOutput("front", true)
  101.         sleep(0.5)
  102.         redstone.setOutput("front", false)
  103.          turtle.turnLeft()
  104.        end
  105.  
  106.     sendMessage("Vielen Dank für ihr Vertrauen - Glückspiel kann süchtig machen!")
  107.    
  108. end
  109.  
  110. -- Event Listener für Redstone Signal
  111. while true do
  112.     if redstone.getInput("top") then
  113.         processTransaction()
  114.         while redstone.getInput("top") do
  115.             sleep(0.1) -- Warten bis der Puls endet
  116.         end
  117.     end
  118.     sleep(0.1)
  119. end
  120.  
Advertisement
Add Comment
Please, Sign In to add comment