Guest User

Ender Dragon Instakillinator

a guest
May 31st, 2023
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 19.04 KB | None | 0 0
  1. //funny thingy to find angles
  2. //aka what yaw/yaw/pitch do I need in order to throw a pearl
  3. //such that i get teleported into the dragon's body at such a precision to give me many velocity
  4. //in a direction that lets me shoot a mach 20 arrow into the dragon, killing it instantly
  5. //
  6. //This utilizes a sprint jump velocity desync between the server/client in order to fine-tune the exact pearl velocity
  7. //this lets us target extremely precise spots without adjusting our position at all
  8. //I think you can get within 0.001m pretty consistently. Which is pretty insane if you know how pearls work
  9. //
  10. //i also realize that this code is super inefficient
  11. //and can be vastly improved with a bit of trig
  12. //but I didn't pay attention in math class and turns out computers are REALLY good at math anyway
  13. //
  14. //you'll have to find your own dragon information to get it to run
  15. //but tbh if you can't obtain that you'll probably have a hard time anyway sorry
  16. //I also havent tested the initClientVel/initServerVel thingies because I didn't need them soo enter at your own risk
  17. //
  18. //in order to execute in-game you have to look in server yaw for one tick
  19. //then turn and sprint jump towards client yaw/pitch for one tick
  20. //and then throw a pearl
  21.  
  22. class InstaKillinator {
  23.  
  24.     ///execute in minecraft:the_end run tp @s 44.10 91.00 -1.76 89.85 -22.41
  25.     //starting pos
  26.     static Vec3 initPos = new Vec3(46.11266719320051, 91.00, 5.495603971894525E-15);
  27.     //server velocity right before throw tick(y has no effect because jump velocity).
  28.     static Vec3 initServerVel = new Vec3(0.0,0,0.0);
  29.     //client velocity during jump tick(y has no effect because you're assumed on the ground).
  30.     static final Vec3 initClientVel = new Vec3(0,0,0.0);
  31.     //random offset from pearl rng
  32.     static final Vec3 pearlRNG = new Vec3(0,0,0);
  33.  
  34.     //dragon midpoint spot
  35.     static Vec3 dBodyPos = new Vec3(44.18664241259023, 124.07306706667013, -13.115441869969073);
  36.     //dragon neck hitbox
  37.     static Vec3 dNeckNegPos = new Vec3(38.19537725378829, 123.95384732909187, -17.7381524500122);
  38.     static Vec3 dNeckPosPos = new Vec3(41.19537725378829, 126.95384732909187, -17.7381524500122);
  39.     //minimum velocity we want from this throw
  40.     static final double minVel = 440.0;
  41.     //increases the range of angles checked because i'm paranoid abt rounding
  42.     //does this by increasing the size of the target area, while still not accepting speeds below the minVel
  43.     static final double targetBuffer = 0.001;
  44.     //how precise to iterate through our magic search area of angles
  45.     //i wonder what it would look like to plot these on a 3d graph
  46.     static final float serverYawStep = .1f;
  47.     static final float clientYawStep = .1f;
  48.     static final float clientPitchStep = .1f;
  49.  
  50.  
  51.     public static void main(String[] args) {
  52.  
  53.         // our x,y plane will look like z,-x
  54.         // (-Math.sin(f)), (Math.cos(f))
  55.         double maxDistForVel = 8/minVel;
  56.         double maxTargetDist = maxDistForVel + targetBuffer;
  57.         initPos = initPos.add(initClientVel.x, 0, initClientVel.z); //incoming velocity essentially only offsets our base position
  58.         initServerVel.add(pearlRNG); //pearl rng is just disguised server velocity
  59.         double initDragonAngle = Math.atan2(-(dBodyPos.x - initPos.x), (dBodyPos.z - initPos.z)) / (Math.PI / 180); //angle towards dargon
  60.         double initDragonDistance = Math.sqrt((dBodyPos.x - initPos.x) * (dBodyPos.x - initPos.x) + (dBodyPos.z - initPos.z) * (dBodyPos.z - initPos.z)); //dist to dragon
  61.         //length of our server velocity vector in the direction of our dragon angle
  62.         double serverVelDragonLength = Math.sqrt(initServerVel.x * initServerVel.x + initServerVel.z * initServerVel.z) * Math.cos(Math.atan2(-initServerVel.x, initServerVel.z) - initDragonAngle * (Math.PI / 180));
  63.         //two positions we can jump to that change our angle to the dragon the most
  64.         Vec3 posJumpBound = jumpOffset((float)(initDragonAngle + 90.0));
  65.         Vec3 negJumpBound = jumpOffset((float)(initDragonAngle - 90.0));
  66.         //and the angles they yield in relation to the most extreme section of the dragon tickle area
  67.         //aka all possible pearl angles that could possibly hit the tickle area fall between these
  68.         //it's a super large range but i don't know the math to make it smaller
  69.         double minVelAngle = (Math.atan2(-(dBodyPos.x - (maxTargetDist * Math.sin(initDragonAngle - 90) * (Math.PI / 180)) - posJumpBound.x), (dBodyPos.z + (maxTargetDist * Math.cos(initDragonAngle - 90) * (Math.PI / 180)) - posJumpBound.z)) / (Math.PI / 180));
  70.         double maxVelAngle = (Math.atan2(-(dBodyPos.x - (maxTargetDist * Math.sin(initDragonAngle + 90) * (Math.PI / 180)) - negJumpBound.x), (dBodyPos.z + (maxTargetDist * Math.cos(initDragonAngle + 90) * (Math.PI / 180)) - negJumpBound.z)) / (Math.PI / 180));
  71.         //start searching angles....
  72.         clientPitchLoop: for(float clientPitch = -90f; clientPitch <= 90f; clientPitch+= clientPitchStep){
  73.             //approximate pearl upwards trajectory at this pitch in order to see if it can reach dragon
  74.             //can't know exactly cuz sin/cos coarseness of x/z, but hopefully this is good enough
  75.             double pearlPosY = initPos.y + 1.9399999901652336; //eye position + jump height but butchered by floats
  76.             float pearlDirY = -BoyKisser.MCsin(clientPitch * BoyKisser.RAD());
  77.             double pearlTestVelY =  pearlDirY * 1.5f + 0.33319999363422365 + 0.0001; //+0.0001 so we don't miss anything from coarseness(i think that's big enough)
  78.             double pearlTestPosY = pearlPosY;
  79.             int trajectoryTickTime = 0;
  80.             while(pearlTestVelY >= 0 && pearlTestPosY < dBodyPos.y - 0.3f){ //tick 1d pearl pog (no need for real collision cuz it's one infinite surface)
  81.                 pearlTestPosY+= pearlTestVelY;
  82.                 pearlTestVelY = (pearlTestVelY * .99f) - .03f; //air resistance/gravity
  83.                 trajectoryTickTime++;
  84.             }
  85.             if(pearlTestPosY < dBodyPos.y - 0.3f) break; //we fell too short, give up. Don't even try any more pitches since going lower isn't going to help.
  86.             //we know we can reach the dragon height at this pitch, now screen for horizontal distance
  87.             float pearlPitchFactor = BoyKisser.MCcos(clientPitch * BoyKisser.RAD());
  88.             //find the furthest we can possibly throw the pearl at this pitch
  89.             double pearlTestVelH = 1.5f * pearlPitchFactor + serverVelDragonLength + 0.18200001f;
  90.             double pearlTestPosH = 0.3274000153899195;
  91.             for(int ticks = 0; ticks < trajectoryTickTime; ticks++){ //tick 1d pearl pt.2 horizontal edition (until we hit dragon height)
  92.                 pearlTestPosH+= pearlTestVelH;
  93.                 pearlTestVelH*= .99f;
  94.             }
  95.             if(pearlTestPosH < initDragonDistance - maxTargetDist) continue; // pearl didn't go far enough even with perfect conditions. Try the next pitch
  96.             //find the closest we can possibly throw the pearl at this pitch
  97.             pearlTestVelH = 1.5f * pearlPitchFactor + serverVelDragonLength - 0.18200001f;
  98.             pearlTestPosH = -0.3274000153899195;
  99.             for(int ticks = 0; ticks < trajectoryTickTime; ticks++){ //tick 1d pearl pt.3 sucky horizontal edition(until we hit dragon height)
  100.                 pearlTestPosH+= pearlTestVelH;
  101.                 pearlTestVelH*= .99f;
  102.             }
  103.             if(pearlTestPosH > initDragonDistance + maxTargetDist) continue; // pearl went too far even with perfect conditions. Try the next pitch
  104.  
  105.             //at this point we have a reasonably vetted pitch that could potentially hit the dragon.
  106.             //which means we can now start iterating over server yaws.
  107.             //any angle here is fine since they're just acting as small offsets
  108.             for(float serverYaw = 0; serverYaw <= 360f; serverYaw+= serverYawStep){
  109.                 //calculate server velocity from sprint jumping towards this direction(plus starting server vel)
  110.                 //and no need to deal with movement acceleration because server doesn't care and nobody asked
  111.                 Vec3 serverVel = jumpVelocity(serverYaw);
  112.                 serverVel.x+= initServerVel.x;
  113.                 serverVel.z+= initServerVel.z;
  114.                 //one tick of gravity/resistance because I'm too lazy to deal with lagged pearls in playback
  115.                 serverVel.x*= 0.91f;
  116.                 serverVel.y = (serverVel.y - 0.08) * 0.98f;
  117.                 serverVel.z*= 0.91f;
  118.  
  119.                 //we can now use this vector as well as our min/maxVelAngles to construct a range of possible client yaws
  120.                 //that after being affected by the serverVel and position offsets have potential to hit the tickle area
  121.                 //there's a chance these min/maxs could be undefined when the horizontal velocity is less than server velocity
  122.                 //but it doesn't seem to break anything so idc
  123.                 float clientYawMin = (float)(startingAngleFromOffset(serverVel.x, serverVel.z, minVelAngle * (Math.PI / 180), 1.5f * pearlPitchFactor) / (Math.PI / 180));
  124.                 float clientYawMax = (float)(startingAngleFromOffset(serverVel.x, serverVel.z, maxVelAngle * (Math.PI / 180), 1.5f * pearlPitchFactor) / (Math.PI / 180));
  125.                 //now we can iterate through these yaws
  126.                 //and finally start bruteforcing pearls to see if we get any hits
  127.                 //everything up to here was just getting okayish bounds
  128.                 for(float clientYaw = clientYawMin; clientYaw < clientYawMax; clientYaw+= clientYawStep){
  129.                     //starting state:
  130.                     Vec3 pearlPos = jumpOffset(clientYaw); //pearl start pos
  131.                     pearlPos.y+= 1.5200000032782555; //eye height thingie
  132.                     Vec3 pearlVel = new Vec3(
  133.                             -BoyKisser.MCsin(clientYaw * BoyKisser.RAD()) * pearlPitchFactor,
  134.                             pearlDirY,
  135.                             BoyKisser.MCcos(clientYaw * BoyKisser.RAD()) * pearlPitchFactor
  136.                     ); //initial direction
  137.                     double l = (float)Math.sqrt((pearlVel.x * pearlVel.x + pearlVel.y * pearlVel.y + pearlVel.z * pearlVel.z));
  138.                     pearlVel.x = (pearlVel.x / l * (double)1.5f) + serverVel.x;
  139.                     pearlVel.y = (pearlVel.y / l * (double)1.5f) + serverVel.y;
  140.                     pearlVel.z = (pearlVel.z / l * (double)1.5f) + serverVel.z; //normalization cuz coarseness(?), speed adjustment, and server velocity factor
  141.                     int ticks = 0;
  142.                     while(true){
  143.                         ticks++;
  144.                         double pearlIntendedX = pearlPos.x + pearlVel.x;
  145.                         double pearlIntendedY = pearlPos.y + pearlVel.y;
  146.                         double pearlIntendedZ = pearlPos.z + pearlVel.z;
  147.                         if(pearlIntendedY >= dBodyPos.y - 0.3f) break; //we hit the dragon stop ticking
  148.                         if(pearlVel.y < 0) break clientPitchLoop; //turns out we couldn't hit the dragon, give up
  149.                         pearlPos.set(pearlIntendedX, pearlIntendedY, pearlIntendedZ); //update pos
  150.                         pearlVel.x*= .99f;
  151.                         pearlVel.y = pearlVel.y * .99f - .03f;
  152.                         pearlVel.z*= .99f; //air resistance/gravity
  153.                     }
  154.                     //pearlPos should now be the position the player will be teleported to(tick before it collides)
  155.                     //so we can just do some logic on it as if it was the player
  156.                     double playerDragonDistX = pearlPos.x - dBodyPos.x;
  157.                     double playerDragonDistZ = pearlPos.z - dBodyPos.z;
  158.                     double playerDragonDist = playerDragonDistX * playerDragonDistX + playerDragonDistZ * playerDragonDistZ;
  159.                     if(playerDragonDist > maxDistForVel * maxDistForVel) continue; //we missed the tickle area go next.
  160.                     //calculate exact velocity it gives us to see if it can hit a hitbox.
  161.                     double dragonVelBoostX = playerDragonDistX / playerDragonDist * 8.0;
  162.                     double dragonVelBoostZ = playerDragonDistZ / playerDragonDist * 8.0;
  163.                     dragonVelBoostZ*= .91f;
  164.                     dragonVelBoostX*= .91f;
  165.                     //collision time :heart_eyes:
  166.                     //only going to check x and z, y should be mostly guaranteed
  167.                     //and also only for the neck because that's all we can reach without like 100 y velocity which uhhhh yeah
  168.                     //also probably misses some things that could barely be hit with a little bit of aiming, but meh
  169.                     //you get enough results regardless
  170.                     CollisionTest:
  171.                     {
  172.                         if (dragonVelBoostX > 0) {
  173.                             double hitP = (dNeckNegPos.x - pearlPos.x) / dragonVelBoostX; //% along X axis where it would hit x- side
  174.                             double hitZ = pearlPos.z + hitP * dragonVelBoostZ; //coord where it'd hit on Z
  175.                             if (0.0 < hitP && hitP < 1.0 && dNeckNegPos.z - 1.0E-7 < hitZ && hitZ < dNeckPosPos.z + 1.0E-7) {
  176.                                 break CollisionTest; //hit
  177.                             }
  178.                         }
  179.                         if (dragonVelBoostX < 0) {
  180.                             double hitP = (dNeckPosPos.x - pearlPos.x) / dragonVelBoostX; //% along X axis where it would x+ side
  181.                             double hitZ = pearlPos.z + hitP * dragonVelBoostZ; //coord where it'd hit on Z
  182.                             if (0.0 < hitP && hitP < 1.0 && dNeckNegPos.z - 1.0E-7 < hitZ && hitZ < dNeckPosPos.z + 1.0E-7) {
  183.                                 break CollisionTest; //hit
  184.                             }
  185.                         }
  186.                         if (dragonVelBoostZ > 0) {
  187.                             double hitP = (dNeckNegPos.z - pearlPos.z) / dragonVelBoostZ; //% along Z axis where it would hit z- side
  188.                             double hitX = pearlPos.x + hitP * dragonVelBoostX; //coord where it'd hit on X
  189.                             if (0.0 < hitP && hitP < 1.0 && dNeckNegPos.x - 1.0E-7 < hitX && hitX < dNeckPosPos.x + 1.0E-7) {
  190.                                 break CollisionTest; //hit
  191.                             }
  192.                         }
  193.                         if (dragonVelBoostZ < 0) {
  194.                             double hitP = (dNeckPosPos.z - pearlPos.z) / dragonVelBoostZ; //% along Z axis where it would z+ side
  195.                             double hitX = pearlPos.x + hitP * dragonVelBoostX; //coord where it'd hit on X
  196.                             if (0.0 < hitP && hitP < 1.0 && dNeckNegPos.x - 1.0E-7 < hitX && hitX < dNeckPosPos.x + 1.0E-7) {
  197.                                 break CollisionTest; //hit
  198.                             }
  199.                         }
  200.                         continue;
  201.                     }
  202.                     double velAngle = Math.atan2(-dragonVelBoostX, dragonVelBoostZ) / BoyKisser.RAD();
  203.                     System.out.printf("hit in %d ticks at (%f,%f,%f) at dist %f with %f speed(%f, %f) at angle %f - serverYaw: %f, clientYaw: %f, clientPitch: %f%n", ticks, pearlPos.x, pearlPos.y, pearlPos.z, Math.sqrt(playerDragonDist), 8.0/Math.sqrt(playerDragonDist), dragonVelBoostX, dragonVelBoostZ, velAngle, serverYaw, clientYaw, clientPitch);
  204.                 }
  205.             }
  206.         }
  207.     }
  208.  
  209.     //returns the starting position, offset by one tick's worth of movement
  210.     //assuming starting on the ground with 0 momentum, and inputting forward, sprint, jump in whatever yaw
  211.     //also assumes no collision and no hitbox. Just praying that hitbox float stuff doesn't become an issue
  212.     static Vec3 jumpOffset(float yaw){
  213.         //start with just jump velocity
  214.         Vec3 offsetVel = jumpVelocity(yaw);
  215.         //acceleration from holding forward
  216.         offsetVel.x+= -((double)0.98f * (double)0.13000001f) * BoyKisser.MCsin(yaw * BoyKisser.RAD());
  217.         offsetVel.z+= ((double)0.98f * (double)0.13000001f) * BoyKisser.MCcos(yaw * BoyKisser.RAD());
  218.         //ez now just add to initial position and send her home
  219.         return initPos.add(offsetVel);
  220.     }
  221.  
  222.     //returns velocity from sprint jumping towards the specified yaw
  223.     static Vec3 jumpVelocity(float yaw){
  224.         return new Vec3(
  225.                 -BoyKisser.MCsin(yaw * BoyKisser.RAD()) * 0.2f,
  226.                 0.42f,
  227.                 BoyKisser.MCcos(yaw * BoyKisser.RAD()) * 0.2f
  228.         );
  229.     }
  230.  
  231.  
  232.     //i have no idea what to call this but it's a random function I pulled out my rear end no idea if it has a name/meaning
  233.     //the idea is you can take an angle you want, desiredAngle
  234.     //and solve for the angle B of a vector with length startLength
  235.     //such that adding this vector to the offset vector provided yields our desiredAngle
  236.     //it then just returns this angle B
  237.     //also confines to minecraft coordinates X,Z- not necessarily x,y
  238.     static double startingAngleFromOffset(double offsetX, double offsetZ, double desiredAngle, double startLength){
  239.         //B = A - asin( (z*cos(A)-y*sin(A)) / n )
  240.         return desiredAngle - Math.asin((-offsetZ * Math.sin(desiredAngle) - offsetX * Math.cos(desiredAngle)) / startLength);
  241.     }
  242.  
  243. }
  244.  
  245. class BoyKisser { //silly math stuff to mimic how minecraft handles it
  246.  
  247.     //lookup table used by minecraft trigonometry functions
  248.     private static final float[] MCsins = constructSines();
  249.  
  250.     //radian value thingy to make my life easier
  251.     //or smthn ig idk what a math is
  252.     private static final float RAD = ((float)Math.PI / 180);
  253.  
  254.     //builds the sin table from minecraft
  255.     public static float[] constructSines(){
  256.         float[] MCsins = new float[65536];
  257.         for (int i = 0; i < 65536; ++i) {
  258.             MCsins[i] = (float)Math.sin((double)i * Math.PI * 2.0 / 65536.0);
  259.         }
  260.         return MCsins;
  261.     }
  262.     //returns the sin value of a given radian
  263.     //but using minecraft's quirky table
  264.     public static float MCsin(float f) {
  265.         return MCsins[(int)(f * 10430.378f) & 0xFFFF];
  266.     }
  267.  
  268.     //returns the cos value of a given radian
  269.     //but also using minecraft's quirky table
  270.     public static float MCcos(float f) {
  271.         return MCsins[(int)(f * 10430.378f + 16384.0f) & 0xFFFF];
  272.     }
  273.  
  274.     //returns the funky radian value?
  275.     public static float RAD(){
  276.         return RAD;
  277.     }
  278. }
  279.  
  280. class Vec3{
  281.     //:3
  282.     public double x;
  283.     public double y;
  284.     public double z;
  285.  
  286.     public Vec3(){
  287.         this.x = 0.0;
  288.         this.y = 0.0;
  289.         this.z = 0.0;
  290.     }
  291.     public Vec3(double x, double y, double z){
  292.         this.x = x;
  293.         this.y = y;
  294.         this.z = z;
  295.     }
  296.     public String toString(){
  297.         return String.format("(%.3f, %.3f, %.3f)", this.x, this.y, this.z);
  298.     }
  299.     public void set(double x, double y, double z){
  300.         this.x = x;
  301.         this.y = y;
  302.         this.z = z;
  303.     }
  304.     public Vec3 add(Vec3 a){
  305.         return new Vec3(this.x + a.x, this.y + a.y, this.z + a.z);
  306.     }
  307.     public Vec3 add(double x, double y, double z){
  308.         return new Vec3(this.x + x, this.y + y, this.z + z);
  309.     }
  310. }
Advertisement
Add Comment
Please, Sign In to add comment