Jump to content

How to force load a dimension without teleporting to it


McJty

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?

 

Thanks!

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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