-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
303 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
enum ModLoaderType { | ||
Fabric = 1, | ||
Forge, | ||
Quilt, | ||
} | ||
|
||
namespace ModLoaderType { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import ModMetadata from "../../metadata/mod-metadata"; | ||
import ZippedModMetadataReader from "../../metadata/zipped-mod-metadata-reader"; | ||
import QuiltModMetadata from "./quilt-mod-metadata"; | ||
|
||
export default class QuiltModMetadataReader extends ZippedModMetadataReader { | ||
constructor() { | ||
super("quilt.mod.json"); | ||
} | ||
|
||
protected loadConfig(buffer: Buffer): Record<string, unknown> { | ||
return JSON.parse(buffer.toString("utf8")); | ||
} | ||
|
||
protected createMetadataFromConfig(config: Record<string, unknown>): ModMetadata { | ||
return new QuiltModMetadata(config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import action from "../../../package.json"; | ||
import Dependency from "../../metadata/dependency"; | ||
import DependencyKind from "../../metadata/dependency-kind"; | ||
import ModConfig from "../../metadata/mod-config"; | ||
import ModConfigDependency from "../../metadata/mod-config-dependency"; | ||
import PublisherTarget from "../../publishing/publisher-target"; | ||
|
||
function extractId(id?: string): string | null { | ||
if (!id) { | ||
return id ?? null; | ||
} | ||
|
||
const separatorIndex = id.indexOf(":"); | ||
if (separatorIndex !== -1) { | ||
id = id.substring(separatorIndex + 1); | ||
} | ||
|
||
return id; | ||
} | ||
|
||
function getDependencyEntries(container: any, transformer?: (x: any) => void): any[] { | ||
if (!Array.isArray(container)) { | ||
return []; | ||
} | ||
|
||
if (transformer) { | ||
container = container.map(x => typeof x === "string" ? ({ id: x }) : ({ ...x })); | ||
container.forEach(transformer); | ||
} | ||
return container; | ||
} | ||
|
||
const ignoredByDefault = ["minecraft", "java", "quilt_loader"]; | ||
const aliases = new Map([ | ||
["fabric", "fabric-api"], | ||
["quilted_fabric_api", "qsl"], | ||
]); | ||
function createDependency(body: any): Dependency { | ||
const id = extractId(typeof body === "string" ? body : String(body.id ?? "")); | ||
const ignore = ignoredByDefault.includes(id); | ||
if (id.startsWith("quilted_") || id.startsWith("quilt_")) { | ||
aliases.set(id, "qsl"); | ||
} | ||
|
||
if (typeof body === "string") { | ||
const dependencyAliases = aliases.has(id) ? new Map(PublisherTarget.getValues().map(x => [x, aliases.get(id)])) : null; | ||
return Dependency.create({ id, ignore, aliases: dependencyAliases }); | ||
} | ||
|
||
const dependencyMetadata = { | ||
ignore, | ||
...body, | ||
id, | ||
version: body.version ?? String(Array.isArray(body.versions) ? body.versions[0] : body.versions || "*"), | ||
kind: ( | ||
body.incompatible && body.unless && DependencyKind.Conflicts || | ||
body.incompatible && DependencyKind.Breaks || | ||
body.embedded && DependencyKind.Includes || | ||
body.optional && DependencyKind.Recommends || | ||
DependencyKind.Depends | ||
) | ||
}; | ||
if (aliases.has(id)) { | ||
if (!dependencyMetadata[action.name]) { | ||
dependencyMetadata[action.name] = {}; | ||
} | ||
for (const target of PublisherTarget.getValues()) { | ||
const targetName = PublisherTarget.toString(target).toLowerCase(); | ||
if (typeof dependencyMetadata[action.name][targetName] !== "string") { | ||
dependencyMetadata[action.name][targetName] = aliases.get(id); | ||
} | ||
} | ||
} | ||
return new ModConfigDependency(dependencyMetadata); | ||
} | ||
|
||
export default class QuiltModMetadata extends ModConfig { | ||
public readonly id: string; | ||
public readonly name: string; | ||
public readonly version: string; | ||
public readonly loaders: string[]; | ||
public readonly dependencies: Dependency[]; | ||
|
||
constructor(config: Record<string, unknown>) { | ||
super(config); | ||
const root = <Record<string, unknown>>this.config.quilt_loader ?? {}; | ||
this.id = String(root.id ?? ""); | ||
this.name = String(root.name ?? this.id); | ||
this.version = String(root.version ?? "*"); | ||
this.loaders = ["quilt"]; | ||
this.dependencies = getDependencyEntries(root.depends) | ||
.concat(getDependencyEntries(root.provides, x => x.embedded = true)) | ||
.concat(getDependencyEntries(root.breaks, x => x.incompatible = true)) | ||
.map(createDependency) | ||
.filter((x, i, self) => self.findIndex(y => x.id === y.id && x.kind === y.kind) === i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ | ||
"schema_version": 1, | ||
"quilt_loader": { | ||
"group": "com.example", | ||
"id": "example-mod", | ||
"version": "0.1.0", | ||
"name": "Example Mod", | ||
"description": "Description", | ||
"authors": [ | ||
"Author" | ||
], | ||
"contact": { | ||
"homepage": "https://github.com/", | ||
"sources": "https://github.com/", | ||
"issues": "https://github.com/", | ||
"wiki": "https://github.com/" | ||
}, | ||
"license": "MIT", | ||
"icon": "icon.jpg", | ||
"intermediate_mappings": "net.fabricmc:intermediary", | ||
"environment": "*", | ||
"entrypoints": { | ||
"main": [ | ||
"example.ExampleMod" | ||
] | ||
}, | ||
"depends": [ | ||
{ | ||
"id": "quilt_loader", | ||
"version": ">=0.11.3" | ||
}, | ||
{ | ||
"id": "quilt_base", | ||
"version": ">=0.40.0" | ||
}, | ||
{ | ||
"id": "minecraft", | ||
"version": "1.17.x" | ||
}, | ||
{ | ||
"id": "java", | ||
"version": ">=16" | ||
}, | ||
{ | ||
"id": "recommended-mod", | ||
"version": "0.2.0", | ||
"optional": true, | ||
"mc-publish": { | ||
"modrinth": "AAAA", | ||
"ignore": true | ||
}, | ||
"projects": { | ||
"curseforge": 42 | ||
}, | ||
"custom": { | ||
"projects": { | ||
"github": "v0.2.0" | ||
} | ||
} | ||
} | ||
], | ||
"provides": [ | ||
"included:included-mod" | ||
], | ||
"breaks": [ | ||
"breaking-mod", | ||
{ | ||
"id": "conflicting:conflicting-mod", | ||
"version": "<0.40.0", | ||
"unless": "fix-conflicting-mod" | ||
} | ||
] | ||
}, | ||
"mc-publish": { | ||
"modrinth": "AANobbMI" | ||
}, | ||
"projects": { | ||
"curseforge": 394468 | ||
}, | ||
"custom": { | ||
"projects": { | ||
"github": "mc1.18-0.4.0-alpha5" | ||
} | ||
}, | ||
"mixins": [ | ||
"example-mod.mixins.json" | ||
], | ||
"access_widener": "example.accesswidener" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters