Kotlin Mixin Remapping issue
FairyTail2000 opened this issue ยท 4 comments
I'm having issues with the final jar using injections to randomTick in CactusBlock, the method doesn't get remapped to the obfuscated target name, the same thing in java works perfectly fine, the only difference is the randomTick* and in the working java code the fully qualified name. This is just because I tried many variatians of the kotlin code, I also tried the same as in the java code
@Suppress("CAST_NEVER_SUCCEEDS") @Mixin(CactusBlock::class) class CactusBlockMixin { @Inject(method = ["randomTick*"], at = [At(value = "HEAD")], cancellable = true) fun randomTickProxy(state: BlockState, world: ServerWorld, pos: BlockPos, random: Random, info: CallbackInfo) { val blockPos = pos.up() if (world.isAir(blockPos)) { val j = state.get(CactusBlock.AGE) as Int if (j == 15) { world.setBlockState(blockPos, (this as CactusBlock).defaultState) val blockState = state.with(CactusBlock.AGE, 0) as BlockState world.setBlockState(pos, blockState, 4) blockState.neighborUpdate(world, blockPos, this, pos, false) } else { world.setBlockState(pos, state.with(CactusBlock.AGE, j + 1), 4) } } return } }
The java code:
@Mixin(CactusBlock.class) public class CactusBlockMixin { @Inject(method = "randomTick(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Ljava/util/Random;)V", at = @At(value = "HEAD"), cancellable = true) public void randomTickProxy(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo info) { var blockPos = pos.up(); if (world.isAir(blockPos)) { var j = state.get(CactusBlock.AGE); if (j == 15) { world.setBlockState(blockPos, ((CactusBlock) (Object)this).getDefaultState()); BlockState blockState = state.with(CactusBlock.AGE, 0); world.setBlockState(pos, blockState, 4); blockState.neighborUpdate(world, blockPos, ((CactusBlock) (Object)this), pos, false); } else { world.setBlockState(pos, state.with(CactusBlock.AGE, j + 1), 4); } } return; } }
Here is the crashlog
Kotlin mixins are unsupported, write your mixins in Java and call into you koltin code.
See SpongePowered/Mixin#245 for more info.
Is there documentation on this https://fabricmc.net/wiki/tutorial:mixin_introduction page? Did I just overlooked it? If not it would be cool if someone (or me) adds a notice to prevent further creating of issues with this topic
Is there documentation on this https://fabricmc.net/wiki/tutorial:mixin_introduction page? Did I just overlooked it? If not it would be cool if someone (or me) adds a notice to prevent further creating of issues with this topic
Just added it.
Technically, Mixin can be written with Kotlin. However, you should handle where to use @JvmName, @JvmField and other annotations.
However, doing this is not so smart as wrapping Kotlin extensions with Java Mixin.