Jump to content

Short-Range Teleport Player To Look Direction


Zetal

Recommended Posts

Well, like the title says, I'm trying to initiate a short range teleport (limited 3-5 blocks) in the direction that the player is facing. It would ideally be usable in any direction, including upwards, but I'm having some difficulty getting the block to teleport them to. I tried using the rayTrace method contained within EntityLiving but that only works if there is a block targeted and also doesn't work server-side so isn't really applicable.

Have a modding question? PM me and hopefully I'll be able to help. Good at 2d Pixel Art? We need your help!  http://www.minecraftforum.net/topic/1806355-looking-for-2d-pixel-artist/

Link to comment
Share on other sites

Well, like the title says, I'm trying to initiate a short range teleport (limited 3-5 blocks) in the direction that the player is facing. It would ideally be usable in any direction, including upwards, but I'm having some difficulty getting the block to teleport them to. I tried using the rayTrace method contained within EntityLiving but that only works if there is a block targeted and also doesn't work server-side so isn't really applicable.

Use instead player.moveEntity(distance*sin(player.pitch)*sin(player.yaw),distance*cos(player.pitch),distance*sin(player.pitch)*sin(player.yaw));

If it's moving at odd angles try switching x and z.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

You got me on the right track with that moveEntity method, so thanks!

In the end, I wound up having to do:

 

 
            int distance = 5;
            float f1 = MathHelper.cos(-this.rotationYaw * 0.017453292F - (float)Math.PI);
            float f2 = MathHelper.sin(-this.rotationYaw * 0.017453292F - (float)Math.PI);
            float f3 = -MathHelper.cos(-this.rotationPitch * 0.017453292F);
            float f4 = MathHelper.sin(-this.rotationPitch * 0.017453292F);
            double i = this.posX;
            double j = this.posY;
            double k = this.posZ;
            this.moveEntity(distance*f2*f3, 
				distance*f4,
				distance*f1*f3);

 

So for anyone interested, this is how I had to do it. It works great! :D

Have a modding question? PM me and hopefully I'll be able to help. Good at 2d Pixel Art? We need your help!  http://www.minecraftforum.net/topic/1806355-looking-for-2d-pixel-artist/

Link to comment
Share on other sites

Use instead player.moveEntity(distance*sin(player.pitch)*sin(player.yaw),distance*cos(player.pitch),distance*sin(player.pitch)*sin(player.yaw));

If it's moving at odd angles try switching x and z.

 

Is the function generally player.moveEntity(x,y,z)?

Which pivot (for yaw and pitch) is which axes? I have done bits of code for mods of different games and the pivots are not usually with the same axes.

 

I know that I could of made a new post but you seemed to have answered the his/her question clearly.

 

Many thanks, Melonize

Link to comment
Share on other sites

Use instead player.moveEntity(distance*sin(player.pitch)*sin(player.yaw),distance*cos(player.pitch),distance*sin(player.pitch)*sin(player.yaw));

If it's moving at odd angles try switching x and z.

 

Is the function generally player.moveEntity(x,y,z)?

Which pivot (for yaw and pitch) is which axes? I have done bits of code for mods of different games and the pivots are not usually with the same axes.

 

I know that I could of made a new post but you seemed to have answered the his/her question clearly.

 

Many thanks, Melonize

Yes. Y is up. I couldn't remember whether yaw starts from x or z, which is why I mentioned that he might have to switch the two. And it looks like I made a typo anyway. In Minecraft:

X = cos(yaw)sin(pitch)

Y = cos(pitch)

Z = sin(yaw)sin(pitch)

I think. Unfortunately, I can't check with Mojang code because they overcomplicate things ( -cos(x) = -cos(-x) = cos(-x+π), even though none of those should be necessary for such formulas), but the only error should be a switch in X and Z.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

Use instead player.moveEntity(distance*sin(player.pitch)*sin(player.yaw),distance*cos(player.pitch),distance*sin(player.pitch)*sin(player.yaw));

If it's moving at odd angles try switching x and z.

 

I find that moving the player at a slope into the ground causes the player to slide further as your y travel is abruptly blocked by the ground but your horizontal is still full length of what it needs to go for the sloped travel if not blocked e.g. falling.

So here is the fix for it:

