Skip to content

Instantly share code, notes, and snippets.

@tildejustin
Created January 30, 2026 03:37
Show Gist options
  • Select an option

  • Save tildejustin/4dfdf38e1ca8fdf9e8c2255ef1437fbb to your computer and use it in GitHub Desktop.

Select an option

Save tildejustin/4dfdf38e1ca8fdf9e8c2255ef1437fbb to your computer and use it in GitHub Desktop.
remap obsfucated mod to named. I should make a gui that automatically downloads mappings and minecraft jar for this.
plugins {
id 'java'
}
group = 'org.example'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven { url "https://maven.fabricmc.net" }
maven { url "https://maven.legacyfabric.net" }
maven { url "https://jitpack.io" }
}
dependencies {
implementation "net.fabricmc:tiny-remapper:0.11.0"
implementation "net.fabricmc:mapping-io:0.7.1"
implementation "net.legacyfabric:intermediary:<version>"
}
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.fabricmc.tinyremapper.*;
import java.io.*;
import java.nio.file.Paths;
public class Main {
public static void main(String... args) throws IOException {
var tree = new MemoryMappingTree();
try (InputStream mappings = Main.class.getResourceAsStream("mappings/mappings.tiny")) {
// you've got bigger problems if you don't have a mappings set
assert mappings != null;
MappingReader.read(new InputStreamReader(mappings), tree);
}
TinyRemapper remapper = TinyRemapper.newRemapper()
.withMappings(TinyRemapperMappingsHelper.create(tree, "official", "named"))
.renameInvalidLocals(true)
.rebuildSourceFilenames(true)
.checkPackageAccess(true)
.fixPackageAccess(true)
.build();
remapper.readInputs(Paths.get("OptiFine_<version>_MOD.jar"));
remapper.readClassPath(Paths.get("minecraft-client-<version>.jar"));
OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(Paths.get("out.jar")).build();
remapper.apply(outputConsumer);
remapper.finish();
outputConsumer.close();
}
}
/*
* Copyright 2016 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.tinyremapper.IMappingProvider;
public class TinyRemapperMappingsHelper {
private TinyRemapperMappingsHelper() {
}
private static IMappingProvider.Member memberOf(String className, String memberName, String descriptor) {
return new IMappingProvider.Member(className, memberName, descriptor);
}
public static IMappingProvider create(MappingTree mappings, String from, String to) {
return (acceptor) -> {
final int fromId = mappings.getNamespaceId(from);
final int toId = mappings.getNamespaceId(to);
for (MappingTree.ClassMapping classDef : mappings.getClasses()) {
final String className = classDef.getName(fromId);
String dstName = classDef.getName(toId);
if (dstName == null) {
dstName = className;
}
acceptor.acceptClass(className, dstName);
for (MappingTree.FieldMapping field : classDef.getFields()) {
acceptor.acceptField(memberOf(className, field.getName(fromId), field.getDesc(fromId)), field.getName(toId));
}
for (MappingTree.MethodMapping method : classDef.getMethods()) {
IMappingProvider.Member methodIdentifier = memberOf(className, method.getName(fromId), method.getDesc(fromId));
acceptor.acceptMethod(methodIdentifier, method.getName(toId));
}
}
acceptor.acceptField(new IMappingProvider.Member("bqm", "renderDistance", "I"), "renderDistance_OF");
acceptor.acceptMethod(new IMappingProvider.Member("cbi", "rotate", "(Lcv;I)I"), "rotate_OF");
acceptor.acceptMethod(new IMappingProvider.Member("cbi", "rotate", "(Lcv;)Lcv;"), "rotate_OF");
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment