Record Class AccessTransformerEntry.Mod
java.lang.Object
java.lang.Record
dev.architectury.loom.accesstransformer.AccessTransformerEntry.Mod
- Record Components:
modId- mod 的 id(原FabricModJson.getId())modSchemaVersion- mod 元数据的 schema 版本(原FabricModJson.getVersion(),只参与身份)data- 规则文件内容hash- 规则内容的 sha256(只参与身份,与改造前同源)
- All Implemented Interfaces:
AccessTransformerEntry
- Enclosing interface:
AccessTransformerEntry
public static record AccessTransformerEntry.Mod(String modId, int modSchemaVersion, byte[] data, String hash)
extends Record
implements AccessTransformerEntry
来自 mod 自带的 为什么这里不持有
它是
META-INF/accesstransformer.cfg.
为什么这里不持有 FabricModJson
它是 AccessTransformerJarProcessor.Spec 的元素,而 spec 会作为
ProcessMinecraftJarTask 的任务状态写进配置缓存。FabricModJson 的两个部分都不可序列化:
规则内容的来源可能是源码集(SourceSetSource 持有 Project 与 SourceSet),
元数据本体是 Gson 的 JsonObject。实测(Gradle 9.5,--configuration-cache):
带 project 自带 accesstransformer.cfg 的 Forge 工程在存储阶段直接以
cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject' 失败。
规则内容本来就已在 buildSpec 里读过一遍(为了算 hash),故这里直接持有它。
为什么身份是显式写出来的
改造前的身份来自 record 自动生成的实现(对 [FabricModJson.hashCode(), hash] 做
从 0 开始的 31 折),spec.hashCode() 是处理产物路径与缓存值的来源,
不能因为改造而漂移(AccessTransformerJarProcessorTest 钉住了这个值)。
显式写法必须与 record 的合并方式一致:Objects.hash(...) 是「从 1 开始」,会得到另一个数。-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.architectury.loom.accesstransformer.AccessTransformerEntry
AccessTransformerEntry.Mod, AccessTransformerEntry.Standalone -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]data()Returns the value of thedatarecord component.boolean与hashCode()同源的等值判定:只比身份,不比规则文件字节.hash()Returns the value of thehashrecord component.inthashCode()身份与改造前逐位一致(合并方式见 record 的注释:从 0 开始的 31 折).modId()Returns the value of themodIdrecord component.intReturns the value of themodSchemaVersionrecord component.toString()Returns a string representation of this record class.
-
Constructor Details
-
Mod
Creates an instance of aModrecord class.- Parameters:
modId- the value for themodIdrecord componentmodSchemaVersion- the value for themodSchemaVersionrecord componentdata- the value for thedatarecord componenthash- the value for thehashrecord component
-
-
Method Details
-
openReader
- Specified by:
openReaderin interfaceAccessTransformerEntry- Throws:
IOException
-
hashCode
public int hashCode()身份与改造前逐位一致(合并方式见 record 的注释:从 0 开始的 31 折). -
equals
与hashCode()同源的等值判定:只比身份,不比规则文件字节. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
modId
Returns the value of themodIdrecord component.- Returns:
- the value of the
modIdrecord component
-
modSchemaVersion
public int modSchemaVersion()Returns the value of themodSchemaVersionrecord component.- Returns:
- the value of the
modSchemaVersionrecord component
-
data
public byte[] data()Returns the value of thedatarecord component.- Returns:
- the value of the
datarecord component
-
hash
Returns the value of thehashrecord component.- Returns:
- the value of the
hashrecord component
-