Posted May 16, 20214 yr 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 May 16, 20214 yr by PianoManu
May 16, 20214 yr Probably through the use of PlayerEvent$PlayerLoggedInEvent and checking some boolean you added to the player via capability or stored as a WSD to check if the user has joined the world previously.
May 17, 20214 yr Author 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
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.