Tesla System Architecture
The Tesla Network is a data-driven energy distribution system implemented via SavedData to ensure persistence and cross-dimensional functionality without requiring chunk loading for energy calculations.
Backend: TeslaTeamEnergyData
The core of the network resides in TeslaTeamEnergyData.java, which extends Minecraft's SavedData.
Data Structure
- Network Map: A
Map<UUID, TeamEnergy>where the UUID represents the team or player frequency. - TeamEnergy Class: Contains the
storedandcapacity(usingjava.math.BigInteger), active endpoints (hatches, soul links, chargers), and flow statistics. - Global Lookup: Maps
BlockPostoUUIDto allow machines to quickly find which network they belong to.
persistence
All data is stored in phoenix_tesla_team_energy.dat in the world's data folder. Since it's attached to the Overworld's data storage, it's globally accessible from any dimension.
Machine Logic
TeslaTowerMachine (The Controller)
- Energy Banking: Uses a custom
TeslaEnergyBanktrait that aggregatesITeslaBatterycapacities into a singleBigIntegerpool. - Syncing: In its server tick, it synchronizes its local
energyBankwith the globalTeslaTeamEnergyData. - Flow Distribution:
- Pulling: Aggregates energy from Input Hatches and Soul-Linked Generators.
- Pushing: Distributes energy to Soul-Linked Consumers.
- Statistics: Calculates
lastNetInputandlastNetOutputevery 20 ticks for UI display.
TeslaEnergyHatchPartMachine
- Wireless Ticking: If not part of a
TeslaTowerMachine, the hatch subscribes to server ticks. - IO Handling:
IO.OUT(Uplink): Drains internal machine buffer →teamData.fill().IO.IN(Downlink):teamData.drain()→ fills internal machine buffer.
- Dynamic Linking: Supports automatic team linking based on owner UUID or manual linking via
TeslaBinderItem.
TeslaWirelessChargerMachine
- Global Search: Iterates through online players on the server.
- Team Validation: Checks
TeamUtils.isPlayerOnTeamto ensure only authorized players receive energy. - Inventory Injection: Uses
GTCapabilityHelper.getElectricItemto charge items in the player's main inventory and Curios slots.
Inter-System Communication
The Tesla Binder (TeslaBinderItem)
The Binder acts as the bridge between the player and the SavedData.
- NBT Sync: During inventoryTick, the binder fetches a snapshot of the TeamEnergy data (including list of all machines and their current EU/t) and stores it in its own NBT.
- UI Rendering: The ModularUI reads this NBT snapshot to display the management interface. This avoids constant SavedData lookups during UI render ticks.
Event Handling
- TeslaLinkEventHandler: Listens for machine placement/removal to ensure the
SavedDatalookup maps stay updated. - Armor Events:
PhoenixArmorEventstriggers checks forteslaModeto handle flight and discharge logic, drawing directly from theTeslaTeamEnergyDataglobal instance.
Performance Considerations
- BigInteger: Used for all energy storage to prevent overflows at OpV+ tiers.
- Tick Subscriptions: Hatches only tick when they are actively wireless and not part of a Tower (which handles its own internal hatches), reducing unnecessary tick overhead.
- Snapshotting: The Binder UI uses 5-tick snapshots rather than per-tick updates to minimize server-to-client NBT synchronization traffic.