Codebase

From Electrical Age
Jump to: navigation, search

First, if you haven't read it yet, see Developing for how to make your own local copy of a project. If you're just browsing the source, read on.

For the remainder of this document, I'll be using the forward slash (/) as the path separator, as it is on most UNIX-like operating systems. This should be equally valid on Windows, despite its normal path separator being the backslash (\). If you're on Windows, take note that some of the paths you see may appear different as a result. Similarly, the "absolute paths" (starting with /) will be relative to the repository root--wherever you cloned that, or are viewing it. Finally, if a path ends with a slash, it means that it's a directory.

Code and Assets

Everything of this sort lives in /src/main/. When building, you may find some siblings in /src/, like api/ or test/ appear--you can safely ignore these.

Under /src/main/, you will find two directories, java/ and resources/. The former is the code, and the latter is the assets.

Code

In /src/main/java/, you may find a few directories, many of which are APIs linked to by ELN, such as ComputerCraft and OpenComputers APIs. The main content lives in mods/eln/; there, you will find all of the following content.

Components and Simulation

  • Eln.java: The main mod file. It is absolutely enormous as of this writing, and we are sorry. This is where all the blocks, items, recipes, etc. get registered. If you're going to add a completely new block, item, recipe, etc., you will have to add it somewhere in this file.
  • sim/: The Big Bad itself. The Simulator is responsible for running all the Processes in various orders, and solving all the circuits made out of Nodes in the world, once per tick.
    • mna/: Stands for Modified Nodal Analysis. This is the core of the Electrical Age Engine code.
      • component/: All of the various basic components. Some of these are built from parts of one another. Everything inherits from `Component`, and then `Bipole`. Most things inherit `Resistor`, `Capacitor`, `Inductor`, or `VoltageSource`.
      • state/: All of the various nodes (as the actual MNA terminology uses it) that are the connection points for components. Components can also be connected to Null instead of a State. Everything in this package inherits from `State`, and some with very little change code-wise.
      • process/: A lot of processes that are independent of the states or components, these are used mostly for inter-subsystem solves.
      • misc/: This folder mostly contains constants (which should be kept here and not in Eln.java, so that when you run the MNA independently of Minecraft it still works!), and various interface classes that are used in the MNA.
      • SubSystem.java: SubSystem is a single subsystem (See it as the single instance of a complete MNA matrix) which calculates everything with regards to an actual MNA itself.
      • RootSystem.java: RootSystem ties together a lot of SubSystems, with "InterSystem" (as we tend to call it) classes that connect various subsystems together.
    • nbt/: Various classes that wrap stateful components into the Minecraft code.
    • process/: Various classes, including watchdogs, explosions, and some thermal code.
    • - various classes -: A set of classes that do various things close to the simulator, such as simulating the thermal system, and other components such as batteries and other devices. These are built from components in the MNA itself, but usually use the nbt wrappers to store state.
  • node/: This is where all the Node base classes live, including NodeBase, NodeBlock, and so forth. The base classes for SixNode and TransparentNode also live here.
  • sixnode/: This is where all the realized (derived from) SixNode content lives, like the Signal Processor, the Sensors, all of the Cables, Switches, Relays, Capacitors and Inductors, etc.
  • transparentnode/: This is where almost all the realized TransparentNode content lives, like the Thermal Dissipators, Solar Panels, all of the Machines, Batteries, the wind, water, and Heat turbines, and so forth.
  • gridnode/: Code for the T1 and T2 electrical Grids (the latter is undocumented as of this writing), such as the Grid Transformer. They have a common GridNode base, which is a TransparentNode as well. These tend to use GhostNodes often; see ghost/ below. Quite a lot of this is Kotlin.
  • mechanical/: Code for the mechanical (shaft) networks, including the steam and Gas turbine (but not the other ones above), the Generator, the Motor, and so forth. They are also derivatives of TransparentNode, and also majority Kotlin.
  • simplenode/: Pretty much just the Electrical Age to other energy exporter and the Energy Exporters.

