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 开始」,会得到另一个数。
  • Constructor Details

    • Mod

      public Mod(String modId, int modSchemaVersion, byte[] data, String hash)
      Creates an instance of a Mod record class.
      Parameters:
      modId - the value for the modId record component
      modSchemaVersion - the value for the modSchemaVersion record component
      data - the value for the data record component
      hash - the value for the hash record component
  • Method Details

    • openReader

      public Reader openReader() throws IOException
      Specified by:
      openReader in interface AccessTransformerEntry
      Throws:
      IOException
    • hashCode

      public int hashCode()
      身份与改造前逐位一致(合并方式见 record 的注释:从 0 开始的 31 折).
      Specified by:
      hashCode in class Record
    • equals

      public boolean equals(Object o)
      与 hashCode() 同源的等值判定:只比身份,不比规则文件字节.
      Specified by:
      equals in class Record
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • modId

      public String modId()
      Returns the value of the modId record component.
      Returns:
      the value of the modId record component
    • modSchemaVersion

      public int modSchemaVersion()
      Returns the value of the modSchemaVersion record component.
      Returns:
      the value of the modSchemaVersion record component
    • data

      public byte[] data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component
    • hash

      public String hash()
      Returns the value of the hash record component.
      Returns:
      the value of the hash record component