Jump to content

Tp player to custom dimension


Lxs_

Recommended Posts

how could i tp the player to an unloaded dimension right after the clearInventory

@Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
        player.playSound(Sounds.CORRUPT_CRYSTAL_USE.get(), 1f, 1f);
        player.getCooldowns().addCooldown(this, 100);
        player.addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 150, 355));
        player.getInventory().clearContent();
        return super.use(level, player, usedHand);
    }

 

Link to comment
Share on other sites

You need to create a class implementing the ITeleporter Interface, and override its placeEntity() method in which you'll have the logic to safely place the teleported entity in the inbound dimension.

Whenever you need to use said class just create a new instance of it and call the changeDimension method of the entity you want to teleport with the ServerLevel instance of the target dimension and the teleporter class:

MinecraftServer mcServer = level.getServer();
ServerLevel targetDimension = mcServer.getLevel(TARGETDIMENSIONLEVELKEY);

if (targetDimension != null) {
	CustomITeleporter teleporter = new CustomITeleporter(. . .);
	entity.changeDimension(targetDimension, teleporter);
}

EDIT: As far as i can tell this works on 1.19+. You didn't specify your version so I defaulted to the most recent one(s)

Edited by chxr
Clarification
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.



×
×
  • Create New...

Important Information

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