try{
// Trace for blocks
MovingObjectPosition eyeTrace = player.rayTrace(distance, 1.0F);
// If no blocks are traced, then eyeTrace is null.
if(eyeTrace.hitVec != null){
	//If a block is found, call the moveEntity below
	player.moveEntity(eyeTrace.hitVec.xCoord-player.posX, eyeTrace.hitVec.yCoord-player.posY + 1.1, eyeTrace.hitVec.zCoord-player.posZ ); 
	}
}
catch(NullPointerException npe){
	// Lolz at your NPE, going to throw you whatever set distance forward in the hope to ignore your NPE
	player.moveEntity(-distance*Math.sin(Math.toRadians(player.rotationYawHead))*Math.cos(Math.toRadians(player.rotationPitch)),-distance*Math.sin(Math.toRadians(player.rotationPitch)), distance*Math.cos(Math.toRadians(player.rotationYawHead))*Math.cos(Math.toRadians(player.rotationPitch)));
}

Link to comment
Share on other sites

Use instead player.moveEntity(distance*sin(player.pitch)*sin(player.yaw),distance*cos(player.pitch),distance*sin(player.pitch)*sin(player.yaw));

If it's moving at odd angles try switching x and z.

 

I find that moving the player at a slope into the ground causes the player to slide further as your y travel is abruptly blocked by the ground but your horizontal is still full length of what it needs to go for the sloped travel if not blocked e.g. falling.

So here is the fix for it:

try{
// Trace for blocks
MovingObjectPosition eyeTrace = player.rayTrace(distance, 1.0F);
// If no blocks are traced, then eyeTrace is null.
if(eyeTrace.hitVec != null){
	//If a block is found, call the moveEntity below
	player.moveEntity(eyeTrace.hitVec.xCoord-player.posX, eyeTrace.hitVec.yCoord-player.posY + 1.1, eyeTrace.hitVec.zCoord-player.posZ ); 
	}
}
catch(NullPointerException npe){
	// Lolz at your NPE, going to throw you whatever set distance forward in the hope to ignore your NPE
	player.moveEntity(-distance*Math.sin(Math.toRadians(player.rotationYawHead))*Math.cos(Math.toRadians(player.rotationPitch)),-distance*Math.sin(Math.toRadians(player.rotationPitch)), distance*Math.cos(Math.toRadians(player.rotationYawHead))*Math.cos(Math.toRadians(player.rotationPitch)));
}

I had a feeling you would run into that; I wasn't quite sure what to do about it. But thanks for posting your solution!

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

  • 3 years later...

I know I'm late to the party, but this was the most elaborate work done on the subject I could find, so if there is anyone left listening, can someone help me make an item that does this? The code is not working and I barely understand what it's doing.

Link to comment
Share on other sites

