MadCat_G

huntv1

Aug 14th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.89 KB | Gaming | 0 0
  1. -- Script: Zombie Piglin Hunter with Item Storage
  2. -- Description: Crafts sticks and stone sword, attacks zombie piglins, collects drops (rotten flesh, gold nuggets, ingots), and deposits them in a chest behind the turtle.
  3.  
  4. local function checkFuel()
  5.     if turtle.getFuelLevel() < 50 then
  6.         print("Low fuel! Please place fuel (e.g., coal) in slot 1 and press Enter.")
  7.         turtle.select(1)
  8.         os.pullEvent("key")
  9.         if turtle.refuel() then
  10.             print("Refueled. Current fuel level: " .. turtle.getFuelLevel())
  11.         else
  12.             print("Failed to refuel. Please add valid fuel.")
  13.             return false
  14.         end
  15.     end
  16.     return true
  17. end
  18.  
  19. local function findItem(itemName)
  20.     for i = 1, 16 do
  21.         local item = turtle.getItemDetail(i)
  22.         if item and item.name == itemName then
  23.             return i
  24.         end
  25.     end
  26.     return nil
  27. end
  28.  
  29. local function craftSticks()
  30.     print("Attempting to craft sticks...")
  31.     turtle.select(5)
  32.     if turtle.getItemCount(5) < 2 then
  33.         print("Error: Need at least 2 planks in slot 5 to craft sticks.")
  34.         return false
  35.     end
  36.     for i = 1, 2 do
  37.         turtle.select(i)
  38.         if turtle.getItemCount(i) > 0 then
  39.             turtle.drop()
  40.         end
  41.     end
  42.     turtle.select(5)
  43.     turtle.transferTo(1, 1)
  44.     turtle.transferTo(2, 1)
  45.     if turtle.craft() then
  46.         print("Sticks crafted successfully!")
  47.         return true
  48.     else
  49.         print("Failed to craft sticks. Ensure 2 planks in slot 5.")
  50.         return false
  51.     end
  52. end
  53.  
  54. local function craftStoneSword()
  55.     print("Attempting to craft a stone sword...")
  56.     turtle.select(4)
  57.     if turtle.getItemCount(4) < 2 then
  58.         print("Error: Need at least 2 cobblestone in slot 4.")
  59.         return false
  60.     end
  61.     local stickSlot = findItem("minecraft:stick")
  62.     if not stickSlot then
  63.         if not craftSticks() then
  64.             return false
  65.         end
  66.         stickSlot = 1
  67.     end
  68.     for i = 1, 3 do
  69.         turtle.select(i)
  70.         if turtle.getItemCount(i) > 0 then
  71.             turtle.drop()
  72.         end
  73.     end
  74.     turtle.select(4)
  75.     turtle.transferTo(1, 1)
  76.     turtle.transferTo(2, 1)
  77.     turtle.select(stickSlot)
  78.     turtle.transferTo(3, 1)
  79.     if turtle.craft() then
  80.         print("Stone sword crafted successfully!")
  81.         return true
  82.     else
  83.         print("Failed to craft sword. Ensure correct items and slots.")
  84.         return false
  85.     end
  86. end
  87.  
  88. local function equipSword()
  89.     turtle.select(1)
  90.     local item = turtle.getItemDetail(1)
  91.     if item and item.name == "minecraft:stone_sword" then
  92.         if turtle.equipLeft() then
  93.             print("Stone sword equipped on left side.")
  94.             return true
  95.         else
  96.             print("Failed to equip sword.")
  97.             return false
  98.         end
  99.     else
  100.         print("No stone sword found in slot 1.")
  101.         return false
  102.     end
  103. end
  104.  
  105. local function depositItems()
  106.     turtle.turnLeft()
  107.     turtle.turnLeft()
  108.     local itemsToDeposit = {
  109.         "minecraft:rotten_flesh",
  110.         "minecraft:gold_nugget",
  111.         "minecraft:gold_ingot"
  112.     }
  113.     for i = 1, 16 do
  114.         local item = turtle.getItemDetail(i)
  115.         if item then
  116.             for _, targetItem in ipairs(itemsToDeposit) do
  117.                 if item.name == targetItem then
  118.                     turtle.select(i)
  119.                     turtle.drop()
  120.                     print("Deposited " .. item.name .. " into chest.")
  121.                 end
  122.             end
  123.         end
  124.     end
  125.     turtle.turnLeft()
  126.     turtle.turnLeft()
  127. end
  128.  
  129. local function hasSword()
  130.     local swordSlot = findItem("minecraft:stone_sword")
  131.     if swordSlot then
  132.         return true
  133.     end
  134.     return false
  135. end
  136.  
  137. local function huntZombiePiglins()
  138.     print("Starting zombie piglin hunter...")
  139.     while true do
  140.         if not checkFuel() then
  141.             print("Stopping due to low fuel.")
  142.             break
  143.         end
  144.         if not hasSword() then
  145.             print("No sword detected. Attempting to craft and equip new sword...")
  146.             if not (craftStoneSword() and equipSword()) then
  147.                 print("Failed to craft/equip sword. Stopping.")
  148.                 break
  149.             end
  150.         end
  151.         if turtle.suck() then
  152.             print("Picked up items. Depositing to chest...")
  153.             depositItems()
  154.         end
  155.         local success, data = turtle.inspect()
  156.         if success and data.name == "minecraft:zombie_piglin" then
  157.             print("Zombie piglin detected! Attacking...")
  158.             turtle.attack()
  159.         else
  160.             print("No zombie piglin in front. Waiting...")
  161.         end
  162.         os.sleep(1)
  163.     end
  164. end
  165.  
  166. print("Zombie Piglin Hunter v2.0")
  167. if craftStoneSword() and equipSword() then
  168.     huntZombiePiglins()
  169. else
  170.     print("Failed to initialize. Check inventory (slot 4: cobblestone, slot 5: planks) and try again.")
  171. end
Add Comment
Please, Sign In to add comment