Skip to content

Instantly share code, notes, and snippets.

@pwouik
Last active October 12, 2023 19:12
Show Gist options
  • Save pwouik/2c7ffd4e0f8ac96f4e115dedde46e84a to your computer and use it in GitHub Desktop.
Save pwouik/2c7ffd4e0f8ac96f4e115dedde46e84a to your computer and use it in GitHub Desktop.
Tnt cannoning resources

DEPRECATED, GO THERE:

https://gist.github.com/lntricate1/e7a2c3f0e10eaa40ac932cab74619ea7

Learning resources:

Xcom's 3-part explanation series, explains most of the basics of pearls, tnt, and chunkloading needed for cannons:

1- https://www.youtube.com/watch?v=MedklDb71Jw

2- https://www.youtube.com/watch?v=F6OaYojEoog

3- https://www.youtube.com/watch?v=Wc1E1zR40gw

Two old Xcom videos explaining some of the basic concepts behind cannon

https://www.youtube.com/watch?v=XV454aiuTEE

https://www.youtube.com/watch?v=t61qa7EPlH4

Explanation of TNT duplication

https://youtu.be/qkSLYcPAhWI

Tnt physics (x and z axis is now highest velocity first,y always come first)

https://youtu.be/WVSsRrxh9Nw

How to program a cannon destination:

https://youtu.be/UlhnxoN7U4g?t=554

Info/data

TNT Explosion Height (not same as eye height): 0.98F*0.0625D= 0.061250001192092896

TNT Eye Height (keep in mind that this is not used for velocity calculations as tnt is an exception, check out ?explosioncode for more info): (double)0.15F= 0.15000000596046448

Pearl Eye Height: 0.85F*0.25D= 0.21250000596046448

Arrow Eye Height: (double)0.13F= 0.12999999523162842

Player Eye Height (elytra): (double)0.4D= 0.4000000059604645

Llama Eye Height: (double)(0.95F*0.87F)= 1.7764999866485596

Rewritten explosion entity velocity code by intricate:

public Vec3d getVelocityOptimized(Vec3d pos, double eyeHeight, float exposure, boolean tnt) {
    // Get distance from explosion to entity feet
    double distanceNormalized = (double) (pos.distanceTo(this.pos) / (this.power * 2.0F));
    // Exit if distance is too high
    if (distanceNormalized > 1.0D) return new Vec3d(0, 0, 0);
    // Get direction vector, different for tnt for some reason
    Vec3d dir = new Vec3d(pos.x - this.pos.x, (tnt ? pos.y : pos.y + eyeHeight) - this.pos.y, pos.z - this.pos.z);
    // Exit if direction vector is 0
    if(dir.length() == 0.0D) return new Vec3d(0, 0, 0);
    // Normalize direction vector
    dir = dir.multiply(1 / dir.length());
    // Velocity magnitude is (1 - distance/2power) * exposure
    return dir.multiply((1.0D - distanceNormalized) * (double) exposure);
}

https://cdn.discordapp.com/attachments/809608573109403684/879070325172760616/TNT.png

Discord:

https://discord.gg/vPyUBcdmZV

@jan-matula
Copy link

History of TNT compression and Explanation of TNT duplication videos seem to be flipped here.

@pwouik
Copy link
Author

pwouik commented Oct 14, 2021

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment