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