[LIB] MCShot - A Custom Realistic Projectile Library

Discussion in 'Resources' started by Jnorr44, Oct 10, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    (see below to get it!)

    MCShot allows the customization of a launched physical but invisible projectile across the MC world. Typically, a developer would simply create a line, and iterate over locations in that line to detect a hit on an entity. MCShot has a few advantages over the aforementioned. MCShot is much faster, has many more comprehensive settings, and doesn't require a bunch of code to run every ~.1 block.

    Create a hit box (see "What is a hit box?" below):
    1. Location center = new Location(WORLD, X, Y, Z, YAW, PITCH);//center of the hit box
    2. float yawRotation = 90F;//the yaw of the hit box, which causes the box to instantiate at an angle
    3. HitBox hitBox = new HitBox(center, LENGTH, WIDTH, HEIGHT, yawRotation);

    Add a data zone (see "What is a data zone?" below) to that hit box:
    1. double damageMultiplier = 1D;//the amount that you may later want to use to multiply your damage by
    2. double thickness = .5D;//the amount that you may later want to use to remove penetration from your projectile
    3. DataZone zone = new DataZone(.25F, .75F, 0F, 1F, .75F, 2F, damageMultiplier, thickness);//float arguments are a distance from the hit box origin
    4. hitBox.addDataZone(zone);

    Create your projectile:
    1. ShotData data = new Realistic308ShotData();
    2. //Realistic308ShotData is provided for you, although you can easily create your own by implementing ShotData

    (see below to create your own)

    Shoot your projectile:
    1. Location from = player.getLocation();//or any other location you want the shot to originate from
    2. List<HitBox> hitBoxes = new ArrayList<HitBox>();
    3. hitBoxes.add(hitBox);
    4. List<Hit> hits = new Shot(from, data).shoot(hitBoxes);

    Create your own projectile:
    1. public class MyShotData implements ShotData {
    2. @Override public float getWindSpeedMPH(World world) {
    3. return 5F;
    4. }
    6. @Override public float getWindCompassDirection(World world) {
    7. return 90F;
    8. }
    10. @Override public double getDistanceToTravel() {
    11. return 30;
    12. }
    14. @Override public double getStartingPenetration() {
    15. return 30;
    16. }
    18. @Override public double getPenetration(double current, double distance) {
    19. return current - (distance / 2);
    20. }
    22. @Override public double getDamage(double distance) {
    23. return 5 * ((30 - distance) * .01);
    24. }
    26. @Override public float getSpeedBPS(double distance) {
    27. return 200;
    28. }
    30. @Override public double getDeltaX(double distance, float originalYaw) {
    31. return 2;
    32. }
    34. @Override public double getDeltaY(double distance, float originalPitch) {
    35. return 2;
    36. }
    38. @Override public double getDeltaZ(double distance, float originalYaw) {
    39. return 5;
    40. }
    41. }

    Creating a hit box that will hit an entity/player:
    1. EntityHitBox hitBox = new EntityHitBox(ENTITY, LENGTH, WIDTH, HEIGHT);
    2. hitBox.update();//moves the box with the entity; automatically called by Shot.shoot();

    >>>GET MCSHOT <<<
    Also be sure to check out MCPath, a custom A* pathfinding library.​
    What is a hit box? (open)

    The outer transparent (with black border) box is the hit box, which rotates freely around the world. The inner boxes are data zones, which hold information such as damage multipliers (maybe hitting a mod in the head is 2x damage), speed reduction (how much speed the projectile loses as it hits this data zone), and other useful information. Think of it as a cuboid container for a bunch of smaller cuboids.
    What is a data zone? (open)
    The inner boxes of a hit box are called data zones. While to hit box may be moving around, rotating, or just standing still, the data zones are in their same position inside the hit box. They are there to return back damage, speed loss, and other data to the user once a projectile is shot.
    stirante, mkremins and Skyost like this.
  2. Offline


    Skyost likes this.
  3. Offline



    also; I don't quite understand the "hit box"'s. Would this be applicable in detecting entity collision?
  4. Offline


    Still having trouble with eGit. Will push soon in all probability.

    EDIT: Just did!
    The hit boxes are basically just an area surrounding the data zones used for proportioning and movement. Like a rectangular prism surrounding a mob, while the data zones would be the head and the body. Perhaps the head would have a x2 multiplier, which would be specified in a data zone. The hit boxes are necessary for the shot to actually work mathematically. You can think of them like containers in a way.
    user_43347 likes this.
  5. Offline


    Great job James, this looks nice and will definitely come in handy sometime.
    Jnorr44 likes this.
  6. Offline


    Some people were having trouble with shooting players and mobs, so I added EntityHitBox. You just pass an Entity to it, and it will update with the location and yaw on its own. You can also make your own by extending HitBox and overriding the update() method, but I figured this would make things easier on new developers. I will add a guide in the main post.
  7. Offline


  8. Offline


    Yes, it doesn't have anything to do with entities, only locations. The EntityHitBox class is the only exception, which isn't even required. That class was just made as a provision for those who don't know how to extend classes :D.
  9. Offline


    @OP: Are there any videos of what people have developed with this? It's actually caught my eye, curious as to how it reacts with the factors you said ingame.
  10. Offline


    No not yet. It's really new, and still has some issues that I am working out.
  11. Offline


    I'd love to see it in action, when you get a chance.
  12. Offline


    Updated! MCShot should now work as intended (although may still not be perfect). Also, Shot now contained the getClosest(List<HitBox> hitBoxes) and arrangeClosest(List<HitBox> hitBoxes) methods, useful for hitting the closest hit box first. There are also static versions of these methods provided in Shot.
    Also, hit boxes now require length width and height, and no longer require origin. This should be easier, although you will have to find entity dimensions to make an entity hit box. The previous methods I used turned out not to work as intended, and gave entities hit boxes with 0 height. Until I find a way to get entity dimensions accurately and in a way that will not break, you will have to provide your own dimensions.
  13. i really like that lib and think about using it in my guns plugin soon , can you show us some examples for codes? (simple code :p)
  14. Offline


    Updated! MCShot can now tell if you hit the target! (haha) However, I need to do a bit more work to be able to figure out where the entrance and exit locations are. Look forward to that update in the future, or create a PR to see it sooner. I am actually struggling to find a fix.
Thread Status:
Not open for further replies.

Share This Page