copy and pasting land between dimensions?

Started by Ellieisokay on

Topic category: Help with Minecraft modding (Java Edition)

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
copy and pasting land between dimensions?

Trying to make it so when a player enters a dimension the nearby land is taken with them, but I'm not sure how I would do that.

just trying to get it to work, it doesn't have to be fancy. 

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You could probably copy a…
Tue, 08/29/2023 - 22:28

You could probably copy a rectangular section of blocks fairly simply by using a bunch of loops:

for (int cx = -10; cx < 10; cx++) {
	for (int cy = -10; cy < 10; cy++) {
		for (int cz = -10; cz < 10; cz++) {
			BlockPos pos = new BlockPos(x + cx, y + cy, z + cz);
			BlockState state = oldLevel.getBlockState(pos);
			newLevel.setBlock(pos, state, 3);
		}
	}
}

But in order to do that, you'd need a handle to both of the dimensions you are about to access. You can get them by getting a level from its resource key:

ResourceKey<Level> destinationType = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation("minecraft:overworld"));
if (entity instanceof ServerPlayer _player && !_player.level.isClientSide()) {
	ServerLevel newLevel = _player.server.getLevel(destinationType);
}

The full code is: (You can paste this into a "Custom code snippet" block; make sure you do this before you actually teleport the player)

if (entity instanceof ServerPlayer _player && !_player.level.isClientSide()) {
	Level oldLevel = _player.level;
	ResourceKey<Level> newLevelType = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation("yourmodname:your_mod_dimension_id"));
	Level newLevel = _player.server.getLevel(newLevelType);
	for (int cx = -10; cx < 10; cx++) {
		for (int cy = -10; cy < 10; cy++) {
			for (int cz = -10; cz < 10; cz++) {
				BlockPos pos = new BlockPos(x + cx, y + cy, z + cz);
				BlockState state = oldLevel.getBlockState(pos);
				newLevel.setBlock(pos, state, 3);
			}
		}
	}
}
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Where do I put this? I tried…
Sun, 09/10/2023 - 03:28

Where do I put this? I tried creating a custom element but it kept saying illegal start to type, tried moving it around a couple times but it wasn't working.

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I figured out where to put…
Sun, 09/10/2023 - 15:50

I figured out where to put it, but it doesn't seem to recognize X Y and Z as coordinates

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Annoyingly, MCreator will…
Sun, 09/10/2023 - 21:17

Annoyingly, MCreator will only recognize "x", "y", and "z" if those appear as blocks somewhere else in the program. Try adding a no-op like "set block at x, y+1000, z to air" or something.

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
seems to work, thanks!
Mon, 09/11/2023 - 01:46

seems to work, thanks!