gtnh-java-style-skill 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,38 +1,38 @@
1
- This package contains components under two licenses.
2
-
3
- 1. Installer code (`bin/`, tests, and package scaffolding)
4
- MIT License
5
-
6
- Copyright (c) 2026 contributors
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy
9
- of this software and associated documentation files (the "Software"), to deal
10
- in the Software without restriction, including without limitation the rights
11
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- copies of the Software, and to permit persons to whom the Software is
13
- furnished to do so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in all
16
- copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- SOFTWARE.
25
-
26
- 2. Skill documentation (`skill/`)
27
- Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
28
-
29
- Adapted from:
30
- GT New Horizons Wiki — “Code Style”
31
- https://wiki.gtnewhorizons.com/wiki/Code_Style
32
-
33
- The source wiki states that its content is available under CC BY-SA 4.0
34
- unless otherwise noted. The adapted skill documentation is distributed under
35
- the same license.
36
-
37
- License text:
38
- https://creativecommons.org/licenses/by-sa/4.0/legalcode
1
+ This package contains components under two licenses.
2
+
3
+ 1. Installer code (`bin/`, tests, and package scaffolding)
4
+ MIT License
5
+
6
+ Copyright (c) 2026 contributors
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+
26
+ 2. Skill documentation (`skill/`)
27
+ Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
28
+
29
+ Adapted from:
30
+ GT New Horizons Wiki — “Code Style”
31
+ https://wiki.gtnewhorizons.com/wiki/Code_Style
32
+
33
+ The source wiki states that its content is available under CC BY-SA 4.0
34
+ unless otherwise noted. The adapted skill documentation is distributed under
35
+ the same license.
36
+
37
+ License text:
38
+ https://creativecommons.org/licenses/by-sa/4.0/legalcode
package/README.md CHANGED
@@ -1,58 +1,56 @@
1
- # gtnh-java-style-skill
2
-
3
- An installable [Agent Skills](https://agentskills.io/) package for GT New Horizons Java code style.
4
-
5
- It turns the GTNH Code Style wiki page into a compact agent workflow plus an on-demand reference, so coding agents can apply the conventions while writing and reviewing Java.
6
-
7
- ## Install with npx
8
-
9
- After publishing to npm:
10
-
11
- ```bash
12
- npx gtnh-java-style-skill
13
- ```
14
-
15
- Default destination:
16
-
17
- ```text
18
- ~/.agents/skills/gtnh-java-style/
19
- ```
20
-
21
- Install into another skills directory:
22
-
23
- ```bash
24
- npx gtnh-java-style-skill --dir ~/.claude/skills
25
- ```
26
-
27
- Replace an existing installation:
28
-
29
- ```bash
30
- npx gtnh-java-style-skill --force
31
- ```
32
-
33
- ## Local development
34
-
35
- ```bash
36
- npm test
37
- npm run check
38
- ```
39
-
40
- Test the package exactly as npm will publish it:
41
-
42
- ```bash
43
- npm pack
44
- npx ./gtnh-java-style-skill-0.1.0.tgz --dir ./tmp-skills
45
- ```
46
-
47
- ## Publish
48
-
49
- 1. Pick an available npm package name if `gtnh-java-style-skill` is already taken.
50
- 2. Run `npm login`.
51
- 3. Run `npm run check`.
52
- 4. Run `npm publish`.
53
-
54
- The package has one `bin` entry, so `npx gtnh-java-style-skill` resolves directly to the installer.
55
-
56
- ## Licensing and attribution
57
-
58
- The installer code is MIT licensed. The skill documentation is adapted from the GT New Horizons Wiki “Code Style” page and is licensed under CC BY-SA 4.0. See `LICENSE` for details.
1
+ # gtnh-java-style-skill
2
+
3
+ An installable [Agent Skills](https://agentskills.io/) package for GT New Horizons Java code style.
4
+
5
+ It turns the GTNH Code Style wiki page into a compact agent workflow plus an on-demand reference, so coding agents can apply the conventions while writing and reviewing Java.
6
+
7
+ ## Install with npx
8
+
9
+ ```bash
10
+ npx gtnh-java-style-skill
11
+ ```
12
+
13
+ Default destination:
14
+
15
+ ```text
16
+ ~/.agents/skills/gtnh-java-style/
17
+ ```
18
+
19
+ Install into another skills directory:
20
+
21
+ ```bash
22
+ npx gtnh-java-style-skill --dir ~/.claude/skills
23
+ ```
24
+
25
+ Replace an existing installation:
26
+
27
+ ```bash
28
+ npx gtnh-java-style-skill --force
29
+ ```
30
+
31
+ ## Local development
32
+
33
+ ```bash
34
+ npm test
35
+ npm run check
36
+ ```
37
+
38
+ Test the package exactly as npm will publish it:
39
+
40
+ ```bash
41
+ npm pack
42
+ npx ./gtnh-java-style-skill-0.1.0.tgz --dir ./tmp-skills
43
+ ```
44
+
45
+ ## Publish
46
+
47
+ 1. Pick an available npm package name if `gtnh-java-style-skill` is already taken.
48
+ 2. Run `npm login`.
49
+ 3. Run `npm run check`.
50
+ 4. Run `npm publish`.
51
+
52
+ The package has one `bin` entry, so `npx gtnh-java-style-skill` resolves directly to the installer.
53
+
54
+ ## Licensing and attribution
55
+
56
+ The installer code is MIT licensed. The skill documentation is adapted from the GT New Horizons Wiki “Code Style” page and is licensed under CC BY-SA 4.0. See `LICENSE` for details.
package/bin/cli.mjs CHANGED
@@ -1,87 +1,87 @@
1
- #!/usr/bin/env node
2
-
3
- import { cp, mkdir, rm, stat } from 'node:fs/promises';
4
- import { homedir } from 'node:os';
5
- import { dirname, join } from 'node:path';
6
- import { fileURLToPath } from 'node:url';
7
-
8
- const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
9
- const source = join(packageRoot, 'skill');
10
- const skillName = 'gtnh-java-style';
11
-
12
- function usage() {
13
- return `Usage: gtnh-java-style-skill [options]\n\n` +
14
- `Installs the ${skillName} Agent Skill.\n\n` +
15
- `Options:\n` +
16
- ` --dir <path> Parent skills directory (default: ~/.agents/skills)\n` +
17
- ` --force Replace an existing installation\n` +
18
- ` -h, --help Show this help\n`;
19
- }
20
-
21
- function parseArgs(argv) {
22
- let dir = join(homedir(), '.agents', 'skills');
23
- let force = false;
24
-
25
- for (let i = 0; i < argv.length; i += 1) {
26
- const arg = argv[i];
27
- if (arg === '--force') {
28
- force = true;
29
- } else if (arg === '--dir') {
30
- const value = argv[i + 1];
31
- if (!value || value.startsWith('--')) {
32
- throw new Error('--dir requires a path');
33
- }
34
- dir = value;
35
- i += 1;
36
- } else if (arg === '--help' || arg === '-h') {
37
- return { help: true, dir, force };
38
- } else {
39
- throw new Error(`unknown option: ${arg}`);
40
- }
41
- }
42
-
43
- return { help: false, dir, force };
44
- }
45
-
46
- async function exists(path) {
47
- try {
48
- await stat(path);
49
- return true;
50
- } catch (error) {
51
- if (error?.code === 'ENOENT') return false;
52
- throw error;
53
- }
54
- }
55
-
56
- async function main() {
57
- let options;
58
- try {
59
- options = parseArgs(process.argv.slice(2));
60
- } catch (error) {
61
- console.error(`error: ${error.message}\n`);
62
- console.error(usage());
63
- process.exitCode = 2;
64
- return;
65
- }
66
-
67
- if (options.help) {
68
- process.stdout.write(usage());
69
- return;
70
- }
71
-
72
- const target = join(options.dir, skillName);
73
- if (await exists(target)) {
74
- if (!options.force) {
75
- console.error(`error: ${target} already exists; use --force to replace it`);
76
- process.exitCode = 1;
77
- return;
78
- }
79
- await rm(target, { recursive: true, force: true });
80
- }
81
-
82
- await mkdir(options.dir, { recursive: true });
83
- await cp(source, target, { recursive: true });
84
- console.log(`installed ${skillName} -> ${target}`);
85
- }
86
-
87
- await main();
1
+ #!/usr/bin/env node
2
+
3
+ import { cp, mkdir, rm, stat } from 'node:fs/promises';
4
+ import { homedir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
9
+ const source = join(packageRoot, 'skill');
10
+ const skillName = 'gtnh-java-style';
11
+
12
+ function usage() {
13
+ return `Usage: gtnh-java-style-skill [options]\n\n` +
14
+ `Installs the ${skillName} Agent Skill.\n\n` +
15
+ `Options:\n` +
16
+ ` --dir <path> Parent skills directory (default: ~/.agents/skills)\n` +
17
+ ` --force Replace an existing installation\n` +
18
+ ` -h, --help Show this help\n`;
19
+ }
20
+
21
+ function parseArgs(argv) {
22
+ let dir = join(homedir(), '.agents', 'skills');
23
+ let force = false;
24
+
25
+ for (let i = 0; i < argv.length; i += 1) {
26
+ const arg = argv[i];
27
+ if (arg === '--force') {
28
+ force = true;
29
+ } else if (arg === '--dir') {
30
+ const value = argv[i + 1];
31
+ if (!value || value.startsWith('--')) {
32
+ throw new Error('--dir requires a path');
33
+ }
34
+ dir = value;
35
+ i += 1;
36
+ } else if (arg === '--help' || arg === '-h') {
37
+ return { help: true, dir, force };
38
+ } else {
39
+ throw new Error(`unknown option: ${arg}`);
40
+ }
41
+ }
42
+
43
+ return { help: false, dir, force };
44
+ }
45
+
46
+ async function exists(path) {
47
+ try {
48
+ await stat(path);
49
+ return true;
50
+ } catch (error) {
51
+ if (error?.code === 'ENOENT') return false;
52
+ throw error;
53
+ }
54
+ }
55
+
56
+ async function main() {
57
+ let options;
58
+ try {
59
+ options = parseArgs(process.argv.slice(2));
60
+ } catch (error) {
61
+ console.error(`error: ${error.message}\n`);
62
+ console.error(usage());
63
+ process.exitCode = 2;
64
+ return;
65
+ }
66
+
67
+ if (options.help) {
68
+ process.stdout.write(usage());
69
+ return;
70
+ }
71
+
72
+ const target = join(options.dir, skillName);
73
+ if (await exists(target)) {
74
+ if (!options.force) {
75
+ console.error(`error: ${target} already exists; use --force to replace it`);
76
+ process.exitCode = 1;
77
+ return;
78
+ }
79
+ await rm(target, { recursive: true, force: true });
80
+ }
81
+
82
+ await mkdir(options.dir, { recursive: true });
83
+ await cp(source, target, { recursive: true });
84
+ console.log(`installed ${skillName} -> ${target}`);
85
+ }
86
+
87
+ await main();
package/package.json CHANGED
@@ -1,35 +1,35 @@
1
- {
2
- "name": "gtnh-java-style-skill",
3
- "version": "0.1.0",
4
- "description": "Install an Agent Skill that teaches coding agents the GT New Horizons Java code style.",
5
- "type": "module",
6
- "bin": {
7
- "gtnh-java-style-skill": "./bin/cli.mjs"
8
- },
9
- "files": [
10
- "bin",
11
- "skill",
12
- "README.md",
13
- "LICENSE"
14
- ],
15
- "scripts": {
16
- "test": "node --test",
17
- "check": "npm test && npm pack --dry-run"
18
- },
19
- "engines": {
20
- "node": ">=18"
21
- },
22
- "keywords": [
23
- "agent-skills",
24
- "gtnh",
25
- "gt-new-horizons",
26
- "java",
27
- "code-style",
28
- "codex",
29
- "claude-code"
30
- ],
31
- "license": "SEE LICENSE IN LICENSE",
32
- "publishConfig": {
33
- "access": "public"
34
- }
35
- }
1
+ {
2
+ "name": "gtnh-java-style-skill",
3
+ "version": "0.1.1",
4
+ "description": "Install an Agent Skill that teaches coding agents the GT New Horizons Java code style.",
5
+ "type": "module",
6
+ "bin": {
7
+ "gtnh-java-style-skill": "bin/cli.mjs"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "skill",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "test": "node --test",
17
+ "check": "npm test && npm pack --dry-run"
18
+ },
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "keywords": [
23
+ "agent-skills",
24
+ "gtnh",
25
+ "gt-new-horizons",
26
+ "java",
27
+ "code-style",
28
+ "codex",
29
+ "claude-code"
30
+ ],
31
+ "license": "SEE LICENSE IN LICENSE",
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }
package/skill/SKILL.md CHANGED
@@ -1,47 +1,48 @@
1
- ---
2
- name: gtnh-java-style
3
- description: Use when writing, reviewing, refactoring, or formatting Java code for GT New Horizons (GTNH), especially when a task mentions GTNH, GregTech 5 Unofficial, GTNH mods, Spotless, Java code style, naming, comments, logging, declarations, deprecation, or pull-request readability.
4
- license: CC-BY-SA-4.0
5
- metadata:
6
- source: https://wiki.gtnewhorizons.com/wiki/Code_Style
7
- version: "0.1.0"
8
- ---
9
-
10
- # GTNH Java Style
11
-
12
- Apply GTNH's Java conventions while keeping behavior changes and style changes easy to review.
13
-
14
- ## Priority order
15
-
16
- 1. Preserve correctness and requested behavior.
17
- 2. Follow repository-local formatter/linter configuration, especially Spotless.
18
- 3. Apply the GTNH conventions in [references/style-guide.md](references/style-guide.md).
19
- 4. Prefer readability when a literal rule would create needless ceremony, unless the readable shortcut introduces a known pitfall.
20
-
21
- Do not churn unrelated legacy code merely to make it match the guide.
22
-
23
- ## Workflow
24
-
25
- Before editing, inspect nearby code and build configuration. Determine whether the module exposes Spotless tasks and whether modern Java syntax is enabled.
26
-
27
- While editing:
28
-
29
- - Keep files reasonably sized; treat 2000 lines as a warning sign, not an automatic refactor mandate.
30
- - Order class members consistently: static fields, instance fields, constructors, then methods grouped by functionality.
31
- - Delete commented-out code instead of preserving it as comments.
32
- - Prefer code that explains itself; write comments for intent, constraints, or non-obvious reasoning rather than narrating syntax.
33
- - Declare variables at the beginning of the relevant block and initialize locals at declaration when practical.
34
- - Use descriptive mixed-case names: noun-like classes, verb-like methods, meaningful variables.
35
- - Avoid unexplained magic constants and chained assignments.
36
- - Keep fields non-public unless public state is genuinely part of the API.
37
- - Keep `@Deprecated` and `@deprecated` Javadoc paired, and point to the replacement.
38
- - Use parentheses generously in mixed-operator expressions when they improve clarity.
39
- - For GTNH logs, normally use one write call per line; keep one-sentence messages lowercase.
40
-
41
- After editing, run the repository's formatter/checker if available. Prefer the project's own Gradle tasks over manually reformatting around them.
42
-
43
- ## Review output
44
-
45
- When reviewing code, report concrete violations with the smallest useful fix. Separate formatter-enforced issues from judgment calls. If a proposed style change would reduce readability or create broad diff noise, leave it alone and explain why.
46
-
47
- For exact examples and edge cases, read [references/style-guide.md](references/style-guide.md).
1
+ ---
2
+ name: gtnh-java-style
3
+ description: Use when writing, reviewing, refactoring, or formatting Java code for GT New Horizons (GTNH), especially when a task mentions GTNH, GregTech 5 Unofficial, GTNH mods, Spotless, Java code style, naming, comments, logging, declarations, deprecation, or pull-request readability.
4
+ license: CC-BY-SA-4.0
5
+ metadata:
6
+ source: https://wiki.gtnewhorizons.com/wiki/Code_Style
7
+ version: "0.1.0"
8
+ ---
9
+
10
+ # GTNH Java Style
11
+
12
+ Apply GTNH's Java conventions while keeping behavior changes and style changes easy to review.
13
+
14
+ ## Priority order
15
+
16
+ 1. Preserve correctness and requested behavior.
17
+ 2. Follow repository-local formatter/linter configuration, especially Spotless.
18
+ 3. Apply the GTNH conventions in [references/style-guide.md](references/style-guide.md).
19
+ 4. Prefer readability when a literal rule would create needless ceremony, unless the readable shortcut introduces a known pitfall.
20
+
21
+ Do not churn unrelated legacy code merely to make it match the guide.
22
+
23
+ ## Workflow
24
+
25
+ Before editing, inspect nearby code and build configuration. Determine whether the module exposes Spotless tasks and whether modern Java syntax is enabled.
26
+
27
+ While editing:
28
+
29
+ - Keep files reasonably sized; treat 2000 lines as a warning sign, not an automatic refactor mandate.
30
+ - Order class members consistently: static fields, instance fields, constructors, then methods grouped by functionality.
31
+ - Delete commented-out code instead of preserving it as comments.
32
+ - Prefer code that explains itself; write comments for intent, constraints, or non-obvious reasoning rather than narrating syntax.
33
+ - Declare variables at the beginning of the relevant block and initialize locals at declaration when practical.
34
+ - Use descriptive mixed-case names: noun-like classes, verb-like methods, meaningful variables.
35
+ - Avoid unexplained magic constants and chained assignments.
36
+ - Keep fields non-public unless public state is genuinely part of the API.
37
+ - Keep `@Deprecated` and `@deprecated` Javadoc paired, and point to the replacement.
38
+ - Use parentheses generously in mixed-operator expressions when they improve clarity.
39
+ - For GTNH logs, normally use one write call per line; keep one-sentence messages lowercase.
40
+ - Do not use wildcard imports; static wildcard imports are allowed.
41
+
42
+ After editing, run the repository's formatter/checker if available. Prefer the project's own Gradle tasks over manually reformatting around them.
43
+
44
+ ## Review output
45
+
46
+ When reviewing code, report concrete violations with the smallest useful fix. Separate formatter-enforced issues from judgment calls. If a proposed style change would reduce readability or create broad diff noise, leave it alone and explain why.
47
+
48
+ For exact examples and edge cases, read [references/style-guide.md](references/style-guide.md).
@@ -1,134 +1,157 @@
1
- # GTNH Java Code Style Reference
2
-
3
- Source: GT New Horizons Wiki, “Code Style” — https://wiki.gtnewhorizons.com/wiki/Code_Style
4
-
5
- This reference is an adapted, condensed form of that page. The source wiki content is available under CC BY-SA 4.0; this adaptation is distributed under the same terms.
6
-
7
- ## Philosophy and formatter
8
-
9
- Consistency exists to reduce maintenance cost and make pull requests easier to read. Code is read far more often than it is written. Use good judgment: readability may override a guideline when strict compliance would be needless or less clear, but do not trade away safety merely for visual simplicity.
10
-
11
- GTNH uses Spotless for line wrapping, spacing, and indentation. When a repository provides Spotless tasks, treat their result as authoritative for mechanical formatting.
12
-
13
- ## File and class organization
14
-
15
- Avoid files longer than **2000 lines** when practical.
16
-
17
- Inside a class or interface, use this broad order:
18
-
19
- 1. Optional documentation comment.
20
- 2. Class or interface declaration.
21
- 3. Optional implementation-wide comment.
22
- 4. Static fields: public, protected, package-private, private.
23
- 5. Instance fields in the same accessibility order.
24
- 6. Constructors.
25
- 7. Methods grouped by functionality, not by visibility. A private helper may sit between public methods if that makes the feature easier to follow.
26
-
27
- ## Comments
28
-
29
- Delete commented-out code; Git history already preserves old implementations. Avoid comments that are likely to become stale. Before adding a comment, consider whether clearer code would remove the need for it. Do not decorate comments with giant boxes of asterisks.
30
-
31
- Use `//` for a short single-line comment. For a multi-line explanatory comment, use a conventional block:
32
-
33
- ```java
34
- /*
35
- * Explain the non-obvious reason here.
36
- */
37
- ```
38
-
39
- `@author` is optional because version control already records authorship.
40
-
41
- ## Declarations
42
-
43
- Prefer one declaration per line unless variables are tightly coupled, such as 3D coordinates:
44
-
45
- ```java
46
- int x, y, z;
47
- ```
48
-
49
- Never mix declaration styles or types in a confusing declaration. Initialize local variables where they are declared unless some required computation must happen first.
50
-
51
- Place declarations at the **beginning of blocks**. In this guide, a block is code enclosed by braces. Avoid delaying a declaration until its first use.
52
-
53
- ## Statements
54
-
55
- When modern Java syntax is enabled for the mod, prefer a modern switch form:
56
-
57
- ```java
58
- switch (condition) {
59
- case ABC, DEF, KLM -> {
60
- handleGroup();
61
- }
62
- case XYZ -> {
63
- handleXyz();
64
- }
65
- default -> {
66
- handleDefault();
67
- }
68
- }
69
- ```
70
-
71
- Do not introduce syntax newer than the module's configured Java compatibility allows.
72
-
73
- ## Naming
74
-
75
- - **Classes:** noun-like, descriptive UpperCamelCase names. Prefer whole words; use acronyms only when widely understood.
76
- - **Interfaces:** UpperCamelCase like classes.
77
- - **Methods:** verb-like lowerCamelCase names, such as `run()` or `getBackgroundColor()`.
78
- - **Variables:** meaningful lowerCamelCase names. Start with a letter rather than `_` or `$`.
79
-
80
- Short names are fine when their role is obvious and local; otherwise optimize for intent rather than keystrokes.
81
-
82
- ## GTNH log formatting
83
-
84
- For uniform logs, normally use **one write call per line**. A one-sentence log message should usually begin lowercase. If the message contains multiple sentences, normal sentence capitalization is appropriate.
85
-
86
- ## Programming practices
87
-
88
- Do not expose instance or class variables as `public` without a good reason. Prefer behavior-oriented methods over direct mutable state access when that produces a clearer API.
89
-
90
- Replace unexplained literal values with well-named constants when the value has domain meaning:
91
-
92
- ```java
93
- private static final int RECIPE_ID = 16281;
94
-
95
- methodName(RECIPE_ID);
96
- ```
97
-
98
- Avoid chained assignments such as:
99
-
100
- ```java
101
- fooBar.fChar = barFoo.lchar = 'c';
102
- ```
103
-
104
- They save little space and make state changes harder to scan.
105
-
106
- ## Deprecation
107
-
108
- `@Deprecated` and the `@deprecated` Javadoc tag must appear together. The Javadoc should identify the replacement or migration path.
109
-
110
- ```java
111
- /**
112
- * @deprecated use {@link DBHelper#update(String, Map)}
113
- */
114
- @Deprecated(forRemoval = true)
115
- public int insert(String request, Map<String, ?> params) {
116
- // existing behavior
117
- }
118
- ```
119
-
120
- ## Parentheses
121
-
122
- Use **parentheses** liberally when expressions mix operators and grouping could otherwise be misread. Prefer:
123
-
124
- ```java
125
- if ((a == b) && (c == d)) {
126
- run();
127
- }
128
- ```
129
-
130
- over relying on every reader to mentally evaluate precedence correctly.
131
-
132
- ## Review checklist
133
-
134
- Check in this order: formatter/Spotless, member organization, comments, declarations, naming, GTNH log style, field visibility, constants, assignments, deprecation pairing, then expression clarity. Keep fixes local to the touched code unless the user explicitly requests a broader cleanup.
1
+ # GTNH Java Code Style Reference
2
+
3
+ Source: GT New Horizons Wiki, “Code Style” — https://wiki.gtnewhorizons.com/wiki/Code_Style
4
+
5
+ This reference is an adapted, condensed form of that page. The source wiki content is available under CC BY-SA 4.0; this adaptation is distributed under the same terms.
6
+
7
+ ## Philosophy and formatter
8
+
9
+ Consistency exists to reduce maintenance cost and make pull requests easier to read. Code is read far more often than it is written. Use good judgment: readability may override a guideline when strict compliance would be needless or less clear, but do not trade away safety merely for visual simplicity.
10
+
11
+ GTNH uses Spotless for line wrapping, spacing, and indentation. When a repository provides Spotless tasks, treat their result as authoritative for mechanical formatting.
12
+
13
+ ## File and class organization
14
+
15
+ Avoid files longer than **2000 lines** when practical.
16
+
17
+ Inside a class or interface, use this broad order:
18
+
19
+ 1. Optional documentation comment.
20
+ 2. Class or interface declaration.
21
+ 3. Optional implementation-wide comment.
22
+ 4. Static fields: public, protected, package-private, private.
23
+ 5. Instance fields in the same accessibility order.
24
+ 6. Constructors.
25
+ 7. Methods grouped by functionality, not by visibility. A private helper may sit between public methods if that makes the feature easier to follow.
26
+
27
+ ## Comments
28
+
29
+ Delete commented-out code; Git history already preserves old implementations. Avoid comments that are likely to become stale. Before adding a comment, consider whether clearer code would remove the need for it. Do not decorate comments with giant boxes of asterisks.
30
+
31
+ Use `//` for a short single-line comment. For a multi-line explanatory comment, use a conventional block:
32
+
33
+ ```java
34
+ /*
35
+ * Explain the non-obvious reason here.
36
+ */
37
+ ```
38
+
39
+ `@author` is optional because version control already records authorship.
40
+
41
+ ## Declarations
42
+
43
+ Prefer one declaration per line unless variables are tightly coupled, such as 3D coordinates:
44
+
45
+ ```java
46
+ int x, y, z;
47
+ ```
48
+
49
+ Never mix declaration styles or types in a confusing declaration. Initialize local variables where they are declared unless some required computation must happen first.
50
+
51
+ Place declarations at the **beginning of blocks**. In this guide, a block is code enclosed by braces. Avoid delaying a declaration until its first use.
52
+
53
+ ## Statements
54
+
55
+ When modern Java syntax is enabled for the mod, prefer a modern switch form:
56
+
57
+ ```java
58
+ switch (condition) {
59
+ case ABC, DEF, KLM -> {
60
+ handleGroup();
61
+ }
62
+ case XYZ -> {
63
+ handleXyz();
64
+ }
65
+ default -> {
66
+ handleDefault();
67
+ }
68
+ }
69
+ ```
70
+
71
+ Do not introduce syntax newer than the module's configured Java compatibility allows.
72
+
73
+ ## Naming
74
+
75
+ - **Classes:** noun-like, descriptive UpperCamelCase names. Prefer whole words; use acronyms only when widely understood.
76
+ - **Interfaces:** UpperCamelCase like classes.
77
+ - **Methods:** verb-like lowerCamelCase names, such as `run()` or `getBackgroundColor()`.
78
+ - **Variables:** meaningful lowerCamelCase names. Start with a letter rather than `_` or `$`.
79
+
80
+ Short names are fine when their role is obvious and local; otherwise optimize for intent rather than keystrokes.
81
+
82
+ ## GTNH log formatting
83
+
84
+ For uniform logs, normally use **one write call per line**. A one-sentence log message should usually begin lowercase. If the message contains multiple sentences, normal sentence capitalization is appropriate.
85
+
86
+ ## Programming practices
87
+
88
+ Do not expose instance or class variables as `public` without a good reason. Prefer behavior-oriented methods over direct mutable state access when that produces a clearer API.
89
+
90
+ Replace unexplained literal values with well-named constants when the value has domain meaning:
91
+
92
+ ```java
93
+ private static final int RECIPE_ID = 16281;
94
+
95
+ methodName(RECIPE_ID);
96
+ ```
97
+
98
+ Avoid chained assignments such as:
99
+
100
+ ```java
101
+ fooBar.fChar = barFoo.lchar = 'c';
102
+ ```
103
+
104
+ They save little space and make state changes harder to scan.
105
+
106
+ ## Deprecation
107
+
108
+ `@Deprecated` and the `@deprecated` Javadoc tag must appear together. The Javadoc should identify the replacement or migration path.
109
+
110
+ ```java
111
+ /**
112
+ * @deprecated use {@link DBHelper#update(String, Map)}
113
+ */
114
+ @Deprecated(forRemoval = true)
115
+ public int insert(String request, Map<String, ?> params) {
116
+ // existing behavior
117
+ }
118
+ ```
119
+
120
+ ## Parentheses
121
+
122
+ Use **parentheses** liberally when expressions mix operators and grouping could otherwise be misread. Prefer:
123
+
124
+ ```java
125
+ if ((a == b) && (c == d)) {
126
+ run();
127
+ }
128
+ ```
129
+
130
+ over relying on every reader to mentally evaluate precedence correctly.
131
+
132
+ ## Imports
133
+
134
+ Do not use wildcard imports. GTNH checks this automatically.
135
+
136
+ Prefer explicit imports:
137
+
138
+ ```java
139
+ import java.util.List;
140
+ import java.util.Map;
141
+ ```
142
+
143
+ Avoid:
144
+
145
+ ```java
146
+ import java.util.*;
147
+ ```
148
+
149
+ Static wildcard imports are allowed:
150
+
151
+ ```java
152
+ import static org.junit.Assert.*;
153
+ ```
154
+
155
+ ## Review checklist
156
+
157
+ Check in this order: formatter/Spotless, member organization, comments, declarations, naming, GTNH log style, field visibility, constants, assignments, deprecation pairing, then expression clarity. Keep fixes local to the touched code unless the user explicitly requests a broader cleanup.