Jump to content

[1.7.2] Teleporting to where your cursor is at?


MegaGEN50

Recommended Posts

You'll need to look into ray tracing in minecraft forge. Either find a forum topic about it, or look in the essentials of the vanilla code to see how it's used (e.g. when a block is even selected).

 

I've haven't ever done anything like this, so that's all I can tell you, sorry :P

 

 

I like to make mods, just like you. Here's one worth checking out

Link to comment
Share on other sites

You could cheat and make an invisible entity that is not affected by gravity, so when the player uses the item it shoots out one of those and teleports the player upon impact.

 

If you want to be able to teleport somewhere even if the player isn't looking at a block (or don't want to use an entity), then you can traverse the player's look vector using for loops to increment each posX/Y/Z by the vector's corresponding coordinates until you either have run 128 iterations (traveled 128 block distances) or hit a block, at which point you teleport the player to that position (or that position minus one or two, if you hit a block).

Link to comment
Share on other sites

Ray Tracing is probably a good idea, I'll take a look at that stuff.

What I'm probably thinking about doing is writing a code that simulates the /tp command, but instead of using the coords or target player, it would use the block you're looking at.

Link to comment
Share on other sites

I made a teleport wand (cursor location) a few weeks ago, in Forge 10.12.0.997, I will tell you how I did it :P

 

[ !!! INCOMING: WALL OF TEXT !!! ]

 

I created a special class for the teleportation and made a method [void] method with (World, EntityPlayer) for the whatchamacallit [forgot ><, someone please tell me] Checking if the world is NOT remote, I get the player's look location [getLook] and position [getPosition] through vectors (Vec3) [vector, lookVector], and multiplying the lookVector (x, y, z) by 50 doubles (50D) to another vector (addedVector).

Then I used (World.clip(Vec3, Vec3)) as a MovingObjectPosition to create an object (that helps locate the error you are looking at). Checking if the moving object is not null, and the thing it hits is a block, I save the coordinates of where it hits, and teleport the player to the location of the saved coordinates through the server net handler, making fall distance to 0F to remove fall damage.

 

I might give you PSUEDO CODE if you need more help/this makes NO sense.

Link to comment
Share on other sites

  • 2 weeks later...

I made a teleport wand (cursor location) a few weeks ago, in Forge 10.12.0.997, I will tell you how I did it :P

 

[ !!! INCOMING: WALL OF TEXT !!! ]

 

I created a special class for the teleportation and made a method [void] method with (World, EntityPlayer) for the whatchamacallit [forgot ><, someone please tell me] Checking if the world is NOT remote, I get the player's look location [getLook] and position [getPosition] through vectors (Vec3) [vector, lookVector], and multiplying the lookVector (x, y, z) by 50 doubles (50D) to another vector (addedVector).

Then I used (World.clip(Vec3, Vec3)) as a MovingObjectPosition to create an object (that helps locate the error you are looking at). Checking if the moving object is not null, and the thing it hits is a block, I save the coordinates of where it hits, and teleport the player to the location of the saved coordinates through the server net handler, making fall distance to 0F to remove fall damage.

 

I might give you PSUEDO CODE if you need more help/this makes NO sense.

I know what you're trying to say, but a bit of code might help. :P

Thanks tho! :D

Link to comment
Share on other sites

I made a similar item and this worked for me. I also didn't want the y to increase but I think you can figure that out

 

In onItemRightClick

double distance = 128;
double a = Math.toRadians(player.rotationYaw);
double dx = -Math.sin(a) * distance;
double dz = Math.cos(a) * distance;
player.setPositionAndUpdate(player.posX + dx, player.posY, player.posZ + dz);// takes in account for collisions with blocks.

Link to comment
Share on other sites

I'll try and give you the basic fields you need and you can rearrange them (if you really know how to use these, if not I'll give you cheats).

* looks at 1 month old stuff *

This might be a long post, but worth it for people to learn some things.

 

Like I said I created a Teleportation Handler with a teleport method.

public void teleport(World world, EntityPlayer player)

 

I checked if the world is not remote[server]:  (!world.isRemote)

Then got the player's position - adding the yCoord (++) by 1 to make sure you aren't inside the block.

Vec3 vec3 = player.getPosition(1.0F);
vec3.yCoord++;

 

Then I get the look position, and send an invisible MovingObjectPosition - we'll save the block coord it hits later. ;)

