From 372d52a6db9665e283ba2c561caa2aa6813c3760 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 4 Sep 2013 17:09:56 +0300 Subject: [PATCH] Improve projectile velocity calculation. --- .../denizen/scripts/commands/entity/ShootCommand.java | 8 +++++--- .../java/net/aufdemrand/denizen/utilities/Velocity.java | 7 ++++--- .../net/aufdemrand/denizen/utilities/entity/Gravity.java | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/ShootCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/ShootCommand.java index 1700116b19..e019163cc5 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/ShootCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/ShootCommand.java @@ -147,7 +147,7 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept aH.debugObj("destination", destination) + aH.debugObj("height", height) + aH.debugObj("gravity", gravity) + - (script != null ? aH.debugObj("script", script) : "")); + (script != null ? aH.debugObj("script", script.identify()) : "")); // Keep a dList of entities that can be called using %shot_entities% // later in the script queue @@ -188,7 +188,9 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept Position.mount(Conversion.convert(entities)); - // Only use the last projectile in the task below + // Get the entity at the bottom of the entity list, because + // only its gravity should be affected and tracked considering + // that the other entities will be mounted on it final dEntity lastEntity = entities.get(entities.size() - 1); @@ -244,7 +246,7 @@ else if (lastVelocity != null) { } } - // Stop the task and and run the script if conditions + // Stop the task and run the script if conditions // are met if (!flying) { diff --git a/src/main/java/net/aufdemrand/denizen/utilities/Velocity.java b/src/main/java/net/aufdemrand/denizen/utilities/Velocity.java index cafdd61105..e8a78267a7 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/Velocity.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/Velocity.java @@ -7,7 +7,8 @@ public class Velocity { /** * Calculates the vector between two locations' vectors * - * Thanks to SethBling. + * Original code by SethBling, edited to be a bit + * more accurate. * * @param from The origin's vector * @param to The destination's vector @@ -31,9 +32,9 @@ public static Vector calculate(Vector from, Vector to, double gravity, double he double c = -endGain; double slope = -b / (2 * a) - Math.sqrt(b * b - 4 * a * c) / (2 * a); - + // Vertical velocity - double vy = Math.sqrt(maxGain * gravity); + double vy = Math.sqrt(maxGain * (gravity + 0.0013675090252708 * heightGain)); // Horizontal velocity double vh = vy / slope; diff --git a/src/main/java/net/aufdemrand/denizen/utilities/entity/Gravity.java b/src/main/java/net/aufdemrand/denizen/utilities/entity/Gravity.java index 649abdd31b..b42dc0ead8 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/entity/Gravity.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/entity/Gravity.java @@ -6,13 +6,13 @@ public enum Gravity { EXPERIENCE_ORB("XPOrb", 0.115), LEASH_HITCH("LeashKnot", 0.115), PAINTING("Painting", 0.115), - ARROW("Arrow", 0.115), - SNOWBALL("Snowball", 0.075), + ARROW("Arrow", 0.118), + SNOWBALL("Snowball", 0.076), FIREBALL("Fireball", 0.115), SMALL_FIREBALL("SmallFireball", 0.115), ENDER_PEARL("ThrownEnderpearl", 0.115), ENDER_SIGNAL("EyeOfEnderSignal", 0.115), - THROWN_EXP_BOTTLE("ThrownExpBottle", 0.115), + THROWN_EXP_BOTTLE("ThrownExpBottle", 0.157), ITEM_FRAME("ItemFrame", 0.115), WITHER_SKULL("WitherSkull", 0.115), PRIMED_TNT("PrimedTnt", 0.115), @@ -56,7 +56,7 @@ public enum Gravity { VILLAGER("Villager", 0.115), ENDER_CRYSTAL("EnderCrystal", 0.115), SPLASH_POTION(null, 0.115), - EGG(null, 0.115), + EGG(null, 0.074), FISHING_HOOK(null, 0.115), LIGHTNING(null, 0.115), WEATHER(null, 0.115),