mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-25 21:40:05 +00:00
Chained mod target overlays
- Mod targets list an ordered overlay chain; later overlays replace earlier ones and earlier source replacements apply to inherited files - Forge and NeoForge metadata take their loader version range from the target - The Fabric permissions library is bundled only for targets that declare it - Dropped the 1.21.1 mods.toml copies that only differed in the loader range
This commit is contained in:
1 parent
03c2630497
commit
79e7b0c79e
9 files changed
+116
-58
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import groovy.json.JsonSlurper
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
Configuration nativeMinecraftSources = configurations.create('nativeMinecraftSources') {
|
||||
@@ -8,31 +9,42 @@ Configuration nativeMinecraftSources = configurations.create('nativeMinecraftSou
|
||||
|
||||
String nativeSourceLoader = extensions.extraProperties.get('nativeSourceLoader')
|
||||
String nativeSourceImplementation = 'minecraft26_2'
|
||||
String nativeSourceMinecraftVersion = providers.gradleProperty('minecraftVersion').getOrElse('26.3')
|
||||
String versionPrefix = "versions/${nativeSourceMinecraftVersion}/"
|
||||
List<String> nativeSourceOverlays = (List<String>) irisModTarget.overlays
|
||||
List<String> versionPrefixes = nativeSourceOverlays.collect { String overlay -> "versions/${overlay}/".toString() }
|
||||
extensions.extraProperties.set('nativeSourceImplementation', nativeSourceImplementation)
|
||||
dependencies.add(nativeMinecraftSources.name,
|
||||
"com.github.VolmitSoftware.VolmLib:native-${nativeSourceImplementation}-sources:master-SNAPSHOT")
|
||||
|
||||
Set<String> overrides = new HashSet<>()
|
||||
Map<String, Object> replacements = [:]
|
||||
List<Set<String>> overlayEntries = versionPrefixes.collect { String ignored -> new HashSet<String>() }
|
||||
List<Map<String, Object>> overlayReplacements = versionPrefixes.collect { String ignored -> new HashMap<String, Object>() }
|
||||
Closure<Integer> overlayOrigin = { String path ->
|
||||
for (int index = overlayEntries.size() - 1; index >= 0; index--) {
|
||||
if (overlayEntries.get(index).contains(path)) {
|
||||
return index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
TaskProvider<Sync> unpackNativeMinecraftSources = tasks.register('unpackNativeMinecraftSources', Sync) {
|
||||
dependsOn(nativeMinecraftSources)
|
||||
inputs.property('minecraftVersion', nativeSourceMinecraftVersion)
|
||||
inputs.property('overlays', nativeSourceOverlays)
|
||||
inputs.property('loader', nativeSourceLoader)
|
||||
doFirst {
|
||||
overrides.clear()
|
||||
overlayEntries.each { Set<String> entries -> entries.clear() }
|
||||
overlayReplacements.each { Map<String, Object> rules -> rules.clear() }
|
||||
for (File artifact : nativeMinecraftSources) {
|
||||
new ZipFile(artifact).withCloseable { ZipFile archive ->
|
||||
archive.entries().each { entry ->
|
||||
if (entry.name.startsWith(versionPrefix)) {
|
||||
overrides.add(entry.name.substring(versionPrefix.length()))
|
||||
versionPrefixes.eachWithIndex { String versionPrefix, int index ->
|
||||
archive.entries().each { ZipEntry entry ->
|
||||
if (entry.name.startsWith(versionPrefix)) {
|
||||
overlayEntries.get(index).add(entry.name.substring(versionPrefix.length()))
|
||||
}
|
||||
}
|
||||
}
|
||||
java.util.zip.ZipEntry rules = archive.getEntry(versionPrefix + 'source-replacements.json')
|
||||
if (rules != null) {
|
||||
archive.getInputStream(rules).withCloseable { InputStream stream ->
|
||||
replacements = (Map<String, Object>) new JsonSlurper().parse(stream)
|
||||
ZipEntry rules = archive.getEntry(versionPrefix + 'source-replacements.json')
|
||||
if (rules != null) {
|
||||
archive.getInputStream(rules).withCloseable { InputStream stream ->
|
||||
overlayReplacements.get(index).putAll((Map<String, Object>) new JsonSlurper().parse(stream))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,32 +54,40 @@ TaskProvider<Sync> unpackNativeMinecraftSources = tasks.register('unpackNativeMi
|
||||
include('art/**', 'modded/**', "${nativeSourceLoader}/**",
|
||||
'resources/modded/**', "resources/${nativeSourceLoader}/**")
|
||||
eachFile { FileCopyDetails source ->
|
||||
if (overrides.contains(source.path)) {
|
||||
if (overlayOrigin(source.path) >= 0) {
|
||||
source.exclude()
|
||||
}
|
||||
}
|
||||
}
|
||||
from(provider { nativeMinecraftSources.collect { File artifact -> zipTree(artifact) } }) {
|
||||
include("${versionPrefix}art/**", "${versionPrefix}modded/**", "${versionPrefix}${nativeSourceLoader}/**",
|
||||
"${versionPrefix}resources/modded/**", "${versionPrefix}resources/${nativeSourceLoader}/**")
|
||||
eachFile { FileCopyDetails source -> source.path = source.path.substring(versionPrefix.length()) }
|
||||
versionPrefixes.eachWithIndex { String versionPrefix, int index ->
|
||||
from(provider { nativeMinecraftSources.collect { File artifact -> zipTree(artifact) } }) {
|
||||
include("${versionPrefix}art/**", "${versionPrefix}modded/**", "${versionPrefix}${nativeSourceLoader}/**",
|
||||
"${versionPrefix}resources/modded/**", "${versionPrefix}resources/${nativeSourceLoader}/**")
|
||||
eachFile { FileCopyDetails source ->
|
||||
source.path = source.path.substring(versionPrefix.length())
|
||||
if (overlayOrigin(source.path) != index) {
|
||||
source.exclude()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
includeEmptyDirs = false
|
||||
into(layout.buildDirectory.dir('generated/sources/native-minecraft'))
|
||||
doLast {
|
||||
List<Map<String, String>> rules = (List<Map<String, String>>) (replacements.get('global') ?: [])
|
||||
Map<String, List<Map<String, String>>> fileRules = (Map<String, List<Map<String, String>>>) (replacements.get('files') ?: [:])
|
||||
project.fileTree(destinationDir).matching { include('**/*.java') }.each { File source ->
|
||||
String path = destinationDir.toPath().relativize(source.toPath()).toString().replace(File.separator, '/')
|
||||
if (!overrides.contains(path)) {
|
||||
String content = source.getText('UTF-8')
|
||||
String rewritten = content
|
||||
String content = source.getText('UTF-8')
|
||||
String rewritten = content
|
||||
for (int index = overlayOrigin(path) + 1; index < overlayReplacements.size(); index++) {
|
||||
Map<String, Object> replacements = overlayReplacements.get(index)
|
||||
List<Map<String, String>> rules = (List<Map<String, String>>) (replacements.get('global') ?: [])
|
||||
Map<String, List<Map<String, String>>> fileRules = (Map<String, List<Map<String, String>>>) (replacements.get('files') ?: [:])
|
||||
for (Map<String, String> rule : rules + (fileRules.get(path) ?: [])) {
|
||||
rewritten = rewritten.replaceAll(rule.pattern, rule.replacement)
|
||||
}
|
||||
if (content != rewritten) {
|
||||
source.setText(rewritten, 'UTF-8')
|
||||
}
|
||||
}
|
||||
if (content != rewritten) {
|
||||
source.setText(rewritten, 'UTF-8')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user