Skip to content

Architecture_EN

MIAOKATZE edited this page Jul 12, 2026 · 2 revisions

Architecture & Interfaces

1. Mod Metadata

This section lists the core metadata of the GTSWN mod for quick version and dependency verification.

Field Value
modId gtswn
modName GTSimpleWirelessNetwork
Version 1.5.13
Minecraft 1.7.10
Forge 10.13.4.1614
Java 17 → 8 (jvmDowngrader downgrade)
Core Dependencies GT5U 5.09.54.20, AE2 rv3-beta-1000, GTNHLib 0.11.23, StructureLib 1.4.42, ModularUI 1.3.4, ModularUI2 2.3.79
Optional Dependencies Baubles-Expanded (compileOnly)
modGroup com.miaokatze.gtswn

Java Downgrade Note: The project source code is written in Java 17 syntax and downgraded to Java 8 bytecode via the jvmDowngrader plugin to be compatible with the Minecraft 1.7.10 runtime.

2. Network Packet Protocol

GTSWN uses Forge's SimpleNetworkWrapper for network communication, with channel name "gtswn". Registration entry GTSWNPacketHandler.register() is called during CommonProxy.preInit.

2.1 discriminator Allocation Table

discriminator Packet Class Direction Side
0 PacketRequestWirelessEU C→S Request EU SERVER
1 PacketResponseWirelessEU S→C Response EU CLIENT
2 PacketUpdateNetworkInfoPanelConfig C→S Info Panel Config SERVER
3 PacketUpdateAETabState C→S AE Tab + Monitor List SERVER
4 PacketSyncAEMonitorData S→C AE Monitor Data Sync CLIENT

2.2 Packet 0: PacketRequestWirelessEU

Field Type Description
ownerUUID String Player UUID

Purpose: Client requests the wireless grid EU balance for the specified player UUID; HUD sends this once every 100t.

2.3 Packet 1: PacketResponseWirelessEU

Field Type Description
euStr String EU balance (BigInteger.toString())

Purpose: Server response, calls WirelessMonitorHUD.receiveSyncedEU(euStr).

Thread Safety: In 1.7.10, SimpleChannelHandlerWrapper invokes onMessage on the Netty network thread; game logic must be scheduled back to the main thread.

2.4 Packet 2: PacketUpdateNetworkInfoPanelConfig

Field Type Description
x, y, z int Info panel block coordinates
action int Action type (see table below)
chartConfig String Chart config JSON

action Constants:

Constant Value Description
ACTION_CHART_CONFIG -1 Regular EU chart config
ACTION_AE_CHART_CONFIG -2 AE chart config
ACTION_AE_MONITOR_FONT_SIZE_MINUS 30 AE monitor font size decrease
ACTION_AE_MONITOR_FONT_SIZE_PLUS 31 AE monitor font size increase
ACTION_AE_MONITOR_BOLD_TOGGLE 32 AE monitor bold toggle
ACTION_AE_MONITOR_RENDER_MODE_TOGGLE 33 AE monitor render mode toggle
ACTION_AE_MONITOR_ICON_SIZE_MINUS 34 AE monitor icon size decrease
ACTION_AE_MONITOR_ICON_SIZE_PLUS 35 AE monitor icon size increase
action >= 0 ≥0 Calls panel.applyConfigAction(action)

Distance Check: ≤64D

2.5 Packet 3: PacketUpdateAETabState

Field Type Description
panelX, panelY, panelZ int Info panel block coordinates
actionType byte Action type (see table below)
tabIndex int Tab index
stackData NBTTagCompound Item/fluid data

actionType Table:

actionType Behavior
0 Switch tab
1 Bind item to trend chart
2 Bind fluid to trend chart
3 Toggle item in monitor list
4 Toggle fluid in monitor list
5 Clear trend chart binding
6 Clear all AE realtime monitors

2.6 Packet 4: PacketSyncAEMonitorData

