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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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