Jump to content

[SOLVED] [1.15.2] Get the players spawnpoint


Slastic

Recommended Posts

		BlockPos spawn = worldIn.getSpawnPoint();
            @Nullable
            BlockPos bed = playerIn.getBedLocation(DimensionType.OVERWORLD);

            if(bed != null && worldIn.getBlockState(bed).getBlock().toString().contains("bed")) {
                playerIn.setPositionAndUpdate(bed.getX(), bed.getY(), bed.getZ());
            } else {
                playerIn.setPositionAndUpdate(spawn.getX(), spawn.getY(), spawn.getZ());
            }

 

Make sure when getting your bed it's nullable or you can get an error

This may not be the best solution but it works

 

Edited by Slastic
Link to comment
Share on other sites

32 minutes ago, Slastic said:

I was trying to figure out how to ensure the bed exists since it still teleported you there, even if there was no bed.

Always lead with what you are actually trying to accomplish, from a gameplay standpoint. :) makes the path to the answer considerably shorter in most cases!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.