Minecraft Interaction

  • item/: Plenty of the items which have no in-world representation, like Machine Boosters, Alloy Dust, the X-Ray Scanner, the Light Bulbs, and so forth.
  • entity/: Really, only the Replicator mob.
  • fluid/: Interacts with Forge's fluid API. Mostly used by the steam and Gas turbines, but also the Fluid Heat Furnace.
  • generic/: The Generic Proxy System used by ELN. In essence, this encodes a large number of different items and blocks in the Minecraft world by using damage values as identifiers, preventing the exhaustion of Block and Item IDs. This system will probably be supplanted in the upcoming 1.10 port with BlockState.
  • packets/: Network packet encoder/decoders sent over the wire.
  • server/: Various serverside things, like the ConsoleListener which interprets chat commands, and PlayerManager and PlayerMetadata, which handle the "wrench" key functionality.
  • client/: Various clientside things, including FrameTime which updates rendered objects' animations in accordance with the real time clock, and the event listener which handles the "wrench" key presses.
  • sound/: Utilities for playing sound, continuously or per event, in various ways.
  • gui/: Various classes to help with rendering the clientside interfaces.

Supporting Code

  • fsm/: Finite State Machines, for long, state-oriented processes, like the Turret or Transporter.
  • ghost/: Handles "ghost" blocks with no rendering that bound the larger objects (entities, really), like the Utility poles, Grid Transformer, Large Solar Panels, Autominer, the Transporter, and so forth.
  • cable/: Only the rendering of cables (which is quite complex); the actual cable itself is a SixNode.
  • misc/: Tons of utility classes, the WindProcess for the Wind turbines, some of the code for the network protocol, the famous Cordoonate, LRDU, and Direction classes, and other dragons of all shapes and sizes.

Everything Else

Do note that there's some blatantly dead code hanging around in the base; if it's not referenced in Eln.java, it's probably not in the game.

And, of course, beware of all the scary things hiding in the dark corners of the codebase. You may, of course, run into them, and may even need to use them, but warning has been given--people who are 100% aware of how everything works together are few and far between.

Assets

Back out in /src/main/resources/, one finds two files: mcmod.info (which declares some important high-level info about the mod, like its name, requirements, authors, logo, etc.), and assets/eln/, which contains the following content:

  • logo.png: Wow, that looks kinda nice.
  • model/, model-to-be-integrated/: All of the Models that get rendered as tile entities. The two directories are separated because Obj3DFolder loads every file which ends in a .obj extension under model/. See Modelling for more information.
  • sprites/: Various textures used within the game engine, such as masks for cable textures, and a couple atlas textures of unknown use. Notably, however, it contains a subdirectory:
    • sprites/gui/: Contains the interfaces for various machines; nominally 256x256 pixel PNGs with transparency, you'll also notice (in some) "off-screen" areas that contain, e.g., the animated arrow in the case of the furnace. Many of the active elements, such as buttons and inventory slots, are missing from these backgrounds--and added by the Gui and Container classes, using pixel positions.
  • sounds.json, sounds/: The former is a sounds.json file, as would be loaded by a resource pack, and defines all the sounds loaded by the mod. The latter directory is the root of the search for the sounds named in sounds.json. See Sounds.
  • lang/: Translation files.
  • textures/: Image files mostly intended to be displayed in inventory slots, with occasional exception:
    • textures/armor/: One exception; these are UV-mapped textures for the Ecoal and Copper Armor.
    • textures/entity/: The other exception; UV-mapped textures for the Replicator (and, presumably, other mobs).
    • textures/voltages/: Backgrounds for the various "voltage levels" or tiers; this is what contributes the background color to some inventory slots. Many of these are PNGs with translucency throughout.
    • textures/items/, textures/blocks/: Item and block textures, as seen in inventories. The filenames correspond to the string names given to the Generic Proxy System constructors, lowercase and with spaces removed.
    • textures/wire.png: Another weird exception, this is the cable texture used for Grid links. (Arguably better placed in sprites/...)