Как редактировать class файлы minecraft

Обновлено: 13.05.2024

"Просто как в текстовом редакторе" не получится. Это бинарные файлы со строгим форматом.

Можно изучить формат, ознакомиться с принципами работы виртуальной машины, особенно в части загрузки и верификации классов, а потом использовать полученные знания для написания программы, модифицирующей бинарник нужным образом, или взять hex-редактор и сделать это вручную.

Кстати, если jar-файл подписанный, то работать он после этого перестанет.

inClassTranslator - Программа для изменения class файлов

Если нужно заменить какие-то надписи в *.class-файлах игры, он может помочь. Например, для перевода модов и плагинов, для замены ссылок на пути скинов, различных стандартных надписей в игре (а-ля Copyright MojangAB) и для многого другого. Интерфейс программы довольно простой, слева список строк открытого класса, справа сверху текст выбранной строки, а внизу мы пишем свой текст. После изменения нужной надписи, надо кликнуть по ней слева ещё раз. После этого сохраняем и заменяем старый класс изменённым.

How do I edit Minecraft Mod Class files?

I'm trying to edit a single line in Pam's Harvestcraft mod. The reason is that in the game these "gardens" inside the mod spawn too often. There is a config file for this mod, however the lowest possible value for rarity = 1 is still too high. This rarity is an int, and I want to change it to a float inside this Mod's jar's .class file, so that I may be able to use 0.5 or something less than 1 to decrease the chance of these gardens spawning.

I copy and pasted the .class file into intelliJ, but it is readable only. Writing my own text file and changing the extension to .class obviously corrupts the file.

For the past hour I've been trying to Google the answer. People say that you might need to set up a modding environment, decompile the code, then recompile it after the changes. This seems very long-winded for a simple line of code editing.

1, I also need to edit a method that getInt() to getFloat() which I cannot do.

2, When I save the newly edited class file, then try to reopen it using this JOE editor IT IS GIVING ME A FILE ERROR. This indicated to me that if I edit the class file it corrupts it anyways.

97.8k 24 24 gold badges 169 169 silver badges 214 214 bronze badges


47 1 1 gold badge 1 1 silver badge 6 6 bronze badges If it is a compiled .class file, there is a reason for that. I would not do it, or look into the API for the file and then develop something out of that. Plus, manually editing a class file is definitely not the way to go, .class is an unreadable/uneditable format by design - by humans at least. Edit the source (decompiled if not available) and compile it back again. Instead of attempting to modify the class file, perhaps you can extend it or create your own class which periodically updates the rarity value from 1 to 0, or 0 to 1.

2 Answers 2

You technically can do this, but it's going to be a pain. If it were just changing a variable, that might be simple, but now you're also talking about changing a field's type.

There are a couple ways to do this, and I don't see one of them listed, so I'll mention that.

First, you can decompile/recompile. I've tried doing this once before, and it really doesn't work well. There were plenty of errors resulting from the recompilation, because it's not going to be a completely accurate decompilation.

The second option, and this would be the easiest if not for needing to change a field type, is editing the machine code. Java is compiled into assembly code that is specifically used by the JVM. You would find the instruction, change the value, and you would be golden. (I say easiest, but if you've never seen assembly before, it'll all look like Greek to you.)

Back to the issue: You're talking about changing a data type. That won't be enough. You not only would need to change the data type, but every spot that data type is used and its get method is called. Every spot that getter is called, its expecting an int return value. If it's a float going into an int , it'll just be automatically converted to an int .

So that is how you would do it, but it's not really worth your time. Simply ask the developer to make an update for you. In fact, if this is the mod you're talking about, it's already open source and you can make the changes yourself.

Редактирование .class файлов

Есть JAR файл. Необходимо декомпилировать один из его классов, отредактировать одно значение и закомпилировать обратно.


11.3k 7 7 золотых знаков 36 36 серебряных знаков 68 68 бронзовых знаков 441 1 1 золотой знак 7 7 серебряных знаков 23 23 бронзовых знака

Если хотите сделать это одноразово, то попробуйте JAD. Но учтите, что декомпиляторы не всегда могут получить исходник из .class-файла. Предположим, вы сумели его декомпилировать верно. После этого, его надо собрать обратно. Чтобы это сделать, надо воспользоваться компилятором.

(если под виндой, то библиотеки надо разделять точкой с запятой вместо двоеточия)

Ну а потом запаковать с помощью утилиты jar или какого-нибудь winrar

UPD

Читайте также: