Posted March 14, 20232 yr I'm trying to make lightning sword (cliché, I know) that calls down lightning at the position the player is looking at on right click. I already have it really close to done, and I can call lightning down at a BlockPos (I've tested this by calling lightning on the player themselves). So all of that works, I just need to find the coordinates the player is looking at from either a Player or ServerPlayer object
March 16, 20232 yr some math you need // #########################################################################3 // devuelve el punto en el espacio a la distancia especificada en la direccion // hacia donde esta // mirando el player public Vec3 calcular_vo() { return calcular_vo(this.vi, this.subject, this.distancia, this.precision); } public Vec3 calcular_vo(Vec3 vi, Entity player, int distancia, float precision) { // int distancia, float // precision // System.out.println( "calcularVectores(Vec3 " + vi + ", Entity player, int " + // distancia + ", float " + precision + ")" ); // vi = player.getEyePosition(0.0F); // rotacion Vertical en grados float gpitch = player.getViewXRot(0.0F); // rotacion Horizontal en grados float gyaw = player.getViewYRot(0.0F); // precision = 0.0F => perfect aim // precision = 1.0f => 45º ramdom error any direction precision = (precision > 1.0F) ? 1.0F : ((precision < 0.0F) ? 0.0F : precision); float factor = (90F * precision); gpitch = (float) ((gpitch - (factor / 2)) + (factor * Math.random())); gpitch = fixGrad(gpitch); gyaw = (float) ((gyaw - (factor / 2)) + (factor * Math.random())); gyaw = fixGrad(gyaw); // util.gradosAradianes(float x) // util.radianesAgrados(float x) // rotacion Horizontal en radianes double ryaw = gradosAradianes(gyaw); // rotacion Vertical en radianes double rpitch = gradosAradianes(gpitch); // correcccion de -90 grados double tmpryaw = ryaw - 1.5707964D; Vec3 vo = new Vec3(vi.x - ((Math.cos(tmpryaw)) * (Math.cos(rpitch) * distancia)), vi.y - (Math.sin(rpitch) * distancia), vi.z - ((Math.sin(tmpryaw)) * (Math.cos(rpitch) * distancia))); return vo; } // #########################################################################3 public static float gradosAradianes(float x) { return (float) ((x * Math.PI) / 180F); } // #########################################################################3 public float radianesAgrados(float x) { return (float) ((x * 180F) / Math.PI); } // #########################################################################3 public static float fixGrad(float D) { D %= 360.0F; if (D < -179F) { D += 360F; } if (D > 180F) { D -= 360F; } return D; }
March 16, 20232 yr player.pick() - method is defined in the Entity class, does ray tracing for an entity On the client, some of the calculations are cached for the player in the Minecraft class, e.g. see how GameRenderer.pick() calculates Minecraft.hitResult or Minecraft.crosshairPickEntity Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
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.