Jump to content

How to force load a dimension without teleporting to it


Recommended Posts

Hi. I just created a new dimension and I have custom world generation (with IWorldGenerator) which is working fine for that dimension. As soon as I teleport to that dimension with the following code:


            WorldServer worldServerForDimension = MinecraftServer.getServer().worldServerForDimension(message.dim);
            MinecraftServer.getServer().getConfigurationManager().transferPlayerToDimension((EntityPlayerMP) player, message.dim,
                    new RfToolsTeleporter(worldServerForDimension, message.x, message.y+1, message.z));


The dimension is created and my world gen is called.


However. I want to create the 0,0 chunk in my dimension without having to teleport to it. I tried to do it with this:


            WorldServer worldServerForDimension = MinecraftServer.getServer().worldServerForDimension(me.getKey());
            ChunkProviderServer providerServer = worldServerForDimension.theChunkProviderServer;
            if (!providerServer.chunkExists(0, 0)) {
                providerServer.loadChunk(0, 0);
                worldServerForDimension.getBlock(8, 70, ;
                providerServer.unloadChunksIfNotNearSpawn(0, 0);


but that isn't working. The dimension seems to load (a new dimension folder is generated in my world file). However, my IWorldGenerator implementation is never called. So how can I force my IWorldGenerator implementation to be called for the new dimension?



Link to comment
Share on other sites

Well when my dimension is created I need to configure my teleportation system for it. That means I need to set up a 'matter receiver' there (which is done by worldgen as it is a block) and that has to be registered. In my current code I have a special case for dimensions that I haven't teleported too yet because the matter receiver hasn't been created yet. That causes my code to be more complex and also has the additional problem that without the world being generated I actually don't know the y location of the teleporter yet. So it would be ideal if I could let worldgen do its job for that chunk so that the matter receiver gets registered to the teleportation system as usual. That way I can get rid of all special case code and also make sure that I now where the teleporter is going to be.


I can't image this is not possible given that in Minecraft there must be code that actually fully creates the chunk. I was trying to trace through the code that is done when you do an actual teleportation but that is rather complex and I quickly got lost in it.

Link to comment
Share on other sites

Actually the keepLoaded doesn't help since the spawn chunk isn't guaranteed to be at 0,0. I just tried to set it to true and the chunk at 0,0 (where my teleportation system is setup) is not loaded. Seems spawn point is a bit away from that. So I'm still stuck :-/


Ah. And keepLoaded doesn't even help at all since my IWorldGenerator implementation is *still* not called. Seems that IWorldGenerator is only called as soon as you actually teleport to a dimension? Seems weird...


Aha, found something: WorldServer.populate(). This is the function that calls the IWorldGenerator stuff.


Last edit: this solves my problem. Very nice!

Link to comment
Share on other sites

I'm trying to read between the lines here, but as I understand it: you have a block or structure of blocks that generates in the spawn chunk in your custom dimension. At some point track the placement of this block needs to be tracked as you need to know a coordinate to teleport the player to; and so you need to know the Y-position of your block/structure, which obviously won't exist until after the block has been placed. The solution you're proposing is to load the entire spawn chunk once so you can get the Y coordinate of your block for later use in your teleport system, so you're asking how to force-load a chunk just once. Is that right?


One-time force-loading chunks is a bit unusual. Perhaps there's a better way of accomplishing the functionality you seek, would you mind sharing a bit of context?


Also: have you peeked at how Nether Portals work in the vanilla code? I think that would be a fine case example of generating a structure at a teleport destination; the only difference being the placement of your structure would have different rules (since I think you only want it in the spawn chunk, yes?).

Link to comment
Share on other sites

Well most regular teleporters work by actually teleporting the player to the other dimension at which point everything is properly generated. I can't easily do that since the device in my mod that generates dimensions is separate from the teleportation system. With the teleportation system you can 'dial' matter transmitters to matter receivers that have been placed in the world. For that to work my matter receivers have to be registered to a datastructure that I keep with my game (World storage). This happens as soon as the matter receiver block is placed/generated.


I made an iWorldGenerator implementation that generates this matter receiver and causes the registration of this so that my teleportation system knows about it. If I teleport into my dimension using some other means (I have a creative-only item in my mod that allows teleportation to any dimension) then the world generation will build my matter receiver and the registration will happen. At that point a dialing device can dial a matter transmitter to this new matter receiver.


Previously I had custom code that let the dialing device also dial to dimensions for which no matter receiver was registered yet. But this was clumsy ad-hoc code and also had the problem of not knowing the exact y coordinate of the teleport destination since this wasn't generated yet. It also meant that the dialing device could not easily test if the destination had enough power (the matter receiver is a tile entity that has an RF buffer (prefilled at creation time of the dimension)). So all in all, a lot of clumsy code that was so easily avoided by just having that chunk generated.


The solution I have now works fine though. After registering the new dimension I simply call loadChunk() and populate() on it and the matter receiver is properly created and registered. After that I don't need to do anything special and my teleportation system just works as it would normally.

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.

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.