Jump to content

[1.16.5] Spawn in custom dimension after creating a new world


PianoManu

Recommended Posts

Hey guys, I made a custom dimension and everything is working completely fine (like world-generation, entering and exiting the dimension via portal block, respawning in the dimension, etc.), so I had the idea that after creating a new world, the player would start directly in my dimension instead of in the overworld. How could I achieve this?

Thanks in advance, and kind regards, Manu :)

 

Edit: if you need my github repository, here it is!

Edited by PianoManu
Link to comment
Share on other sites

Hey, thank you very much for your tip!

Your approach was very veeeeeery helpful. That gave me a good idea and it works now, although I've chosen a slightly different way. This is how I solved the problem: At first I took a look into the PlayerEvent class (which is highly documentated, special thanks to whoever did that - it is unfortunately not very common), so I had the idea to search for some sort of "WorldEvent" class and check, whether it contains some useful events, and tah-dah, it contains a static class "WorldEvent.Load", where I can get an IWorld-instance, that features a player list. (The WorldEvent class is also documented pretty well, thanks again, you've made it easy for me!) I concluded, that I have to listen for both events, since I need the world (with the player list) and the player entity (to check, whether he is already registered in said list. The exact code looks like this:

	@SubscribeEvent
    public void playerLogginIn(final PlayerEvent.PlayerLoggedInEvent event) { //listen for "logging in"-event
        ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
        if (!world.players().contains(player)) { //check whether the player (who is logging in) is already listed in the list of players on this world
            ServerWorld deepDark = player.server.getLevel(DDDMain.DEEP_DARK_DIMENSION); //if it's not the case (i.e. the player is new to this world), we need to teleport the player to this dimension instead
            if (deepDark != null) {
                DDDTeleporter teleporter = new DDDTeleporter(DDDConfig.SPAWN_POS);
                teleporter.setOverworldTeleporterPos(player.blockPosition());
                player.setPos(DDDConfig.SPAWN_POS.getX(), DDDConfig.SPAWN_POS.getY(), DDDConfig.SPAWN_POS.getZ());
                player.changeDimension(deepDark, teleporter);
            }
        }
    }

    @SubscribeEvent
    public void playerLoadsWorld(final WorldEvent.Load event) { //is called before "playerLoggingIn", so we can collect the world the player is joining
        world = event.getWorld(); //world is a private static IWorld-variable
    }

After that, I registered this class to the MinecraftForge.EVENT_BUS in my Main class between "enqueueIMC" and "processIMC". I hope this was correct, I'm not quite sure where to put it, but it's working, so I think it should be okay. (Pls correct me if I'm wrong)

 

Thanks again to you @ChampionAsh5357 for your helpful tip ❤️ 

Kind regards, Manu

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.