I use [World#clip] because its a hardcoded method that helps with this - don't know what to call it :P

Vec3 lookVec = player.getLook(1.0F);
Vec3 aVector = vec3.addVector(lookVec.xCoord * 50.0D, lookVec.yCoord * 50.0D, lookVec.zCoord * 50.0D);
MovingObjectPosition movingObjPos = world.clip(vec3, aVector);

 

I then check if the MovingObject [movingObjPos] is not null, and the [typeOfHit] is a block (MovingObjectPosition.MovingObjectType.BLOCK)

proceeding, I create 3 ints and put each int with the [blockX, blockY, blockZ] of the MovingObject [movingObjPos]

 

I create an instance of the player as EntityPlayerMP - below if you are confused and/or need help.

EntityPlayerMP playerMP = (EntityPlayerMP)player;

 

Once again, I check if EntityPlayerMP's ServerNetHandler's Connection is not closed.

if (!playerMP.playerNetServerHandler.connectionClosed) 

 

I set the PlayerMP's position whilst updating it (setPositionAndUpdate):

playerMP.setPositionAndUpdate((double) blockX, (double) ((float) blockY + 1F), (double) blockZ);

 

Be sure after that you set the player's fallDistance to 0 floats [0F].

 

 

Phew. I'm done :D

 

Link to comment
Share on other sites

I'll try and give you the basic fields you need and you can rearrange them (if you really know how to use these, if not I'll give you cheats).

* looks at 1 month old stuff *

This might be a long post, but worth it for people to learn some things.

 

Like I said I created a Teleportation Handler with a teleport method.

public void teleport(World world, EntityPlayer player)

 

I checked if the world is not remote[server]:  (!world.isRemote)

Then got the player's position - adding the yCoord (++) by 1 to make sure you aren't inside the block.

Vec3 vec3 = player.getPosition(1.0F);
vec3.yCoord++;

 

Then I get the look position, and send an invisible MovingObjectPosition - we'll save the block coord it hits later. ;)

