Skip to content

Instantly share code, notes, and snippets.

@CorgiTaco
Last active May 18, 2022 01:51
Show Gist options
  • Save CorgiTaco/e4b5f7c968988e8c65bcf9f0093fd602 to your computer and use it in GitHub Desktop.
Save CorgiTaco/e4b5f7c968988e8c65bcf9f0093fd602 to your computer and use it in GitHub Desktop.
import net.fabricmc.loom.api.mappings.layered.MappingContext
import net.fabricmc.loom.api.mappings.layered.MappingLayer
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace
import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec
import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingLayer
import net.fabricmc.mappingio.MappingVisitor
import net.fabricmc.mappingio.tree.MemoryMappingTree
buildscript {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
}
dependencies {
classpath group: 'net.fabricmc', name: 'mapping-io', version: '0.3.0', changing: true
}
}
dependencies {
// auto-generate mappings to stop mojmap conflicts with geckolib
mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:${project.parchment_mappings}@zip")
// don't convert this to a dynamic instantiation, otherwise java won't see the overridden hashCode
addLayer(new MappingsSpec<MappingLayer>() {
final Map<String, String> METHOD_NAME_MAP = Map.of(
"getTextureLocation", "_getTextureLocation"
)
@Override
MappingLayer createLayer(MappingContext mappingContext) {
return new MappingLayer() {
@Override
void visit(MappingVisitor mappingVisitor) throws IOException {
MemoryMappingTree memoryMappingTree = mappingVisitor as MemoryMappingTree
memoryMappingTree.getClasses().forEach(classEntry -> {
classEntry.methods.forEach(methodEntry -> {
String newMethodName = METHOD_NAME_MAP.get(methodEntry.getName(MappingsNamespace.NAMED.toString()))
if (newMethodName != null) {
//noinspection GroovyAccessibility
methodEntry.srcName = newMethodName
}
})
})
}
@Override
MappingsNamespace getSourceNamespace() {
return MappingsNamespace.NAMED
}
@Override
List<Class<? extends MappingLayer>> dependsOn() {
return List.of(IntermediaryMappingLayer.class)
}
}
}
@Override
int hashCode() {
// used to make sure caches stay consistent
return METHOD_NAME_MAP.hashCode()
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment