User Tools

Site Tools


tutorial:mixin_redirectors_methods

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:mixin_redirectors_methods [2020/08/17 01:08] – case user11681tutorial:mixin_redirectors_methods [2021/01/15 04:20] (current) – Fix instance method example - removed "static" modifier & rename class obw
Line 10: Line 10:
 The ''INVOKE'' injection point reference is used for invocations of ''target'' in ''method'', which means that it can be used in order to redirect a method immediately before it is called. The ''INVOKE'' injection point reference is used for invocations of ''target'' in ''method'', which means that it can be used in order to redirect a method immediately before it is called.
  
-==== redirecting a static method ====+==== Redirecting a static method ====
  
 Static method redirectors should have the same parameters as the ''target''. Static method redirectors should have the same parameters as the ''target''.
Line 17: Line 17:
  
 <code java [enable_line_numbers=true]> <code java [enable_line_numbers=true]>
-@Mixin(ItemStack.class) +@Mixin(SimpleInventory.class) 
-class ItemStackMixin {+abstract class SimpleInventoryMixin {
     @Redirect(method = "readTags",     @Redirect(method = "readTags",
               at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/item/ItemStack;fromTag(Lnet/minecraft/nbt/ListTag;)Lnet/minecraft/item/ItemStack;"))               at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/item/ItemStack;fromTag(Lnet/minecraft/nbt/ListTag;)Lnet/minecraft/item/ItemStack;"))
Line 27: Line 27:
 </code> </code>
  
-==== redirecting an instance method ====+==== Redirecting an instance method ====
  
 Instance method redirectors are similar to static methood redirectors, but they should have an additional parameter at the start of their parameter lists for the objects on which their ''target''s are invoked. Instance method redirectors are similar to static methood redirectors, but they should have an additional parameter at the start of their parameter lists for the objects on which their ''target''s are invoked.
Line 35: Line 35:
 <code java [enable_line_numbers=true]> <code java [enable_line_numbers=true]>
 @Mixin(Entity.class) @Mixin(Entity.class)
-class ItemStackMixin {+abstract class EntityMixin {
     @Redirect(method = "dropItem",     @Redirect(method = "dropItem",
               at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;dropItem(Lnet/minecraft/item/ItemConvertible;I)Lnet/minecraft/entity/ItemEntity;"))               at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;dropItem(Lnet/minecraft/item/ItemConvertible;I)Lnet/minecraft/entity/ItemEntity;"))
-    private static ItemEntity replaceDroppedItem(Entity droppingEntity, ItemConvertible item, int yOffset) {+    private ItemEntity replaceDroppedItem(Entity droppingEntity, ItemConvertible item, int yOffset) {
         return droppingEntity.dropItem(item == Items.DIAMOND ? Items.AIR : item, yOffset);         return droppingEntity.dropItem(item == Items.DIAMOND ? Items.AIR : item, yOffset);
     }     }
Line 52: Line 52:
 <code java [enable_line_numbers=true]> <code java [enable_line_numbers=true]>
 @Mixin(MinecraftClient.class) @Mixin(MinecraftClient.class)
-class MinecraftClientMixin {+abstract class MinecraftClientMixin {
     @Redirect(method = "render",     @Redirect(method = "render",
               at = @At(value = "INVOKE_STRING",               at = @At(value = "INVOKE_STRING",
tutorial/mixin_redirectors_methods.1597626534.txt.gz · Last modified: 2020/08/17 01:08 by user11681