I use [World#clip] because its a hardcoded method that helps with this - don't know what to call it :P

Vec3 lookVec = player.getLook(1.0F);
Vec3 aVector = vec3.addVector(lookVec.xCoord * 50.0D, lookVec.yCoord * 50.0D, lookVec.zCoord * 50.0D);
MovingObjectPosition movingObjPos = world.clip(vec3, aVector);

 

I then check if the MovingObject [movingObjPos] is not null, and the [typeOfHit] is a block (MovingObjectPosition.MovingObjectType.BLOCK)

proceeding, I create 3 ints and put each int with the [blockX, blockY, blockZ] of the MovingObject [movingObjPos]

 

I create an instance of the player as EntityPlayerMP - below if you are confused and/or need help.

EntityPlayerMP playerMP = (EntityPlayerMP)player;

 

Once again, I check if EntityPlayerMP's ServerNetHandler's Connection is not closed.

if (!playerMP.playerNetServerHandler.connectionClosed) 

 

I set the PlayerMP's position whilst updating it (setPositionAndUpdate):

playerMP.setPositionAndUpdate((double) blockX, (double) ((float) blockY + 1F), (double) blockZ);

 

Be sure after that you set the player's fallDistance to 0 floats [0F].

 

 

Phew. I'm done :D

Not to be that guy again, but you should be aware that EntityLivingBase#getPosition is CLIENT side only - you can not use this method when on a server or you will crash. You need to create your own Vec3 using the player's position coordinates:

// you can add 1 to the player's posY directly while creating the vector if you want:
Vec3 positionVector = world.getWorldVec3Pool().getVecFromPool(player.posX, player.posY + 1, player.posZ);

Anyway, the rest of the code should work, just thought it worth mentioning (I learned this one the hard way :P )

Link to comment
Share on other sites

Take a look at OgreSean's old Teleport Swords mod: http://www.minecraftforum.net/topic/157524-v181ogreseans-mods-mods-updated-for-181/

 

It's old, but the vector math is still relevant, you'd just need to change a couple of things to keep it relevant in today's methods. He also has a bit in there about adding "randomness" to the teleport, but you can just get rid of that stuff.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • C:\Minecraft Server>java -Xmx4096M -Xms1024M -jar server.jar nogui Starting net.minecraft.server.Main ERROR StatusConsoleListener Unable to delete file C:\Minecraft Server\logs\latest.log: java.nio.file.FileSystemException C:\Minecraft Server\logs\latest.log: The process cannot access the file because it is being used by another process ^CTerminate batch job (Y/N)?
    • Oke i tried to download a different mod and try that out on my server and i get the same error. Now i know for a fact that my port forwarding and server is working properly, because i can join them without adding any mods into the server file, but then i dont know what i am doing wrong 
    • Salutation to you ladies and gentlemen, i must confidently say a very big thanks to Fastfundrecovery8 AT GMAIL COM for their tremendous action taken over my case immediately brought to their table, i saw how the whole process was going, and i wisperred to myself and said indeed i am previlledge to know such a legitimate recovery company who is very understable and do not stress their client over recovery software tools, Fastfunds Recovery are good in keeping to time, punctuality, I was scammed last year December 18, i realized that my long investment which i inteded to withdraw has long been a scam, got so frustrated, hired 4 recovery hackers which ended up taking money from me and i couldn't contact them anymore, i went through emotional pains and betrayer, wasn't easy for me at that moment, am very greatful for FastFunds Recovery, who was referred to me by a civil engineer who i was opportuned to share part of my story with and he was like i have a cyber friend do reach and say i'm from Pato's, that's how i got in touch with fastfundsrecovery8(@)gmail(.)com, do inform FastFunds recovery for any cyber issues. Fastfundsrecovery8 AT GMAIL WILL ALWAYS HELP GET BACK YOUR FUNDS.
    • Hello everyone i have made a server with forge and have added pixelmon into the server. But for some reason i keep getting "Internal Exception: io.netty.handles.codec.DecoderException: Not enough bytes in buffer, expected 105, byt got 48". I tried upping the ram of the server to 2GB but it didnt solve anything. I have 16 GB of ram on my pc (where i host the server), but i cant seem to get it to work. Pixelmon does work when i try to go into singleplayer, but for some reason just doesnt work online   Edit: server logs sais nothing aswell [18:55:49] [ServerMain/INFO]: Environment: Environment[accountsHost=https://api.mojang.com, sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD] [18:55:50] [ServerMain/INFO]: Loaded 7 recipes [18:55:51] [ServerMain/INFO]: Loaded 1271 advancements [18:55:51] [Server thread/INFO]: Starting minecraft server version 1.20.2 [18:55:51] [Server thread/INFO]: Loading properties [18:55:51] [Server thread/INFO]: Default game type: SURVIVAL [18:55:51] [Server thread/INFO]: Generating keypair [18:55:51] [Server thread/INFO]: Starting Minecraft server on *:xxxx [18:55:51] [Server thread/INFO]: Using default channel type [18:55:51] [Server thread/INFO]: Preparing level "world" [18:55:52] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld [18:55:53] [Worker-Main-8/INFO]: Preparing spawn area: 0% [18:55:53] [Worker-Main-8/INFO]: Preparing spawn area: 0% [18:55:53] [Worker-Main-8/INFO]: Preparing spawn area: 0% [18:55:53] [Worker-Main-12/INFO]: Preparing spawn area: 0% [18:55:54] [Worker-Main-11/INFO]: Preparing spawn area: 31% [18:55:54] [Server thread/INFO]: Time elapsed: 2344 ms [18:55:54] [Server thread/INFO]: Done (2.865s)! For help, type "help" [18:55:56] [User Authenticator #1/INFO]: UUID of player kemal007023 is 9a2a1dff-fa06-4e29-b57d-b1e6afb2db87 [18:55:56] [Server thread/INFO]: kemal007023[/xxxx] logged in with entity id 271 at (9.497695306619189, 68.0, 10.973182362716573) [18:55:56] [Server thread/INFO]: kemal007023 joined the game [18:55:56] [Server thread/INFO]: kemal007023 lost connection: Disconnected [18:55:56] [Server thread/INFO]: kemal007023 left the game [18:56:00] [User Authenticator #2/INFO]: UUID of player kemal007023 is 9a2a1dff-fa06-4e29-b57d-b1e6afb2db87 [18:56:00] [Server thread/INFO]: kemal007023[xxxx] logged in with entity id 272 at (9.497695306619189, 68.0, 10.973182362716573) [18:56:00] [Server thread/INFO]: kemal007023 joined the game [18:56:00] [Server thread/INFO]: kemal007023 lost connection: Disconnected [18:56:00] [Server thread/INFO]: kemal007023 left the game  
    • Hi, im making a BlockEntity that can contain fluids, and render them in the GUI, only one fluid works perfectly, I can fill or drain it, sync it to the client, and render it. The problem comes when i try to have two fluids in the same GUI, depending on what I delete or leave, the fluids act differently; for example, deleting both of them from "saveAdditional" and "load" methods makes that the fluids cannot render. Also, it can only render one fluid alone, or again, render one fluid, but twice (copies one fluid to the other one). FYI the left one is water, the right one is a red custom fluid. How can I fix this? BoilerBlockEntity: https://pastebin.com/e6b2U3sD BoilerMenu: https://pastebin.com/D375yCNr BoilerScreen: https://pastebin.com/WMrK83Du 
  • Topics

×
×
  • Create New...

Important Information

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