User Tools

Site Tools


tutorial:interface_injection

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:interface_injection [2022/03/08 21:12] – use automatic intermediary -> yarn mappings juuztutorial:interface_injection [2025/02/12 18:42] (current) – Add node on unicode escape for $ earthcomputer
Line 11: Line 11:
  
 The scope of this example is to add the following method into ''<yarn net.minecraft.class_3609>'' to get the sound of the bucket when emptied. The scope of this example is to add the following method into ''<yarn net.minecraft.class_3609>'' to get the sound of the bucket when emptied.
-This, normally, is not possible because ''<yarn net.minecraft.class_3609>'' does not has a similar method.+This, normally, is not possible because ''<yarn net.minecraft.class_3609>'' does not have a similar method.
  
 <yarncode java [enable_line_numbers="false"]> <yarncode java [enable_line_numbers="false"]>
Line 38: Line 38:
  @Override  @Override
  public Optional<class_3414> getBucketEmptySound() {  public Optional<class_3414> getBucketEmptySound() {
- //This is how to get the default sound, copied from BucketItem class. +     //This is how to get the default sound, copied from BucketItem class. 
- return Optional.of(((FlowableFluid) (Object) this).isIn(FluidTags.LAVA) ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA SoundEvents.ITEM_BUCKET_EMPTY);+     return Optional.of(((class_3609) (Object) this).method_15791(class_3486.field_15518) ? class_3417.field_15010 class_3417.field_14834);
  }  }
 } }
Line 64: Line 64:
 </yarncode> </yarncode>
  
-You could also override this method in classes extending FlowableFluid to implement custom behaviours.+You could also override this method in classes extending <yarn class_3609> to implement custom behaviours
 + 
 +Sometimes, your interface injections may need to include the ''$'' symbol, but the Groovy template processor may interpret this as a template variable if you are replacing variables (such as ''${version}'') in your ''fabric.mod.json''. A workaround for this is to use the Unicode escape for ''$'', which is ''\u0024''.
tutorial/interface_injection.1646773957.txt.gz · Last modified: 2022/03/08 21:12 by juuz