User Tools

Site Tools


tutorial:mixin_making_your_first_mixin

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
tutorial:mixin_making_your_first_mixin [2025/09/27 06:04] – [Extending the target class's parents] reworded duck interfacing to duck typing gauntreclusetutorial:mixin_making_your_first_mixin [2025/09/27 06:42] (current) – Add horizontal line separations between sections; Amend debug segment to mention MCDev breakpoint support, and warn against using loggers as a primary debug tool. gauntrecluse
Line 40: Line 40:
  
 And that's all there is to actually creating the Mixin Class. It doesn't do anything yet, though. So let's get to that. And that's all there is to actually creating the Mixin Class. It doesn't do anything yet, though. So let's get to that.
 +
 +----
  
 ==== Creating the injector ==== ==== Creating the injector ====
Line 124: Line 126:
 The constructor is irrelevant to actual Mixin work, it's only there for the sake of extension. A perceptive reader might notice that we didn't implement any methods. That is another benefit of making our class abstract. Abstract classes, because they are never instantiated, do not need to implement all methods from their parents. Do note if you implement an interface not implemented by the target class, that will be merged into the target class at runtime aswell. This has some utility for duck typing, also known as using a "duck interface"((An approach that allows to give access to fields added to a target class via Mixin. Use bot message ''!!duck'' on the Fabric Discord for a direct example. See also [[https://github.com/SpongePowered/Mixin/wiki/Introduction-to-Mixins---Understanding-Mixin-Architecture#3-quack-quack|the Mixin Wiki segment on it]])) The constructor is irrelevant to actual Mixin work, it's only there for the sake of extension. A perceptive reader might notice that we didn't implement any methods. That is another benefit of making our class abstract. Abstract classes, because they are never instantiated, do not need to implement all methods from their parents. Do note if you implement an interface not implemented by the target class, that will be merged into the target class at runtime aswell. This has some utility for duck typing, also known as using a "duck interface"((An approach that allows to give access to fields added to a target class via Mixin. Use bot message ''!!duck'' on the Fabric Discord for a direct example. See also [[https://github.com/SpongePowered/Mixin/wiki/Introduction-to-Mixins---Understanding-Mixin-Architecture#3-quack-quack|the Mixin Wiki segment on it]]))
  
-==== Debugging with Mixins ====+----
  
-There are many ways to debug mod code in general, and most apply to code you mixed into aswell, but Mixin also provides a very useful utility for debugging; namely, the ''@Debug'' annotation, with the ''export = true'' parameter.+==== Debugging Mixins ==== 
 + 
 +=== The @Debug export feature === 
 +Mixin provides a very useful utility for debugging; namely, the ''@Debug'' annotation, with the ''export = true'' parameter.
  
 Adding it to our tutorial class it should look like: Adding it to our tutorial class it should look like:
Line 147: Line 152:
 :!: //The ''@Debug'' settings stay as they are in dev when the mod is built into a ''jar'', make sure to not accidentally export Mixin classes in the ''jar'' you publish!// :!: //The ''@Debug'' settings stay as they are in dev when the mod is built into a ''jar'', make sure to not accidentally export Mixin classes in the ''jar'' you publish!//
  
 +=== Breakpoints and MCDev ===
 +
 +Breakpoints don't natively work with Mixin classes as they get merged at runtime. However, MCDev adds breakpoint support in Mixin Classes directly, allowing you to debug with them by directly putting them in your Mixins rather than having to try and anticipate your injector.
 +
 +=== Loggers ===
 +
 +Logger calls can be very handy when trying to debug complex logical flows or just for general warning and error notifications. And whilst that may be useful for debugging, one should be particularly careful when using them anywhere that'll be called a **lot**, for performance reasons. This applies just the same with Mixins, and one should in general not use loggers as their primary form of debugging.
 +
 +
 +----
  
 ==== Closing Thoughts and where to go next ==== ==== Closing Thoughts and where to go next ====
tutorial/mixin_making_your_first_mixin.txt · Last modified: 2025/09/27 06:42 by gauntrecluse