[Solved] PotionSplash on Arrow Location

Discussion in 'Spigot Plugin Development' started by Kongolan, May 25, 2015.

  1. Hey there,

    i currently code a plugin, which spawns a splash potion where the arrow hits a wall or other entity like a player. The only problem is, that the harming potion thrown, doesn't apply the damage, it normally does, when i use the arrow location.

    Strange is that it seems that the splash potion just doesn't spawn on the middle of the target hit. Cause normal splash potions have an range amplifier. Though when i check for the PotionSplashEvent it shows and intensity of 1.0, just as it should. But the difference between a normal potion and my spawned potion is still there.

    Code (Text):
    private void createPotionSplash(Arrow arrow, Potion potion) {
            // Make it a splash potion

            // Set it to an item stack
            ItemStack itemStack = new ItemStack(Material.POTION);

            // Spawn the potion
            ThrownPotion thrownPotion = arrow.getShooter().launchProjectile(
            Location spawnIn = arrow.getLocation().clone();
            // spawnIn.setPitch(0);
            // spawnIn.setYaw(0);


        public void onArrowHit(PotionSplashEvent event) {
            for (Entity e : event.getAffectedEntities()) {
                if (e instanceof Player) {
                    Player p = (Player) e;
                    out("healt:", p.getHealth());
                    out("intensity: ", event.getIntensity((LivingEntity) e));

    So what i mainly aim for is a way to teleport the splash potion to a location, which is 2 coordinates (since splash potions have a range of 4) moved to the sight, depending on the vector the arrow has. Sadly my math class is long ago and i can't figure the math for vectors anymore. But the splash potion should hit it's peak and midpoint at the location of the actual hit.

    Can anyone help me on this?
  2. *Bumb*
    Is some vector math really undoable? ;)
  3. you want to teleport it 2 blocks away? why?
  4. Visually it seems like the splash potion isn't splashing with it's peak, where the maximum damage happens. Intensity still shows 1.0 but potion of harming 2 as example does only 2-3 hearts damage, while it should do 5.
  5. So, you want to get 2 blocks far from where the arrow landed. Try it yourself getting the direction of the arrow by using arrow.getLocation().getDirection() , then invert the vector and add it to the arrow location as many times as you want.
  6. I was thinking about that, but i don't know how to invert it and how to play around with it. Can you give me a code example? My math class really is long ago and i didn't do anything with vectors for like 4 years ;)
  7. It's not math, it's logic.
    I made some quick code, test it yourself.
    Well, let's say we have an Arrow object called a1:
    Location loc = a1.getLocation().clone();
    Vector initialVector = loc.getDirection();
    initialVector = initialVector.multiply(-1,-1,-1);
    for(int times = 10; times--; times < 0 ){
    loc it's now your final location.
  8. Try the following:

    Location loc = a1.getLocation().clone();
    Vector initialVector = loc.getDirection();
    initialVector = initialVector.multiply(-1).normalize().multiply(2);

    Location spawnLocation = loc.add(initialVector);


    You got an arrow with a direction.
    .multiply(-1) = invert the direction to go back and not forward
    .normalize() = set the vectors length to 1 to go exactly one block back
    .multiply(2) = to go 2 blocks back, can be replaced with any value
    • Like Like x 1
  9. @Friwi
    Thanks worked perfectly fine :) Only had to use the Arrow Velocity for it, to be more accurate. Also the damage values are a bit higher now, though the Protection IV armor is still inconsistent :/