Skip to content
This repository was archived by the owner on Oct 29, 2026. It is now read-only.

Commit b4cb0ae

Browse files
Release API 2.1.1 with strict wildcard inputs
Require EnergyInput's wildcard type and dynamic flag to agree in the canonical constructor, rejecting a wildcard input that does not lock its type and a dynamic input that names a concrete type. Drop the silent rewrite that turned every dynamic input's type into ANY. Bump the API to 2.1.1 and document the new validation.
1 parent 0dcf045 commit b4cb0ae

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ GT6CE 的独立公共 API 仓库,提供纯 Java 契约与按 Minecraft/加载
2323

2424
| 坐标 | 产物目录 |
2525
| --- | --- |
26-
| `gregtech:gt6ce-api:2.1.0` | `common/build/libs/` |
27-
| `gregtech:gt6ce-addon-sdk-1.20.1-forge:2.1.0` | `minecraft/versions/1.20.1-forge/build/libs/` |
28-
| `gregtech:gt6ce-addon-sdk-1.21.1-neoforge:2.1.0` | `minecraft/versions/1.21.1-neoforge/build/libs/` |
26+
| `gregtech:gt6ce-api:2.1.1` | `common/build/libs/` |
27+
| `gregtech:gt6ce-addon-sdk-1.20.1-forge:2.1.1` | `minecraft/versions/1.20.1-forge/build/libs/` |
28+
| `gregtech:gt6ce-addon-sdk-1.21.1-neoforge:2.1.1` | `minecraft/versions/1.21.1-neoforge/build/libs/` |
2929

3030
每项包含 binary、sources 和 javadoc JAR。游戏 SDK 使用开发环境的 Mojang 名称,仅声明公共库为传递依赖;消费者还需对应 Minecraft/加载器开发环境。这些坐标是发布配置,不表示已上传公共 Maven 服务。公共库的 publication 为 `api`,平台为 `addonApi`,发布仓库需另行配置。
3131

@@ -265,9 +265,16 @@ API 版本仍以 `common/build.gradle` 为准。0.3 包含公开签名删除,
265265
- `MaterialTextureSet.modeled()` 行为不变,Javadoc 明确它当前等于 `values()`;`getByProducts()` 与 `getCompositionComponents()` 现在返回新列表,不再返回内部视图。
266266
- `ModData.bindPresence` 在尚未绑定时先检查注册表是否已初始化:在材料元数据之后调用会抛 `IllegalStateException`,且不再留下已绑定状态;已绑定时仍报出首个绑定者。`InstalledService` 为此新增只读的 `isBound()`。
267267

268+
## 2.1.1 迁移与兼容
269+
270+
2.1.1 修复 `EnergyInput` 能构造出通配符类型却不是动态输入的问题。`GregTechAddons.apiVersion()` 保持版本码 `2001`(补丁版本不改变版本码)。公开签名不变,但此前能通过的错误声明现在会抛 `IllegalArgumentException`。
271+
272+
- `EnergyInput` 的规范构造器要求 `type().wildcard()` 与 `dynamic()` 一致:`EnergyInput.builder(EnergyType.ANY, 32).build()` 会报错,直接构造 `dynamic=true` 的非通配符输入同样报错。此前这类输入能通过 `RecipeMachine` 与 `AuxiliaryEnergy` 的 `dynamic()` 检查,把通配符类型带进宿主。
273+
- 构造器不再把 `dynamic=true` 的输入类型静默改写为 `EnergyType.ANY`。需要动态类型时使用 `Builder.anyType()`,它会把 `type()` 设为通配符并置 `dynamic=true`;类型由调用方显式提供,不再由构造器代改。
274+
268275
## 兼容性检查
269276

270-
`common/check` 会运行 japicmp,把构建出的 `gt6ce-api` JAR 与 `common/api-baseline/gt6ce-api-1.1.0.jar` 比较。1.2 到 2.1 的破坏已在上节列明,因此 `apiCompatibility` 目前只报告差异、不因二进制不兼容失败;`common/api-baseline/` 中没有 1.5.0、1.6.0、2.0.0 或 2.1.0 的 JAR,发布新基线后再替换并恢复 `--error-on-binary-incompatibility`。`@ApiStatus.Internal` 类型已从比较中排除:它们仍随 JAR 发布,但不在兼容承诺内。
277+
`common/check` 会运行 japicmp,把构建出的 `gt6ce-api` JAR 与 `common/api-baseline/gt6ce-api-1.1.0.jar` 比较。1.2 到 2.1.1 的破坏已在上节列明,因此 `apiCompatibility` 目前只报告差异、不因二进制不兼容失败;`common/api-baseline/` 中没有 1.5.0、1.6.0、2.0.0、2.1.0 或 2.1.1 的 JAR,发布新基线后再替换并恢复 `--error-on-binary-incompatibility`。`@ApiStatus.Internal` 类型已从比较中排除:它们仍随 JAR 发布,但不在兼容承诺内。
271278

