Jump to content

[1.15.2] Teleport Player to Nearest "Safe" Spot


ModMCdl

Recommended Posts

Hello. I wrote a custom teleporter (a basic implementation of ITeleporter) to bring the player in-between my custom dimension and others negating portal spawn. However, the generation in my dimension is made up of floating islands, similar to the End. Right now my custom teleporter brings players to the exact coordinates in each dimension, which results in them high up in the air, falling into the void, or spawning inside a block. What I would like to do is either of the following, for two separate instances:

 

a). Teleport the player to the nearest safe surface in each world. (Nearest island in my dimension, and up to the surface in the overworld).

b). Teleport the player to their own spawn point in the overworld, and the origin of my dimension.

 

I've poked around in the vanilla classes a bit, but can't seem to find any instances of this type of teleportation. Are there any examples of this that you can point me in the direction of and/or does anyone know how to achieve this?

 

Thanks.

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Link to comment
Share on other sites

11 minutes ago, MrInfinity said:

Well In the nether, if you spawn above lava, you spawn inside of a portal with 1 block out on both sides. You might want to use this solution. Or you could have it automatically place a block under the player when they spawn in

But the portal still tries to locate the nearest solid ground to place a portal on, does it not? I tried reverse engineering that code but I was either looking at the wrong methods or just don't know how it's doing that.

 

And whilst I could just spawn a block under the player, that doesn't seem like a survival-friendly solution. 

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Link to comment
Share on other sites

https://minecraft.gamepedia.com/Nether_portal#Portal_search - Under Portal Creation

 

Here it says that a nether portal first looks for any valid locations in a 4x4 chunk radius around the center of where it would spawn. If it finds none, then it will spawn somewhere between y 90 and 10 blocks below the world limit. So if you create a nether-portal like portal, it would follow those rules, meaning that if it spawned in empty space, the floating portal would be created

Edited by MrInfinity
Link to comment
Share on other sites

Just now, MrInfinity said:

https://minecraft.gamepedia.com/Nether_portal#Portal_search - Under Portal Creation

 

Here it says that a nether portal first looks for any valid locations in a 4x4 chunk radius around the center of where it would spawn. If it finds none, then it will spawn somewhere between y 90 and 10 blocks below the world limit. So if you create a nether-portal like portal, it would follow those rules, meaning that if it spawned in empty space, the floating portal would be created

I don't create a portal though, as I specified in my OP. I use a special item to teleport players in between dimensions. 

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Link to comment
Share on other sites

11 hours ago, ModMCdl said:

I've poked around in the vanilla classes a bit, but can't seem to find any instances of this type of teleportation. Are there any examples of this that you can point me in the direction of and/or does anyone know how to achieve this?

I think the method makePortal() in the Teleporter class is where vanilla tries to find a nearby valid position to create the portal in. However, it is kind of a large and unreadable method, so I don't know if it is realistic to try and replicate it.

 

Another possibility would be to do something similar to how the locate command works. I am not too familiar with world generation, but if your islands are generated similar to how vanilla structures are generated, then this could work.

Link to comment
Share on other sites

8 hours ago, diesieben07 said:

You can use World#getHeight to get the surface y position at a given x and z coordinate. You can then use that to place the player on the surface.

Thank you, I had tried doing that with the players spawnpoints, and World#getHeight is definitely a good thing to hear about. I also think I might have been phrasing my question wrong this entire time. I don't know how to implement additional, conditions shall we say, into the changeDimension method. Or even if I can. Do I need to write a custom teleport method to do this? Same thing with sending each player to the spawn point. (Sorry, I just really have no idea what I'm doing in this instance.)

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Link to comment
Share on other sites

Just now, diesieben07 said:

That's exactly what a custom teleporter does, right? what do you mean by "conditions"?

