Skip to content

Commit

Permalink
Merge pull request #56 from Ender-Cube/center-spawning
Browse files Browse the repository at this point in the history
Make players spawn in the center of a block when respawning on parkour checkpoints
  • Loading branch information
zax71 authored Jun 12, 2024
2 parents 9180fcb + 138a357 commit 73310b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.endercube.common.utils;

import net.minestom.server.coordinate.Pos;

public class CoordinateUtils {

/**
* Gets the center of a block from a block position
*
* @param blockPos The {@link Pos} with the integer block position
* @return The {@link Pos} with the .5 position
*/
public static Pos posFromBlockpos(Pos blockPos) {
double x = blockPos.blockX();
double z = blockPos.blockZ();

if (x > 0) {
x = x - 0.5;
} else {
x = x + 0.5;
}

if (z > 0) {
z = z - 0.5;
} else {
z = z + 0.5;
}

return new Pos(x, blockPos.y(), z, blockPos.yaw(), blockPos.pitch());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.nio.file.Paths;
import java.util.ArrayList;

import static net.endercube.common.utils.CoordinateUtils.posFromBlockpos;

/**
* This is the entrypoint for Parkour
*/
Expand Down Expand Up @@ -152,7 +154,7 @@ public static void sendToCheckpoint(EndercubePlayer player) {
player.teleport(currentInstance.getTag(Tag.Transient("spawnPos")));
player.setTag(Tag.Long("parkour_startTime"), System.currentTimeMillis()); // Reset timer
} else {
player.teleport(checkpoints[currentCheckpoint]);
player.teleport(posFromBlockpos(checkpoints[currentCheckpoint]));
}
}

Expand Down

0 comments on commit 73310b1

Please sign in to comment.