Class InteractionManager

java.lang.Object
me.hackware.api.InteractionManager

public final class InteractionManager extends Object
Centralized interaction manager — item use, entity attacks, use-action lifecycle.

Block placement and block interaction are handled by BlockPlacementManager. This manager covers:

  • Item use (pearls, potions, food, fireworks, XP bottles, etc.)
  • Entity attacks (crystals, players, mobs)
  • Use-action control (stop/release using item)
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    attack(String caller, net.minecraft.world.entity.Entity target)
    Attacks an entity via gameMode.attack.
    get()
     
    void
    Register event handlers.
    void
    Releases the item being used (e.g.
    void
    sendAttackPacket(String caller, net.minecraft.world.entity.Entity target)
    Sends a raw attack packet without going through gameMode.attack.
    void
    sendUseItemPacket(String caller, net.minecraft.world.InteractionHand hand, float yaw, float pitch)
    Sends a raw ServerboundUseItemPacket via startPrediction.
    void
    Stops the player's current item use action (e.g.
    net.minecraft.world.InteractionResult
    useItem(String caller, net.minecraft.world.InteractionHand hand)
    Uses the item currently in the given hand via gameMode.useItem.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • get

      public static InteractionManager get()
    • init

      public void init()
      Register event handlers. Call once during mod init.
    • useItem

      public net.minecraft.world.InteractionResult useItem(String caller, net.minecraft.world.InteractionHand hand)
      Uses the item currently in the given hand via gameMode.useItem. Handles prediction internally.
      Parameters:
      caller - descriptive source (module name)
      hand - which hand to use
      Returns:
      the interaction result
    • sendUseItemPacket

      public void sendUseItemPacket(String caller, net.minecraft.world.InteractionHand hand, float yaw, float pitch)
      Sends a raw ServerboundUseItemPacket via startPrediction. Use this when you need packet-level control (e.g. pearl throws with custom rotation).
      Parameters:
      caller - descriptive source
      hand - which hand
      yaw - look yaw for the packet
      pitch - look pitch for the packet
    • attack

      public void attack(String caller, net.minecraft.world.entity.Entity target)
      Attacks an entity via gameMode.attack. This is the standard vanilla attack path (includes swing, sounds, knockback).
      Parameters:
      caller - descriptive source
      target - the entity to attack
    • sendAttackPacket

      public void sendAttackPacket(String caller, net.minecraft.world.entity.Entity target)
      Sends a raw attack packet without going through gameMode.attack. Useful for silent attacks that bypass vanilla's attack cooldown/swing.
      Parameters:
      caller - descriptive source
      target - the entity to attack
    • stopUsingItem

      public void stopUsingItem(String caller)
      Stops the player's current item use action (e.g. interrupts eating, bow draw).
    • releaseUsingItem

      public void releaseUsingItem(String caller)
      Releases the item being used (e.g. fires bow, throws trident). Different from stopUsingItem(java.lang.String) — this triggers the release action.