User Tools

Site Tools


drafts:mixin_override

Differences

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

Link to this comparison view

Next revision
Previous revision
drafts:mixin_override [2025/11/02 15:42] – created gauntreclusedrafts:mixin_override [2025/11/03 14:52] (current) gauntrecluse
Line 1: Line 1:
 :!: //This is a draft! Feedback is appreciated, but keep in mind this is currently not intended to be read by Wiki users, it is not guaranteed that this page is fully accurate.// :!: //This is a draft! Feedback is appreciated, but keep in mind this is currently not intended to be read by Wiki users, it is not guaranteed that this page is fully accurate.//
 +
 +//TODO List: Example of how a direct injection attempt would fail; Note about how submixin patterns cannot contain interfaces//
  
 ====== Creating an Override in a target class (DRAFT) ====== ====== Creating an Override in a target class (DRAFT) ======
Line 31: Line 33:
  
  
-===== Compatible Solutions to the Problem =====+===== The Solutions =====
 ==== Injecting an instanceof check in the super ==== ==== Injecting an instanceof check in the super ====
 We can inject a check within the method we wish to functionally override, which will execute our custom operations if the ''this'' instance is of the intended subclass. In our case, we could create a Mixin like the following: We can inject a check within the method we wish to functionally override, which will execute our custom operations if the ''this'' instance is of the intended subclass. In our case, we could create a Mixin like the following:
Line 39: Line 41:
     @WrapMethod(method = "damage")     @WrapMethod(method = "damage")
     private boolean doSomethingForCopperGolem(ServerWorld world, DamageSource source, float amount, Operation<Boolean> original) {     private boolean doSomethingForCopperGolem(ServerWorld world, DamageSource source, float amount, Operation<Boolean> original) {
-        if ((Object) this instanceof CopperGolemEntity) {+        if ((Object) this instanceof CopperGolemEntity) { // We have to cast to Object first to satisfy the compiler
             ExampleMod.doSomething();             ExampleMod.doSomething();
         }         }
drafts/mixin_override.1762098123.txt.gz · Last modified: 2025/11/02 15:42 by gauntrecluse