Skip to content

Add Mixin guides#133

Draft
ArkoSammy12 wants to merge 8 commits intoFabricMC:mainfrom
ArkoSammy12:mixin_guides
Draft

Add Mixin guides#133
ArkoSammy12 wants to merge 8 commits intoFabricMC:mainfrom
ArkoSammy12:mixin_guides

Conversation

@ArkoSammy12
Copy link
Copy Markdown

This Mixin will create an emphasis on building an intuitive understanding of mixins, as well as how to properly write them using modern mixin features, as well as teaching the proper foundations so that one can learn the decision making involved when choosing the type of mixin to use.

This is still a work in progress.

@ArkoSammy12 ArkoSammy12 added the new-content A new page or set of pages label Jul 9, 2024
@ArkoSammy12 ArkoSammy12 self-assigned this Jul 9, 2024
@netlify
Copy link
Copy Markdown

netlify bot commented Jul 9, 2024

Deploy Preview for nimble-elf-d9d491 ready!

Name Link
🔨 Latest commit f39d749
🔍 Latest deploy log https://app.netlify.com/projects/nimble-elf-d9d491/deploys/69543535aa789300075509bd
😎 Deploy Preview https://deploy-preview-133--nimble-elf-d9d491.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@IMB11 IMB11 added the help-wanted Anyone is welcome to work on this label Aug 6, 2024
@its-miroma its-miroma linked an issue Oct 17, 2024 that may be closed by this pull request
@IMB11 IMB11 mentioned this pull request Dec 30, 2024
4 tasks
@its-miroma its-miroma removed the help-wanted Anyone is welcome to work on this label Dec 30, 2024
@its-miroma its-miroma added the priority:low This is nice to have, but it can wait a little label Oct 13, 2025
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 24, 2026

Deploy Preview for nimble-elf-d9d491 ready!

Name Link
🔨 Latest commit 49bf0b6
🔍 Latest deploy log https://app.netlify.com/projects/nimble-elf-d9d491/deploys/69c2cc316480eb00082877fc
😎 Deploy Preview https://deploy-preview-133--nimble-elf-d9d491.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Member

@its-miroma its-miroma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we get the Person and PersonMixin classes in reference, even though they wouldn't be used at all?

}

public int getAge() {
mixinMerged_logAgeAccess(); // <- Injected call to mixinMerged_logAccess
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mixinMerged_logAgeAccess(); // <- Injected call to mixinMerged_logAccess
mixinMerged_logAgeAccess(); // ![code highlight]


There are many different types of annotations, many of them can do more than inject simple calls to method, and they each have their purpose and use cases. Later we will learn how to choose the right one for the goal and how to use them appropriately.

## Wait, What Do You Mean By "At Runtime"? {#wait-what-do-you-mean-by-at-runtime}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Wait, What Do You Mean By "At Runtime"? {#wait-what-do-you-mean-by-at-runtime}
## Wait, What Do You Mean by "At Runtime"? {#wait-what-do-you-mean-by-at-runtime}


But here's the thing, we _know_ that the `age` field will be available to the injected method when the game runs, as the method will be merged with the `Person` class. If only there was a way to tell the compiler that `age` will exist and to let us access it.

Let's consider an annotation that does that, called `@Shadow`. What we do now is that we add the `age` field to our mixin class like any other regular field, but we annotate it with `@Shadow` to let the compiler know that this field will refer to the `age` field of the mixin's target class.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Let's consider an annotation that does that, called `@Shadow`. What we do now is that we add the `age` field to our mixin class like any other regular field, but we annotate it with `@Shadow` to let the compiler know that this field will refer to the `age` field of the mixin's target class.
There is an annotation that does just that, called `@Shadow`. What we need to do is to add the `age` field to our mixin class, like any other regular field, but we annotate it with `@Shadow` to let the compiler know that this field will refer to the `age` field of the mixin's target class.

Comment on lines +226 to +227
Then, we can modify our mixin like so:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Then, we can modify our mixin like so:

Comment on lines +250 to +251
On the topic of abstract mixin classes, let's finally discuss why mixin classes should be abstract.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
On the topic of abstract mixin classes, let's finally discuss why mixin classes should be abstract.


## Abstract Mixin Classes {#abstract-mixin-classes}

There are a few advantages of making your mixin classes abstract. Apart from making semantic sense (a mixin class should never be instantiated directly), it allows you to access the `this` instance.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
There are a few advantages of making your mixin classes abstract. Apart from making semantic sense (a mixin class should never be instantiated directly), it allows you to access the `this` instance.
Let's finally discuss why mixin classes should be abstract. There are a few advantages of making your mixin classes abstract. Apart from making sense semantically (a mixin class should never be instantiated directly), it allows you to access the `this` instance.

Comment on lines +275 to +276

We are now ready to get started with creating our first mixin in our Fabric mod!
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We are now ready to get started with creating our first mixin in our Fabric mod!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File name should be index.md

items: [
{
text: "develop.mixins.introduction",
link: "/develop/mixins/introduction",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
link: "/develop/mixins/introduction",
link: "/develop/mixins/",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-content A new page or set of pages priority:low This is nice to have, but it can wait a little

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Developer Guides: Mixins

5 participants