Running commands for different coords after entering dimension

Started by spectrejks on

Topic category: Help with modding (Java Edition)

Last seen on 22:37, 22. Apr 2024
Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Running commands for different coords after entering dimension

I currently have a custom portal that teleports the player into The Nether.

When the player enters The Nether they are sometimes teleporting under the map, in block and in lava.

I’m trying to make it so when the player has joined the nether a command is run to replace blocks in a 9x9 area with AIR and generate a platform below the player incase they spawn in mid air.

The only issue is, when entering the portal the procedure generates the platform and airblocks in the over world where the player has entered the portal rather than where they spawn in the nether.

I’ve tried calling:
If entity dimension = nether
Call on procedure: Platform (this procedure contains the commands)
But it still spawns in the over world

Last seen on 20:18, 12. Mar 2024
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Try putting this in a custom…
Sun, 07/16/2023 - 17:34

Try putting this in a custom code snippet at the top of your code:

ResourceKey<Level> destinationType = Level.NETHER;
ServerLevel nextLevel = world.getServer().getLevel(destinationType);

"NETHER" on the first line can be replaced by the dimension you want to place blocks in.

Then, whenever you want to set a block in the nether, use:

nextLevel.setBlock(new BlockPos(x, y, z), Blocks.OAK_PLANKS.defaultBlockState(), 3);

This will ensure that your blocks get placed in the nether, regardless of where the player is. "x", "y", and "z" can be replaced by variable names. In addition, OAK_PLANKS can be replaced by whatever block you want, including AIR to remove blocks.