From 088c5f47a8fe0ca532dd45a1e2f7a014fd14e749 Mon Sep 17 00:00:00 2001 From: Neoblacks Date: Sat, 2 Aug 2025 19:52:52 +0200 Subject: [PATCH] get Energy --- getStorageEnergy.lua | 63 +++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/getStorageEnergy.lua b/getStorageEnergy.lua index 085c46a..174e74b 100644 --- a/getStorageEnergy.lua +++ b/getStorageEnergy.lua @@ -7,13 +7,14 @@ local function getPeripheralType(direction) return peripheralType end -local function findPeripheral(typeOfPeripheral) - local peripheral = peripheral.find(typeOfPeripheral) - if not peripheral then - print("No peripheral found in that direction.") +local function findPeripheralInfo(typeOfPeripheral) + local findingPeripheralInfo = peripheral.find(typeOfPeripheral) + if not findingPeripheralInfo then + print("No peripheral found of type: " .. typeOfPeripheral) return nil end - return peripheral + print("Found peripheral of type: " .. typeOfPeripheral) + return findingPeripheralInfo end local function uraniniteReactorStorageEnergy(peripheral) @@ -33,27 +34,35 @@ local function checkDirectionIsValid(direction) return true end -print("Enter the direction of the peripheral (left, right, top, bottom, front, back):") -local direction = io.read() -if not checkDirectionIsValid(direction) then - return +PeripheralInfo = {} + +local function main() + print("Enter the direction of the peripheral (left, right, top, bottom, front, back):") + local direction = io.read() + if not checkDirectionIsValid(direction) then + return + end + + local typeOfPeripheral = getPeripheralType(direction) + if not typeOfPeripheral then + return + end + + if typeOfPeripheral == "uraninite_reactor" then + -- alors on est dans le cas d'un reacteur de Powah + PeripheralInfo = findPeripheralInfo(typeOfPeripheral) + if PeripheralInfo then + local storedEnergy = uraniniteReactorStorageEnergy(PeripheralInfo) + if storedEnergy then + print("Stored energy in the reactor: " .. storedEnergy .. " RF") + else + print("Could not retrieve stored energy from the reactor.") + end + else + print("No uraninite reactor found in that direction.") + end + return + end end -local typeOfPeripheral = getPeripheralType(direction) -if not typeOfPeripheral then - print("No peripheral found in that direction.") - return -end - -local peripheral = findPeripheral(typeOfPeripheral) -if not peripheral then - print("No peripheral found of type: " .. typeOfPeripheral) - return -end - -if peripheral == "uraninite_reactor" then - local energy = uraniniteReactorStorageEnergy(peripheral) - print("Stored energy in uranium reactor: " .. energy) -else - print("Peripheral type is not a uranium reactor, cannot get stored energy.") -end +main()