Advertisement
dadragon84

ChestInventory

Mar 15th, 2025 (edited)
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Turtle-Programm für cc:tweaked
  2.  
  3. -- Konfiguration
  4. local INPUT_CHEST = "right"   -- Deposit box
  5. local DEPOT_CHEST = "bottom"  -- Depot kit
  6. local PRICE_CHEST = "back"    -- Investigations
  7. local OUTPUT_CHEST = "left"  -- Payout box
  8. local MAX_ITEMS = 16           -- Maximum number of prizes per transaction
  9.  
  10. -- Advanced peripherals for chat messages
  11. local chat = peripheral.find("chatBox")
  12.  
  13. -- Auxiliary functions
  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. -- Main logic
  58. local function processTransaction()
  59.     turtle.turnRight()
  60.  
  61.     while turtle.suck() do
  62.         -- As long as there are items in the deposit box, collect
  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.         -- Put diamonds and emeralds in the 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("There were " .. totalItems .. " Diamonds/Emeralds deposited.")
  82.  
  83.         -- Remove prizes from prize box and place them in payout box
  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("Prize box is empty. Not enough prizes could be provided.")
  89.                 break
  90.             end
  91.         end
  92.         turtle.turnRight()
  93.         dropAll("forward")
  94.         sendMessage("The prizes were placed in the payout box.")
  95.          turtle.turnRight()
  96.     else
  97.         -- Move incorrect items to the depot
  98.         sendMessage("No valid items found. Move faulty items to the 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("Thank you for your trust - gambling can be addictive!")
  107.    
  108. end
  109.  
  110. -- Event Listener for Redstone Signal
  111. while true do
  112.     if redstone.getInput("top") then
  113.         processTransaction()
  114.         while redstone.getInput("top") do
  115.             sleep(0.1) -- Wait until the pulse ends
  116.         end
  117.     end
  118.     sleep(0.1)
  119. end
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement