Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi, I'm trying to create a spawning platform when players spawn in a custom dimension, so that they don't fall from a high area.

 

Travelling to and from the custom dimension and the overworld works, but the platform is being created in the overworld instead of the custom dimension.

 

The relevant code for the portal block (transfers player properly when right-clicked):

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float x2, float y2, float z2) {
  if (player instanceof EntityPlayerMP && !world.isRemote) { // Might be a bit redundant
    if (player.dimension == 0) {
      EntityPlayerMP serverPlayer = (EntityPlayerMP)player;
      serverPlayer.mcServer.getConfigurationManager().transferPlayerToDimension(serverPlayer, CUSTOM_DIM_ID, new CustomTeleporter());
    }
    else {
      // ...
    }
  }
}

 

The CustomTeleporter class extends Teleporter, and I overrode 3 methods:

@Override
public void placeInPortal(Entity entity, double dX, double dY, double dZ, float f) {
  if (entity instanceof EntityPlayer) {
    makePortal(entity);
    placeInExistingPortal(entity, dX, dY, dZ, f);
  }
}

@Override
public boolean placeInExistingPortal(Entity entity, double dX, double dY, double dZ, float f) {
  if (entity instanceof EntityPlayerMP) {
    EntityPlayerMP player = (EntityPlayerMP)entity;
    player.setPosition(dX, dY, dZ);
    return true;
  }
  return false;
}

@Override
public boolean makePortal(Entity entity) {
  if (entity instanceof EntityPlayerMP) {
    EntityPlayerMP player = (EntityPlayerMP)entity;      
    
    System.out.println("making portal in dimension "+ player.dimension); // This prints out the ID of the custom dimension
      
    int pX = MathHelper.floor_double(player.posX);
    int pY = MathHelper.floor_double(player.posY);
    int pZ = MathHelper.floor_double(player.posZ);
   
    this.worldServerInstance.setBlock(pX, pY-1, pZ, Blocks.glowstone); // This sets the block in the overworld (or previous dimension) instead of the current one
    
    return true;
  }
  return false;
}

 

The Teleporter class seems to be the class that creates the nether portal when you travel to the nether, so I'm not sure why it's changing the blocks in the overworld instead of the custom dimension.

 

Is there any explanation of what the Teleporter class does, or any explanation of how custom dimensions work? (The tutorials that I've found show examples of code, but they don't really have much explanation.)

Hi

 

What WorldServer did you give Teleporter in your CustomTeleporter constructor?

serverPlayer.mcServer.getConfigurationManager().transferPlayerToDimension(serverPlayer, CUSTOM_DIM_ID, new CustomTeleporter());

 

Each dimension has its own WorldServer.  So I'm guessing you've probably given your Teleporter the wrong one.

 

MinecraftServer.getServer().worldServerForDimension or DimensionManager.getWorld() might be of use.

 

-TGG

  • Author

Ah, I gave the teleporter serverPlayer.getServerForPlayer(), but that's the WorldServer that the player was previously in.

 

I ended up adding the platform generation to the onBlockActivated() method after transferring the player to the new dimension:

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float x2, float y2, float z2) {
  if (player instanceof EntityPlayerMP && !world.isRemote) { // Might be a bit redundant
    if (player.dimension == 0) {
      EntityPlayerMP serverPlayer = (EntityPlayerMP)player;
      serverPlayer.mcServer.getConfigurationManager().transferPlayerToDimension(serverPlayer, CUSTOM_DIM_ID, new CustomTeleporter());

      World customDimension = serverPlayer.getServerForPlayer(); // Is now the WorldServer for the custom dimension

      int pX = MathHelper.floor_double(serverPlayer.posX);
      int pY = MathHelper.floor_double(serverPlayer.posY);
      int pZ = MathHelper.floor_double(serverPlayer.posZ);

      customDimension.setBlock(pX, pY-1, pZ, Blocks.glowstone);
    }
    else {
      // ...
    }
  }
}

 

Which works.

 

Thanks!

Nephroid

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.