I'm using changeDimension accepts a DimensionType and then ITeleporter, at least as far as I can tell, and so right now I'm using 

               player.changeDimension(world.dimension.getType() == DimensionType.byName(VoidaicDepths.VOID_DIM_TYPE) ? DimensionType.OVERWORLD : DimensionType.byName(VoidaicDepths.VOID_DIM_TYPE), new VoidTeleporter((ServerWorld) player.getEntityWorld()));

 

Passing in my custom dimension and then my custom teleporter.

 

My custom teleporter only overrides placeEntity from ITeleporter so that it does not place a portal. Forgive me, but I can't find how I would add additional methods to check, and as @vemerionhad mentioned, the place portal method that might be doing that is quite "unreadable," or at the very least hard to dissect.

 

Custom Teleporter: https://github.com/ModMCdl/Voidaic-Depths/blob/master/src/main/java/com/modmcdl/voidaicdepths/util/VoidTeleporter.java

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Link to comment
Share on other sites

5 minutes ago, diesieben07 said:

Please describe what you want to achieve from a gameplay perspective, not how you have attempted to program it.

I have an item that on right click, teleports the player to another dimension. I do not want it to spawn a portal. I simply want to teleport the player to their relative coordinates in either dimension, but move them to the nearest "safe" surface. (In the overworld, this would be the surface, in my "void" dimension, this would be the nearest island). Originally, this seemed like the best option. However, after going through the code, I think a better alternative and easier solution would simply be to teleport to each world's spawnpoint. I've been told that each method follows the same idea of relocating the entity, but spawnpoints have an existing implementation, and I can kind of see how it's done with the if statement in player#changeDimension relating to the end.

 

My problem is while I have a general idea of how to do this, I do not know where to place this method so that it will successfully be called when the player teleports. I have considering putting it into my custom teleporter, but I'm not sure how to go about doing that without creating an entirely new changeDimension function. I'm lost in terms of I know the theory behind doing it, but have no idea how to actually implement it. Usually I can find an example in the vanilla code, (which is how I learn most of how I do modding, as seeing examples for me is the best sort of jumping-off point) but I can't seem to find a specific example that actually does what I want, and when I do, the specific use case does not allow me to implement it successfully.

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Link to comment
Share on other sites

2 hours ago, diesieben07 said:

All you need to do is change the entity's position in placeEntity of your teleporter. That is literally the method is used for.

Been picking this problem apart for a few hours now.

 

This is what I'm working on, which from what I've gathered should get the spawn points for each world and place them in a BlockPos, but I'm not sure what I should be doing afterwards to return the new position to the Player. Looking through the javadocs, it appears that repositionEntity is reserved for portal placement specifically, so I don't think I want to return that as true. Right now my script does nothing, as I don't call these new dimensions anywhere.

    @Override
    public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity)
    {
        BlockPos pos;

        if(destWorld.dimension.getType() == DimensionType.byName(VoidaicDepths.VOID_DIM_TYPE))
        {
            pos = destWorld.getSpawnCoordinate();
        }
        else if(destWorld.dimension.getType() == DimensionType.OVERWORLD)
        {
            pos = destWorld.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, destWorld.getSpawnPoint());
        }
        return repositionEntity.apply(false);
    }

 

I don't really know what ask here without sounding stupid, and I know everyone hates it when people ask stupid questions here. You've given me a lot of good information on how to go about doing this, but do you have an example to point me to or an implementation? As I said before, I don't understand how it is working in the vanilla Teleporter class. I tried updating my forge mappings to try and clear up the methods in the Teleporter class, but that didn't seem to change much.

Edited by ModMCdl

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Link to comment
Share on other sites

10 hours ago, ModMCdl said:

This is what I'm working on, which from what I've gathered should get the spawn points for each world and place them in a BlockPos, but I'm not sure what I should be doing afterwards to return the new position to the Player

If you look at the call hierarchy of the placeEntity() method, you can see that the entity it returns is in fact the entity that is teleported. Therefore, to change the position of the entity you would only need to change the position of the entity you return before returning it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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