Skip to content
Advertisement

Forge 1.12.2 Coremodding: java.lang.ClassCircularityError

I try to make a coremod on 1.12.2 Forge in order to patch some missing stuff in the Lost Cities mod. (Source: https://github.com/McJtyMods/LostCities/blob/1.12/src/main/java/mcjty/lostcities/dimensions/world/lost/BuildingInfo.java)

A friend and I have written this LostCitiesClassTransformer.java:

JavaScript

The original code we want to patch (Bytecode Outline):

JavaScript

The Bytecode Outline containing our fix:

JavaScript

The Stacktrace we get:

JavaScript

What we tried: We tried to get the building using different ways, e.g. using GETFIELD. Error remain the same.

Any help would be appreciated. If you need to know more details, feel free to ask. Thanks in advance.

Edit: After hardcoding the String, I got another Stacktrace. Is this still related to me doing something wrong with ASM?

JavaScript

Advertisement

Answer

The problem is that you do Type.getInternalName(BuildingInfo.class). That’s the very class you’re trying to transform as it’s being loaded, so you created a circular reference by using it in a way that would need it to be loaded. You’ll need to hardcode the string "mcjty/lostcities/dimensions/world/lost/BuildingInfo" there instead.

Also, in "()Lmcjty/lostcities/api/ILostCityBuilding", that’s supposed to have a semicolon at the end, so change it to "()Lmcjty/lostcities/api/ILostCityBuilding;".

Finally, you need to change false to true in new MethodInsnNode(INVOKEINTERFACE, Type.getInternalName(ILostCityBuilding.class), "getMinCellars", "()I", false));, since it is in fact an interface method.

Advertisement