java.lang.Object
net.timtaran.interactivemc.body.player.interaction.GrabInteraction

public class GrabInteraction extends Object
Handles the logic for physical interactions between a player and objects in the world.

This class manages the detection of grabbable objects using sphere-casting, the creation of physical constraints (joints) to "attach" objects to the player's hands, and the subsequent release of those objects.

This class is only intended for use by PlayerBodyManager.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Result of a grab attempt.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GrabInteraction(net.xmx.velthoric.core.physics.world.VxPhysicsWorld world, PlayerBodyManager playerBodyManager)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyPullForce(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, PlayerBodyPart playerBodyPart)
     
    @Nullable net.xmx.velthoric.core.constraint.VxConstraint
    attach(net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, com.github.stephengold.joltjni.readonly.RVec3Arg worldGrabPoint, net.minecraft.world.entity.player.Player player, PlayerBodyPart playerBodyPart)
     
    attachIfWithinReach(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, PlayerBodyPart playerBodyPart)
     
    static boolean
    canGrabClient(PlayerBodyPart playerBodyPart)
    Checks is any body around player can be grabbed.
    grab(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, PlayerBodyPart playerBodyPart, boolean isRemoteAllowed)
    Attempts to grab an object using the specified player's body part.
    boolean
    release(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, PlayerBodyPart playerBodyPart, PlayerBodyPartData playerBodyPartData)
    Releases any object being grabbed by the specified player's hand.
    boolean
    updatePullState(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, PlayerBodyPart playerBodyPart)
     

    Methods inherited from class java.lang.Object

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

    • GrabInteraction

      public GrabInteraction(net.xmx.velthoric.core.physics.world.VxPhysicsWorld world, PlayerBodyManager playerBodyManager)
  • Method Details

    • grab

      @Nullable public @Nullable GrabInteraction.GrabResult grab(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, PlayerBodyPart playerBodyPart, boolean isRemoteAllowed)
      Attempts to grab an object using the specified player's body part.
      Parameters:
      player - the player attempting to grab
      grabberBody - the body that is grabbing
      playerBodyPart - the player's body part
      isRemoteAllowed - whether remote grabbing (raycast-based) is allowed if no bodies are within grab radius
      Returns:
      the body that was grabbed, or null if no body was grabbed
    • attach

      @Nullable public @Nullable net.xmx.velthoric.core.constraint.VxConstraint attach(net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, com.github.stephengold.joltjni.readonly.RVec3Arg worldGrabPoint, net.minecraft.world.entity.player.Player player, PlayerBodyPart playerBodyPart)
    • attachIfWithinReach

      public GrabInteraction.GrabResult attachIfWithinReach(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, PlayerBodyPart playerBodyPart)
    • applyPullForce

      public void applyPullForce(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, PlayerBodyPart playerBodyPart)
    • updatePullState

      public boolean updatePullState(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, PlayerBodyPart playerBodyPart)
    • release

      public boolean release(net.minecraft.world.entity.player.Player player, net.xmx.velthoric.core.body.VxBody grabberBody, net.xmx.velthoric.core.body.VxBody grabbedBody, PlayerBodyPart playerBodyPart, PlayerBodyPartData playerBodyPartData)
      Releases any object being grabbed by the specified player's hand.

      This removes the grab constraint, allowing the grabbed body to move freely again.

      Parameters:
      playerBodyPartData - the player's body part data
      Returns:
      true if the body was successfully released, false otherwise
    • canGrabClient

      @Environment(CLIENT) public static boolean canGrabClient(PlayerBodyPart playerBodyPart)
      Checks is any body around player can be grabbed. Used to predict if player can grab body in KeyMappingHandlingMixin to prevent other grip binds to be called.
      Returns:
      is any body around player can be grabbed.