MigasRocha

Dropping specific items test

Apr 15th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. -- List of unwanted item names
  2. local unwantedItems = {
  3.     "minecraft:cobblestone",
  4.     "minecraft:dirt",
  5.     "minecraft:gravel"
  6.     -- Add more item names as needed
  7. }
  8.  
  9. -- Function to check if an item is unwanted
  10. local function isUnwanted(itemName)
  11.     for _, unwanted in ipairs(unwantedItems) do
  12.         if itemName == unwanted then
  13.             return true
  14.         end
  15.     end
  16.     return false
  17. end
  18.  
  19. -- Function to drop unwanted items from turtle's inventory
  20. local function dropUnwantedItems()
  21.     for slot = 1, 16 do  -- Iterate over turtle's inventory slots (1 to 16)
  22.         local itemDetails = turtle.getItemDetail(slot)
  23.         if itemDetails then
  24.             local itemName = itemDetails.name
  25.             if isUnwanted(itemName) then
  26.                 turtle.select(slot)  -- Select the slot with unwanted item
  27.                 turtle.drop()        -- Drop the unwanted item
  28.             end
  29.         end
  30.     end
  31. end
  32.  
  33. -- Call the function to drop unwanted items
  34. dropUnwantedItems()
Add Comment
Please, Sign In to add comment