Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

err... ๐Ÿ™‚

ServerPlayer.getRespawnPosition() but you will also need ServerPlayer.getRespawnDimension()

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.comย  You should also read the support forum sticky post.

  • Author

with the output of the getRespawnPositionย 

public Optional<Vec3> getRespawnPosition(BlockState state, EntityType<?> type, LevelReader levelReader, BlockPos pos, float orientation, @Nullable LivingEntity entity) {
        return super.getRespawnPosition(state, type, levelReader, pos, orientation, entity);
    }

I want to teleport the player to that location

ย 

Edited by CrativeMan

ย What is the code you are showing?

The ServerPlayer.getRespawnPosition() method looks like this

 public BlockPos getRespawnPosition() {

Note: the result maybe null if the player hasn't set their spawn.

ย 

ย 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.comย  You should also read the support forum sticky post.

  • Author
package de.sebastian.tutorial.block.custom;

import com.mojang.realmsclient.util.WorldGenerationInfo;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class TeleporterBlock extends Block {

    public long requiredXl;
    public long requiredYl;
    public long requiredZl;

    public double requiredXd;
    public double requiredYd;
    public double requiredZd;

    @Override
    public Optional<Vec3> getRespawnPosition(BlockState state, EntityType<?> type, LevelReader levelReader, BlockPos pos, float orientation, @Nullable LivingEntity entity) {
        return super.getRespawnPosition(state, type, levelReader, pos, orientation, entity);
    }
    String failed = "To low on levels";

    @Override
    public InteractionResult use(BlockState state, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {

        if(!level.isClientSide && interactionHand == InteractionHand.MAIN_HAND){
            if(player.experienceLevel > 1){
            player.giveExperienceLevels(-1);
//            player.teleportTo();
            } else {
                player.sendSystemMessage(Component.nullToEmpty(failed));
            }

        }

        return super.use(state, level, blockPos, player, interactionHand, blockHitResult);
    }

    public TeleporterBlock(Properties properties) {
        super(properties);
    }
}

This is my code. I am a bit lost on what to do with your response

You can't just teleport somebody to their spawn. The location might be in a different dimension. Which needs special handling.

In the vanilla code, this is only done when the player dies which effectively creates a new player as they respawn.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.comย  You should also read the support forum sticky post.

Ok, that respawnPosition is not what you think it is. It is

Quote

ย  ย  /**
ย  ย  ย * Returns the position that the entity is moved to upon
ย  ย  ย * respawning at this block.
ย  ย  ย *
ย  ย  ย * @param state The current state
ย  ย  ย * @param type The entity type used when checking if a dismount blockstate is dangerous. Currently always PLAYER.
ย  ย  ย * @param levelReader The current level
ย  ย  ย * @param pos Block position in level
ย  ย  ย * @param orientation The angle the entity had when setting the respawn point
ย  ย  ย * @param entity The entity respawning, often null
ย  ย  ย * @return The spawn position or the empty optional if respawning here is not possible
ย  ย  ย */
ย  ย  default Optional<Vec3> getRespawnPosition(BlockState state, EntityType<?> type, LevelReader levelReader, BlockPos pos, float orientation, @Nullable LivingEntity entity

It lets a block decide where to place the player if they happen to respawn at that block.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.comย  You should also read the support forum sticky post.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.