Yeah, really late. Like 3.5 years late... Make your own post, and show what you have tried.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm unable to join my local forge servers. When running my forge servers of seemingly any version (tested 1.18 to 1.21.1) I get an error message [Forge Version Check/WARN] [ne.mi.fm.VersionChecker/]: Failed to process update information The server continues to start up and run, however I'm unable to join. Looking for solutions? Full error message: (note last "thead warning" error seems to be unrelated and only happened once for 1.20.1) Forge version check warning has happened for every version. [09:52:31] [Forge Version Check/WARN] [ne.mi.fm.VersionChecker/]: Failed to process update information java.net.http.HttpConnectTimeoutException: HTTP connect timed out         at jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:950) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:133) ~[java.net.http:?] {}         at net.minecraftforge.fml.VersionChecker$1.openUrlString(VersionChecker.java:142) ~[fmlcore-1.20.1-47.3.10.jar%23102!/:?] {}         at net.minecraftforge.fml.VersionChecker$1.process(VersionChecker.java:180) ~[fmlcore-1.20.1-47.3.10.jar%23102!/:?] {}         at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {}         at net.minecraftforge.fml.VersionChecker$1.run(VersionChecker.java:117) ~[fmlcore-1.20.1-47.3.10.jar%23102!/:?] {} Caused by: java.net.http.HttpConnectTimeoutException: HTTP connect timed out         at jdk.internal.net.http.ResponseTimerEvent.handle(ResponseTimerEvent.java:68) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientImpl.purgeTimeoutsAndReturnNextDeadline(HttpClientImpl.java:1788) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:1385) ~[java.net.http:?] {} Caused by: java.net.ConnectException: HTTP connect timed out         at jdk.internal.net.http.ResponseTimerEvent.handle(ResponseTimerEvent.java:69) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientImpl.purgeTimeoutsAndReturnNextDeadline(HttpClientImpl.java:1788) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:1385) ~[java.net.http:?] {} [09:52:31] [Yggdrasil Key Fetcher/ERROR] [mojang/YggdrasilServicesKeyInfo]: Failed to request yggdrasil public key com.mojang.authlib.exceptions.AuthenticationUnavailableException: Cannot contact authentication server         at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:119) ~[authlib-4.0.43.jar%2375!/:?] {}         at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:91) ~[authlib-4.0.43.jar%2375!/:?] {}         at com.mojang.authlib.yggdrasil.YggdrasilServicesKeyInfo.fetch(YggdrasilServicesKeyInfo.java:94) ~[authlib-4.0.43.jar%2375!/:?] {}         at com.mojang.authlib.yggdrasil.YggdrasilServicesKeyInfo.lambda$get$1(YggdrasilServicesKeyInfo.java:81) ~[authlib-4.0.43.jar%2375!/:?] {}         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572) ~[?:?] {}         at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358) ~[?:?] {}         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?] {}         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?] {}         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?] {}         at java.lang.Thread.run(Thread.java:1575) ~[?:?] {} Caused by: java.net.SocketTimeoutException: Connect timed out         at sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:546) ~[?:?] {}         at sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:592) ~[?:?] {}         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[?:?] {}         at java.net.Socket.connect(Socket.java:760) ~[?:?] {}         at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:304) ~[?:?] {}         at sun.net.NetworkClient.doConnect(NetworkClient.java:178) ~[?:?] {}         at sun.net.www.http.HttpClient.openServer(HttpClient.java:531) ~[?:?] {}         at sun.net.www.http.HttpClient.openServer(HttpClient.java:636) ~[?:?] {}         at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264) ~[?:?] {}         at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:377) ~[?:?] {}         at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:193) ~[?:?] {}         at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1273) ~[?:?] {}         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1114) ~[?:?] {}         at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:179) ~[?:?] {}         at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1676) ~[?:?] {}         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1600) ~[?:?] {}         at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:223) ~[?:?] {}         at com.mojang.authlib.HttpAuthenticationService.performGetRequest(HttpAuthenticationService.java:140) ~[authlib-4.0.43.jar%2375!/:?] {}         at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:96) ~[authlib-4.0.43.jar%2375!/:?] {}         ... 9 more [09:52:31] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 5985ms or 119 ticks behind
    • Remove the mod tempad from the mods-folder
    • Hi, deleting the config folder did not appear to work, what mod are you referring to I could try to delete to fix the problem?
    • A friend found this code, but I don't know where. It seems to be very outdated, maybe from 1.12? and so uses TextureManager$loadTexture and TextureManager$deleteTexture which both don't seem to exist anymore. It also uses Minecraft.getMinecraft().mcDataDir.getCanonicalPath() which I replaced with the resource location of my texture .getPath()? Not sure if thats entirely correct. String textureName = "entitytest.png"; File textureFile = null; try { textureFile = new File(Minecraft.getMinecraft().mcDataDir.getCanonicalPath(), textureName); } catch (Exception ex) { } if (textureFile != null && textureFile.exists()) { ResourceLocation MODEL_TEXTURE = Resources.OTHER_TESTMODEL_CUSTOM; TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); texturemanager.deleteTexture(MODEL_TEXTURE); Object object = new ThreadDownloadImageData(textureFile, null, MODEL_TEXTURE, new ImageBufferDownload()); texturemanager.loadTexture(MODEL_TEXTURE, (ITextureObject)object); return true; } else { return false; }   Then I've been trying to go through the source code of the reload resource packs from minecraft, to see if I can "cache" some data and simply reload some textures and swap them out, but I can't seem to figure out where exactly its "loading" the texture files and such. Minecraft$reloadResourcePacks(bool) seems to be mainly controlling the loading screen, and using this.resourcePackRepository.reload(); which is PackRepository$reload(), but that function seems to be using this absolute confusion of a line List<String> list = this.selected.stream().map(Pack::getId).collect(ImmutableList.toImmutableList()); and then this.discoverAvailable() and this.rebuildSelected. The rebuild selected seemed promising, but it seems to just be going through each pack and doing this to them? pack.getDefaultPosition().insert(list, pack, Functions.identity(), false); e.g. putting them into a list of packs and returning that into this.selected? Where do the textures actually get baked/loaded/whatever? Any info on how Minecraft reloads resource packs or how the texture manager works would be appreciated!
  • Topics

×
×
  • Create New...

Important Information

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