Field Type Description
x, y, z int Info panel block coordinates
chartKey String Trend chart key
chartSamples List Trend chart sample list
monitorLatest Map<String, AEMonitorSample> Monitor latest values
monitorAvg300s Map<String, Double> 300s averages

AEMonitorSample Fields:

Field Type
timeMs long
tick long
amount long
rate double

3. EUDataSet

EUDataSet stores wireless grid EU historical sample data and is the core data structure for trend chart calculation.

3.1 Constants

Constant Value Description
CAPACITY 61 Fixed capacity (0s initial + 60 × 100t checks = 300s)
LONG_SILENT_THRESHOLD_TICKS 6000L Long-term silence threshold (300s)

3.2 Public Methods

Method Signature Purpose
void add(BigInteger value, long tick) Add new measurement (FIFO)
boolean isAllSameValue() Detect silent state
boolean isLongTermSilent() Return long-term silent state
Measurement getNewest() Get newest measurement point
Measurement getOldest() Get oldest measurement point
int size() Current data count (0~CAPACITY)
boolean isFull() Whether full
boolean isEmpty() Whether empty
void clear() Clear and reset longTermSilent
double calculateEUT() Calculate EU/t (first-last slope, BigDecimal precise division 6 decimals HALF_UP)
double calculateRecentEUT() Calculate realtime EU/t (latest 2 samples)
void saveToNBT(NBTTagCompound, String) Serialize to NBT
void loadFromNBT(NBTTagCompound, String) Deserialize from NBT

3.3 NBT Format

measurementHistory: {
  count: <int>,
  m0: { tick, value(string) },
  m1: { ... },
  ...
  m{count-1}: { ... },
  longTermSilent: <boolean>
}

4. WorldSavedData Persistence

GTSWN uses two WorldSavedData subclasses for data persistence, both stored in world.perWorldStorage.

4.1 AEMonitorDataStore

Property Value
DATA_NAME "gtswn_ae_monitor_data"
Storage Location world.perWorldStorage
Data Structure Map<String, AEMonitorDataSet> dataSets
key Format dimensionId:x:y:z (coordinate string)
Granularity Each Network Info Panel block maintains its own AE monitor data independently

4.2 NetworkInfoDataStore

Property Value
DATA_NAME "gtswn_network_info_data"
Storage Location world.perWorldStorage
Data Structure Map<String, NetworkInfoDataSet> dataSets
key Format Player ownerUUID.toString()
Granularity All Network Info Panels of the same player share one dataset

Note: Early versions used per-panel datasetId; this has been changed to ownerUUID. Old data is discarded during deserialization.

5. MTE ID Allocation

GTSWN's MetaTileEntity IDs are allocated using a formula to avoid conflicts with other mods.

5.1 ID Formula

Final ID = BASE (14600) + Config.metaIdOffset (config offset) + relativeId (enum-relative ID)

5.2 BASE Constant

Constant Value
MetaTileEntityID.BASE 14600

5.3 Enum Table

Enum Name relativeId Final ID (default offset=0) Description
WIRELESS_ENERGY_MONITOR 0 14600 LV-tier Wireless Energy Monitor

Currently only 1 MTE ID. Config.metaIdOffset range is [-5000, 5000], used to avoid ID conflicts with other mods.

6. Build Artifacts

GTSWN is built using Gradle Kotlin DSL + GTNH Convention plugin (com.gtnewhorizons.gtnhconvention).

6.1 jar File List

Build artifacts are located in the build/libs/ directory:

Filename Description
gtswn-1.5.13.jar Main jar (release, Java 8 bytecode)
gtswn-1.5.13-dev.jar Dev jar (includes source and debug info)
gtswn-1.5.13-sources.jar Sources jar

6.2 Key Build Configuration

Config Item Value Description
enableModernJavaSyntax jvmDowngrader Written in Java 17 syntax, downgraded to Java 8 bytecode
RELEASE_VERSION 1.5.13 Forced version (overrides git-derived version)
gtnh.modules.gitVersion false Disable gitVersion module
generateGradleTokenClass com.miaokatze.gtswn.Tags Generate version token class

Clone this wiki locally