272279
`apiCompatibilitySince030` 是只报告的任务,对照 `gt6ce-api-0.3.0.jar` 输出 0.3 到 1.0 的公开契约差异(`@ApiStatus.Internal` 类型除外)。1.0 的删除已在上一节列明,因此该任务不参与 `check`。
273280

‎common/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tasks.named('test') {
2525
}
2626

2727
group = 'gregtech'
28-
version = '2.1.0'
28+
version = '2.1.1'
2929
base { archivesName = 'gt6ce-api' }
3030

3131
java {

‎common/src/main/java/gregtech/api/energy/EnergyInput.java‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* them in {@link MachineFace#index()} order. A capacity of zero is the behavior-machine default
1414
* and is stored as unspecified, so it is indistinguishable from leaving capacity unset.
1515
*
16-
* @param type the energy type; {@link EnergyType#ANY} when {@link #dynamic()} is true
16+
* @param type the energy type; {@link EnergyType#ANY} exactly when {@link #dynamic()} is true
1717
* @param perTick energy consumed each tick
1818
* @param rangeMin smallest accepted packet, or 0 when no range was declared
1919
* @param rangeMax largest accepted packet, or 0 when no range was declared
@@ -35,7 +35,10 @@ public record EnergyInput(EnergyType type, long perTick, long rangeMin, long ran
3535
throw new IllegalArgumentException("Energy input cannot both limit packets and accept any packet");
3636
if (capacity < 0)
3737
throw new IllegalArgumentException("Negative energy capacity");
38-
type = dynamic ? EnergyType.ANY : type;
38+
if (type.wildcard() != dynamic)
39+
throw new IllegalArgumentException(dynamic
40+
? "A dynamic energy input must use the wildcard type, not " + type
41+
: "The wildcard energy type needs a dynamic input");
3942
faces = MachineFace.canonical(faces, "energy face");
4043
}
4144

@@ -113,8 +116,9 @@ public Builder anyPacket() {
113116

114117
/**
115118
* Lock the energy type from the first accepted packet. Only a behavior machine's main input
116-
* may use this; {@link #type()} becomes {@link EnergyType#ANY}. The constructor type is
117-
* replaced; {@code EnergyInput.builder(EnergyType.EU, 32).anyType()} is the usual form.
119+
* may use this; {@link #type()} becomes {@link EnergyType#ANY}. The type passed to
120+
* {@link #builder} is replaced; {@code EnergyInput.builder(EnergyType.EU, 32).anyType()}
121+
* is the usual form.
118122
*/
119123
public Builder anyType() {
120124
dynamic = true;
@@ -134,14 +138,13 @@ public Builder overload(boolean enabled) {
134138

135139
public EnergyInput build() {
136140
if (type == null) throw new IllegalArgumentException("Missing energy input type");
137-
EnergyType resolved = dynamic ? EnergyType.ANY : type;
138141
if (rangeDeclared && (rangeMin < 1 || rangeMax < rangeMin))
139142
throw new IllegalArgumentException("Invalid energy range: " + rangeMin + ".." + rangeMax);
140143
if (anyPacket && rangeDeclared)
141144
throw new IllegalArgumentException("Energy input cannot both limit packets and accept any packet");
142145
if (capacity < 0)
143146
throw new IllegalArgumentException("Negative energy capacity");
144-
return new EnergyInput(resolved, perTick, rangeMin, rangeMax, facesSpecified, faces, capacity,
147+
return new EnergyInput(type, perTick, rangeMin, rangeMax, facesSpecified, faces, capacity,
145148
anyPacket, overload, dynamic);
146149
}
147150
}

‎common/src/test/java/gregtech/api/contracts/ApiContracts.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ private static void checkSharedValueContracts() {
161161
"withFaces must not change equality for a zero-capacity input");
162162
check(EnergyInput.builder(EnergyType.EU, 32).range(1, 4).build().rangeSpecified(),
163163
"A declared range is reported as specified");
164+
EnergyInput dynamic = EnergyInput.builder(EnergyType.EU, 32).anyType().build();
165+
check(dynamic.dynamic() && dynamic.type().wildcard(),
166+
"A dynamic input must use the wildcard type");
167+
reject(() -> EnergyInput.builder(EnergyType.ANY, 32).build());
168+
reject(() -> new EnergyInput(EnergyType.EU, 32, 0, 0, false, List.of(), 0, false, true, true));
164169
check(EnergyInput.builder(EnergyType.EU, 32).faces(MachineFace.FRONT, MachineFace.TOP).build()
165170
.equals(EnergyInput.builder(EnergyType.EU, 32)
166171
.faces(MachineFace.TOP, MachineFace.FRONT).build()),

0 commit comments

Comments
 (0)