[SOLVED]How to code Teleportation between Dimensions?

Ok so now the next big step in this plugins creation…i need some assistance how would i use the actual TeleporterAgent to make a portal between worlds work? can i set these portals through commands? if so how? please assist thank you

See look people I’ve seen plugins that can do it…however I’m just looking for something small and compact so i can place down portals or using a mod that’ll allow travel between those worlds like a teleportation device…please help

Plugins that use existing nether and end portals to go to different worlds other than the nether and end they would normally go to, tend to capture the player event associated with moving /teleporting/world changing and then cancel it, and move the player destination to one of their predetermined locations.

Plugins that just use a frame of blocks that you approach and pass thru , tend to respond to the player movement position being within a particular distance from one of many known portal-frame locations, portal X in this case, as the trigger, then change the players location to be that of the corresponding end-target portals - the target location for portal X.

Plugins that use some location with a push-button or plate to step on, to trigger the portal simply work by identifying the location of the triggered plate or button in a redstone-tripping event or a player-block interaction event, and have a mapping knowledge that that button or plate corresponds to portal x, and then changes the players location to be that of the corresponding end - target locations for portal x.

Teleport-helper/safe teleportation is for blind tps without knowing the terrain is clear and open and safe. If you have a portal setup in a safe area for travel, it will always work by simply changing the players location. So its just a matter of what trigger event to listen for, or how to check for a proximity, to determine the trigger-moment when you will alter the players location.

…ok but how would i go about createing a portal in the overworld dimension and TEST dimension and then linking them? or if it can’t be done through dimensions regular world

if you are restricting it to administratively controlled, fixed portals, and not whimisicallyh placed about by anyone at anytime portals…

whatever mechanism you use to create one portal - a slap of a block with a fish, a command … you would generate the portal and store its location information; second portal in other location/world/dimension, same thing, generate it and store its location information (using names for each portal may help store the info, or making all portals only in pairs a and b such that if you’re making a portal, its either the first or second, if its the second, then you cross-link the information from both.)

Dimensions are just another world - any world, any dimension will have a way to identify it. If you dont have some other preexisting cross-world teleport commands, you’d maybe have to make your own since you need to get into those special worlds somehow to place the portal - thats where the setsafelocation part comes in, set the coordinates to 0,64,0 for the position in a location object for the specified world, and set your position to that via command - that gets you into the world, after which you can tp to any specific coordinate you want in that world, etc.

ooook…My mind did not follow that at all my apoligies…i’ve currently got one that’s working…but it uses the world builder to identify the world…can some one help me witha a way to retrieve the world from a registry?

Here’s what i have and how i’m teleporting right now…I’d like to remove the world builder out of it equation so any help would be nice. :smile:

public CommandResult execute(CommandSource src, CommandContext args)
throws CommandException
{
String name = (String)args.getOne(“worldName”).get();
if ((src instanceof Player))
{
Player player = (Player)src;
WorldBuilder builder = (WorldBuilder)this.game.getRegistry().createBuilder(WorldBuilder.class);
builder.dimensionType(DimensionTypes.OVERWORLD);
builder.name(name);
builder.enabled(false);
builder.hardcore(false);
builder.keepsSpawnLoaded(true);
builder.loadsOnStartup(true);
builder.usesMapFeatures(false);
builder.generator(GeneratorTypes.DEFAULT);
Optional optWorld = builder.build();
if (optWorld.isPresent())
{
player.setLocation(((World)optWorld.get()).getSpawnLocation());
player.sendMessage(Texts.of("Succesfully Teleported to: " + name));
return CommandResult.success();
}

The builder is constantly creating the world if needed each time and then being ‘the world’ to use in your code; Builders are only used for making the world, not for specifying the world. Once a world exists, it has a name, and a uuid and can be gotten from game.getServer().getWorld(xxx) methods, or from a collection of worlds listed in game.getServer().


if ((src instanceof Player))
{
// you can do optional world get and check for validity here
// I am just going to short-cut the code as if world “name” does exist
// and use your world spawn location from above…

World w=game.getServer().getWorld(name).get();
(Player)src.setLocation(w.getSpawnLocation());

return CommandResult.success();
}

You can specify any coordinate for the world you want doing
p.setLocation(w.getLocation(x,y,z));
or
p.setLocation(w.getLocation(positionVector3d));

or just generally get/modify/construct a Location object for the world and position in newLocationObj
p.setLocation(newLocationObj);


Your code as it is is good for teleporting to a previously non-existing world, by creating it and going to its default world spawn location after creating it all in one shot. But not for teleporting to known locations.

…except it does work for sending players to an already existing one! becuause the builder is disabled it uses it’s effects! the coding you gave didn’t work…I’m trying remove the parts of the builder from the scenario in this code so that i can get rid of comberson code…i’m not asking if the code works…I already know that the coding works…what i’m trying to do is get it so that i don’t need this many lines…thank you though :confused:

works fine in my test code that was the whole point - get rid of all those lines from the builder, just get the world to use forward… And I wasn’t questioning if the code worked or not - I know that is the code you were using, and wanted to replace… I was outlining that it was remaking the world each time in order to get a world reference to act on -p when all you want is a different way to get a world reference to act on, hence the getWorld(by name or uuid) etc

game.getServer().getWorld(name).get() only works if you have a game variable for Game - so however you need to change that, make it referenced, pass as a paramater / access statically whatever - its the Game object for the server you need

1 Like

ahhhh gotcha thank you

so can someone explain why i get this error?

Something is null in MainClass on line 34. I can’t tell you anymore than that without source code.

…ok if you dont mind me asking…how did you come up with that lol so i can start tyring to help myself on occasion too :smile:

It says

java.lang.NullPointerException
    at me.Cleardragonf.HOS.MainClass.Destroy(MainClass.java:34)
   [...]

You can read the tutorial on exceptions here: Lesson: Exceptions (The Java™ Tutorials > Essential Classes)

The oracle tutorial is a good place to learn java and perhaps figure out things without having to ask
https://docs.oracle.com/javase/tutorial/

OMG i’ve been reading everything below that!!! thank you so much!!!

how is this null?

    World w=game.getServer().getWorld("world").get();

It’s a good possibility that game isn’t correctly initialized

It would help if you shared the code

public class MainClass {

@Inject
private Logger logger;

@Inject
private void setLogger(Logger logger){
    this.logger = logger;
}
public Logger getLogger(){
    return logger;
}
Player player;
Game game;
@Listener
public void Destroy(ChangeBlockEvent.Break event){
    World w=game.getServer().getWorld("world").get();
    player.setLocation(w.getSpawnLocation());
}

}

Ask and you shall recieve :slight_smile:

You need @Inject on Game game;

may i ask what ‘inject’ represents?