Jump to content

Recommended Posts

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.)

Posted

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

Posted

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.

Announcements



×
×
  • Create New...

Important Information

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