DimensionalDevelopment / Rift

A lightweight mod loader and API for Minecraft 1.13
MIT License
122 stars 52 forks source link

[Question] How to rewrite Forge event handler hook ? #42

Closed Sejoslaw closed 6 years ago

Sejoslaw commented 6 years ago

Hi,

First of all let me say that I really like the way Rift is made and it made me curious... How can I rewrite my mod, which was Forge-based, and in which I used event handler hooks ?

The problem is simple: I have a class which contains a method and this method takes, as an argument, Forge event (e.g. RightClickBlock) and also is decorated with annotation "SubscribeEvent". How can I rewrite that piece of code to work with Rift ?

My point is that I would like to hook, e.g. to the "block-mining" point of Minecraft code, and add some additional functionality there. Should I use the Mixin to find that part in Minecraft code and create my own hook or will Rift support more events ?

Best regards Sejoslaw

vladyslav-vasiliev commented 6 years ago

Yes, you should use mixins

Runemoro commented 6 years ago

e.g. RightClickBlock

Yes, you should use @Inject from Mixin to add a hook only to the block(s) you want to affect. Rift won't be adding "right-click" events because they're too general and therefore less efficient (they get called for all blocks when the modder usually wants to affect just a few blocks) and often lead to modders using hacks to get around their limitations when a @Redirect or @Inject in a different place would be a cleaner solution.

Sejoslaw commented 6 years ago

Ok, thank you :)