Skip to content

Commit

Permalink
add left click push && right click pull
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorax5 committed Aug 30, 2024
1 parent cf67eed commit 0414333
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import fr.phylisiumstudio.soraxPhysic.PhysicsManager;
import fr.phylisiumstudio.soraxPhysic.consumers.ToolHeld;
import fr.phylisiumstudio.soraxPhysic.consumers.ToolUnheld;
import fr.phylisiumstudio.soraxPhysic.event.LeftClickRigidblockEvent;
import fr.phylisiumstudio.soraxPhysic.event.RightClickRigidblockEvent;
import fr.phylisiumstudio.soraxPhysic.models.RigidBlock;
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
Expand Down Expand Up @@ -63,6 +64,27 @@ public void onRightClickRigidbody(RightClickRigidblockEvent event){

player.spawnParticle(Particle.CRIT, clickedPosition.getX(), clickedPosition.getY(), clickedPosition.getZ(), 100);

Location playerLocation = event.getPlayer().getEyeLocation();
Vector playerDirection = playerLocation.getDirection();
playerDirection.normalize();
Vector direction = clickedPosition.subtract(playerLocation.toVector());
Vector3f impulse = new Vector3f((float) direction.getX(), (float) direction.getY(), (float) direction.getZ());

impulse.scale(5);

org.joml.Vector3f impulseJoml = new org.joml.Vector3f(impulse.x, impulse.y, impulse.z);
org.joml.Vector3f clickedPositionJoml = new org.joml.Vector3f((float) clickedPosition.getX(), (float) clickedPosition.getY(), (float) clickedPosition.getZ());
rigidBlock.applyImpulse(clickedPositionJoml, impulseJoml);
}

@EventHandler
public void onLeftClickRigidbody(LeftClickRigidblockEvent event){
Vector clickedPosition = event.getClickLocation().toVector();
RigidBlock rigidBlock = event.getRigidBlock();
Player player = event.getPlayer();

player.spawnParticle(Particle.CRIT, clickedPosition.getX(), clickedPosition.getY(), clickedPosition.getZ(), 100);

Location playerLocation = event.getPlayer().getEyeLocation();
Vector playerDirection = playerLocation.getDirection();
playerDirection.normalize();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
right-click-pull: true
left-click-push: true

0 comments on commit 0414333

Please sign in to comment.