88import meteordevelopment .meteorclient .commands .Command ;
99import meteordevelopment .meteorclient .events .entity .player .PlayerMoveEvent ;
1010import meteordevelopment .meteorclient .events .packets .PacketEvent ;
11+ import meteordevelopment .meteorclient .events .render .Render2DEvent ;
1112import meteordevelopment .meteorclient .events .world .BlockUpdateEvent ;
13+ import meteordevelopment .meteorclient .renderer .text .TextRenderer ;
14+ import meteordevelopment .meteorclient .utils .render .NametagUtils ;
1215import meteordevelopment .orbit .EventHandler ;
1316import nekiplay .Main ;
1417import nekiplay .protrainer .ProTrainerAddon ;
2629import net .minecraft .util .math .Vec3d ;
2730import net .minecraft .util .math .Vec3i ;
2831import net .minecraft .world .World ;
32+ import org .joml .Vector3d ;
2933
3034import java .io .*;
3135import java .nio .charset .StandardCharsets ;
@@ -47,6 +51,8 @@ public TrainerCommand() {
4751 public Gson gson = new Gson ();
4852 public boolean started = false ;
4953 public Vec3d start_position = new Vec3d (Double .NEGATIVE_INFINITY , Double .NEGATIVE_INFINITY , Double .NEGATIVE_INFINITY );
54+ public Vec3d spawnpoint_position = new Vec3d (Double .NEGATIVE_INFINITY , Double .NEGATIVE_INFINITY , Double .NEGATIVE_INFINITY );
55+
5056
5157 public List <BlockDataAndPosition > replaced = new ArrayList <>();
5258 public HashMap <BlockPosition , BlockData > map_blocks = new HashMap <>();
@@ -71,6 +77,15 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
7177 }
7278 return SINGLE_SUCCESS ;
7379 }));
80+ builder .then (literal ("spawnpoint" ).executes (context -> {
81+ if (started ) {
82+ mc .player .setPos (spawnpoint_position .x , spawnpoint_position .y , spawnpoint_position .z );
83+ }
84+ else {
85+ warning ("Parkour hasn't started" );
86+ }
87+ return SINGLE_SUCCESS ;
88+ }));
7489 builder .then (literal ("start" ).then (argument ("map" , StringArgumentType .string ()).executes (context -> {
7590 if (started ) {
7691 error ("Parkour has already begun" );
@@ -86,6 +101,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
86101 File dir2 = new File (dir , map + ".json" );
87102
88103 start_position = mc .player .getPos ();
104+ spawnpoint_position = mc .player .getPos ().add (0 , 1 , 0 );
89105
90106 new Thread (() -> {
91107 try {
@@ -248,27 +264,25 @@ public List<BlockPos> collectBlocksBetween(World world, BlockPos start, BlockPos
248264 @ EventHandler
249265 private void onPlayerMove (PlayerMoveEvent event ) {
250266 BlockPos pos = mc .player .getBlockPos ();
251- BlockPos pos_down = pos .down ();
252267
253268 BlockState state = mc .world .getBlockState (pos );
254- BlockState state_down = mc .world .getBlockState (pos_down );
255269
256270 if (started ) {
257271 var module = ProTrainerAddon .getInstance ().module ;
258272
259273 if (module .respawnBlocks .get ().contains (state .getBlock ())) {
260- mc .player .setPos (start_position .x , start_position .y , start_position .z );
274+ mc .player .setPos (spawnpoint_position .x , spawnpoint_position .y , spawnpoint_position .z );
261275 }
262- if (module .respawnBlocks .get ().contains (state_down .getBlock ())) {
263- mc . player . setPos ( start_position . x , start_position . y , start_position . z );
276+ if (module .checkPointsBlocks .get ().contains (state .getBlock ())) {
277+ spawnpoint_position = new Vec3d ( pos . getX () + 0.5 , pos . getY () + 1 , pos . getZ () + 0.5 );
264278 }
265279 }
266280 }
267281
268282 @ EventHandler
269283 private void onBlockUpdate (BlockUpdateEvent event ) {
270284 BlockPosition position = new BlockPosition (event .pos );
271- BlockDataAndPosition position2 = new BlockDataAndPosition (Blocks . AIR . getDefaultState () , event .pos );
285+ BlockDataAndPosition position2 = new BlockDataAndPosition (event . oldState , event .pos );
272286 if (map_blocks .containsKey (position ) && started ) {
273287 BlockData data = map_blocks .get (position );
274288 mc .world .setBlockState (event .pos , Block .getStateFromRawId (data .blockId ));
@@ -279,6 +293,36 @@ private void onBlockUpdate(BlockUpdateEvent event) {
279293 }
280294 }
281295
296+ @ EventHandler
297+ private void on2DRender (Render2DEvent event ) {
298+ if (started ) {
299+ Vec3d camera_pos = mc .gameRenderer .getCamera ().getPos ();
300+ Vector3d pos2 = new Vector3d (spawnpoint_position .x , spawnpoint_position .y , spawnpoint_position .z );
301+ if (pos2 .distance (camera_pos .x , camera_pos .y , camera_pos .z ) <= ProTrainerAddon .getInstance ().module .spawnpointTextRenderDistance .get ()) {
302+ if (NametagUtils .to2D (pos2 , 1 , true )) {
303+ TextRenderer text = TextRenderer .get ();
304+ NametagUtils .begin (pos2 );
305+ text .beginBig ();
306+
307+ String hologram_text = "Spawnpoint" ;
308+ double hologramWidth = text .getWidth (hologram_text , true );
309+ double heightDown = text .getHeight (true );
310+
311+ double widthHalf = hologramWidth / 2 ;
312+
313+
314+ double hX = -widthHalf ;
315+ double hY = -heightDown ;
316+
317+ text .render (hologram_text , hX , hY , ProTrainerAddon .getInstance ().module .spawnpointTextColor .get (), true );
318+
319+ text .end ();
320+ NametagUtils .end ();
321+ }
322+ }
323+ }
324+ }
325+
282326 @ EventHandler
283327 private void onSendPacket (PacketEvent .Send event ) {
284328 if (event .packet instanceof PlayerMoveC2SPacket playerMoveC2SPacket ) {
0 commit comments