Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function compareItemName(itemName, slotID)
- if turtle.getItemDetail(slotID) ~= nil and
- turtle.getItemDetail(slotID).name == itemName then
- return true
- else
- return false
- end
- end
- function isBlazeRod(slotID)
- return compareItemName("minecraft:blaze_rod", slotID)
- end
- function isBlazePowder(slotID)
- return compareItemName("minecraft:blaze_powder", slotID)
- end
- function isDiamond(slotID)
- return compareItemName("minecraft:diamond", slotID)
- end
- function isIron(slotID)
- return compareItemName("minecraft:iron_ingot", slotID)
- end
- function isGold(slotID)
- return compareItemName("minecraft:gold_ingot", slotID)
- end
- function isEmerald(slotID)
- return compareItemName("minecraft:emerald", slotID)
- end
- function isNetherStar(slotID)
- return compareItemName("minecraft:nether_star", slotID)
- end
- function isRedstoneBlock(slotID)
- return compareItemName("minecraft:redstone_block", slotID)
- end
- function isBlazingCrystalBlock(slotID)
- return compareItemName("powah:blazing_crystal_block", slotID)
- end
- function isUranium(slotID)
- return compareItemName("emendatusenigmatica:uranium_ingots", slotID)
- end
- ---@diagnostic disable: redefined-local
- function craftBlazeRod(blazeRodSlotID)
- writeMessage("Found Blaze Rod at "..blazeRodSlotID.."\n"..
- "Crafting with Blaze Rod")
- turtle.select(blazeRodSlotID)
- turtle.drop(1)
- end
- function craftBlazePowder()
- writeMessage("Found Blaze Powder"..
- "Crafting with Blaze Powder")
- local needed = 4
- for slotNum = 1, 16, 1 do
- if isBlazePowder(slotNum) then
- local count = turtle.getItemCount(slotNum)
- if (count >= needed) then
- turtle.select(slotNum)
- turtle.drop(needed)
- needed = 0
- else
- turtle.select(slotNum)
- turtle.drop(count)
- needed = needed - count
- end
- end
- if (needed == 0) then
- return
- end
- end
- end
- function craftDiamond(diamondSlotID)
- writeMessage("Found Diamond at "..diamondSlotID.."\n"..
- "Crafting with Diamond")
- turtle.select(diamondSlotID)
- turtle.drop(1)
- end
- function craftIronGold(ironSlotID, goldSlotID)
- writeMessage("Found Iron at "..ironSlotID.."\n"..
- " and Gold at "..goldSlotID.."\n"..
- "Crafting with Iron and Gold")
- turtle.select(ironSlotID)
- turtle.drop(1)
- turtle.select(goldSlotID)
- turtle.drop(1)
- end
- function craftEmerald(emeraldSlotID)
- writeMessage("Found Emerald at "..emeraldSlotID.."\n"..
- "Crafting with Emerald")
- turtle.select(emeraldSlotID)
- turtle.drop(1)
- end
- function craftUranium(uraniumSlotID)
- writeMessage("Found Uranium at "..uraniumSlotID.."\n"..
- "Crafting with Uranium")
- turtle.select(uraniumSlotID)
- turtle.drop(1)
- end
- function craftNitro(starSlotID, redstoneBlockSlotID, blazingCrystalBlockSlotID)
- writeMessage("Found Nether Star at "..starSlotID.."\n"..
- " and Redstone Block at "..redstoneBlockSlotID.."\n"..
- " and Blazing Crystal Block at "..blazingCrystalBlockSlotID.."\n"..
- "Crafting Nitro")
- turtle.select(starSlotID)
- turtle.drop(1)
- turtle.select(redstoneBlockSlotID)
- turtle.drop(2)
- turtle.select(blazingCrystalBlockSlotID)
- turtle.drop(1)
- end
- function doCrafting()
- local canCraft, blazeRodSlotID = shouldCraftBlaze()
- if canCraft then
- craftBlazeRod(blazeRodSlotID)
- return
- end
- local canCraft = shouldCraftBlazePowder()
- if canCraft then
- craftBlazePowder()
- return
- end
- local canCraft, diamondSlotID = shouldCraftDiamond()
- if canCraft then
- craftDiamond(diamondSlotID)
- return
- end
- local canCraft, emeraldSlotID = shouldCraftEmerald()
- if canCraft then
- craftEmerald(emeraldSlotID)
- return
- end
- local canCraft, starSlotID, redstoneBlockSlotID, blazingCrystalBlockSlotID = shouldCraftNitro()
- if canCraft then
- craftNitro(starSlotID, redstoneBlockSlotID, blazingCrystalBlockSlotID)
- return
- end
- local canCraft, ironSlotID, goldSlotID = shouldCraftIronGold()
- if canCraft then
- craftIronGold(ironSlotID, goldSlotID)
- return
- end
- local canCraft, slotID = shouldCraftUranium()
- if canCraft then
- craftUranium(slotID)
- return
- end
- end
- function shouldCraftBlaze()
- for slotNum = 1, 16, 1 do
- if isBlazeRod(slotNum) then
- return true, slotNum
- end
- end
- return false, -1
- end
- function shouldCraftDiamond()
- for slotNum = 1, 16, 1 do
- if isDiamond(slotNum) then
- return true, slotNum
- end
- end
- return false, -1
- end
- function shouldCraftEmerald()
- for slotNum = 1, 16, 1 do
- if isEmerald(slotNum) then
- return true, slotNum
- end
- end
- return false, -1
- end
- function shouldCraftUranium()
- for slotNum = 1, 16, 1 do
- if isUranium(slotNum) then
- return true, slotNum
- end
- end
- return false, -1
- end
- function shouldCraftIronGold()
- local ironSlotID = -1
- local goldSlotID = -1
- for slotNum = 1, 16, 1 do
- if isIron(slotNum) then
- ironSlotID = slotNum
- elseif isGold(slotNum) then
- goldSlotID = slotNum
- end
- end
- local canCraft = ironSlotID > 0 and goldSlotID > 0
- return canCraft, ironSlotID, goldSlotID
- end
- function shouldCraftBlazePowder()
- local count = 0
- for slotNum = 1, 16, 1 do
- if isBlazePowder(slotNum) then
- count = count + turtle.getItemCount(slotNum)
- end
- end
- return count >= 4
- end
- function shouldCraftNitro()
- local starSlotID = -1
- local redstoneBlockSlotID = -1
- local blazingCrystalBlockSlotID = -1
- for slotNum = 1, 16, 1 do
- if isNetherStar(slotNum) then
- starSlotID = slotNum
- elseif isBlazingCrystalBlock(slotNum) then
- blazingCrystalBlockSlotID = slotNum
- elseif isRedstoneBlock(slotNum) and
- turtle.getItemDetail(slotNum).count >= 2 then
- redstoneBlockSlotID = slotNum
- end
- end
- local canCraft = starSlotID > 0 and blazingCrystalBlockSlotID > 0 and redstoneBlockSlotID > 0
- return canCraft, starSlotID, redstoneBlockSlotID, blazingCrystalBlockSlotID
- end
- -- Uncomment those lines if you want to keep
- -- the program as seperate files.
- --dofile("slotChecking.lua")
- --dofile("crafting.lua")
- --dofile("nextCrafting.lua")
- function writeMessage(message)
- term.clear()
- term.setCursorPos(1, 1)
- print("+-----------------------------+")
- print("|Welcome to Powah Autocrafting|")
- print("+-----------------------------+")
- print()
- print(message)
- end
- writeMessage("Startup finished")
- while true do
- doCrafting()
- -- Wait two Redstone ticks for the Redstone Signal to update
- sleep(0.4)
- -- Spin in a loop till crafting is done
- while redstone.getInput("back") do
- sleep(0.4)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement