drafts:new_mixin_example

Playground

Possible addition to Mixin Examples External Link

Modifying a static block

static {
int i = 4;
}

  1. public class ExampleMod implements ModInitializer {
  2. [...]
  3.  
  4. @Override
  5. public void onInitialize() {
  6. AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) -> {
  7. BlockState state = world.getBlockState(pos);
  8. /* Manual spectator check is necessary because AttackBlockCallbacks
  9.   fire before the spectator check */
  10. if (state.isToolRequired() && !player.isSpectator() &&
  11. player.getMainHandStack().isEmpty()) {
  12. player.damage(player.getDamageSources().generic(), 1.0F);
  13. }
  14. return ActionResult.PASS;
  15. });
  16. }
  17. }

drafts/new_mixin_example.txt · Last modified: 2023/09/13 18:46 by nebelnidas