Advertisement
AkaShiroKage

MEItemComparer

May 24th, 2024 (edited)
512
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | Source Code | 1 0
  1. local ME = peripheral.find("meBridge")
  2.  
  3. local deuteriumReg = "gtceu:deuterium"
  4. local tritiumReg = "gtceu:tritium"
  5.  
  6. local tritiumFromDeuteriumCraft = {
  7.   name = tritiumReg,
  8.   count = 40
  9. }
  10.  
  11. local function getFluidME(fluidRegistryName)
  12.   assert(type(fluidRegistryName) == "string", "Please enter a valid registry name!")
  13.   local serializedFluidsList = textutils.serialize(ME.listFluid()) -- get fluids from ME network
  14.  
  15.   local fluidStart = string.find(serializedFluidsList, "  {\n    name = \"" .. fluidRegistryName) -- find first occurence of fluid
  16.   local fluidEnd = string.find(serializedFluidsList, '},\n  {', fluidStart) -- get ending bracket of fluid entry
  17.   assert(fluidStart ~= nil and fluidEnd ~= nil)
  18.  
  19.   local fluidMEData = string.sub(serializedFluidsList, fluidStart, fluidEnd)
  20.   return textutils.unserialise(fluidMEData)
  21. end
  22.  
  23. -- check for equal fluid amount --
  24. local function equalFluids(itemA, itemB)
  25.   return getFluidME(itemA).amount == getFluidME(itemB).amount
  26. end
  27.  
  28. -- periodically check if fluids are equal, craft more if not --
  29. while (true) do
  30.   if not equalFluids(tritiumReg, deuteriumReg) then
  31.     ME.craftFluid(tritiumFromDeuteriumCraft)
  32.     print("Crafting 40mB of Tritium Gas with 160mB of Deuterium Gas...")
  33.   end
  34.  
  35.   os.sleep(0.5)
  36. end
Tags: AE2 gtceu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement