Files
scriptLua/getStorageEnergy.lua
2025-08-02 19:41:21 +02:00

60 lines
1.6 KiB
Lua

local function getPeripheralType(direction)
local peripheralType = peripheral.getType(direction)
if not peripheralType then
print("No peripheral found in that direction.")
return nil
end
return peripheralType
end
local function findPeripheral(typeOfPeripheral)
local peripheral = peripheral.find(typeOfPeripheral)
if not peripheral then
print("No peripheral found in that direction.")
return nil
end
return peripheral
end
local function uraniniteReactorStorageEnergy(peripheral)
if peripheral.getStoredEnergy then
return peripheral.getStoredEnergy()
else
print("The peripheral does not support getting stored energy.")
return nil
end
end
local function checkDirectionIsValid(direction)
if not direction or direction == "quit" or direction == "exit" then
print("No direction specified, exiting.")
return false
end
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
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