From fdbedf0ae9695d92dfd1a40830164debf5c53c6c Mon Sep 17 00:00:00 2001 From: Pugzy Date: Mon, 28 Nov 2022 18:29:02 +0000 Subject: [PATCH] Allow fireballs to be precise when shot Signed-off-by: Pugzy --- .../java/tc/oc/pgm/projectile/ProjectileDefinition.java | 5 ++++- .../java/tc/oc/pgm/projectile/ProjectileMatchModule.java | 5 +++++ .../main/java/tc/oc/pgm/projectile/ProjectileModule.java | 4 +++- util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/projectile/ProjectileDefinition.java b/core/src/main/java/tc/oc/pgm/projectile/ProjectileDefinition.java index c0f914831d..5925152643 100644 --- a/core/src/main/java/tc/oc/pgm/projectile/ProjectileDefinition.java +++ b/core/src/main/java/tc/oc/pgm/projectile/ProjectileDefinition.java @@ -18,6 +18,7 @@ public class ProjectileDefinition extends SelfIdentifyingFeatureDefinition { protected Filter destroyFilter; protected Duration coolDown; protected boolean throwable; + protected boolean precise; public ProjectileDefinition( @Nullable String id, @@ -29,7 +30,8 @@ public ProjectileDefinition( List potion, Filter destroyFilter, Duration coolDown, - boolean throwable) { + boolean throwable, + boolean precise) { super(id); this.name = name; this.damage = damage; @@ -40,6 +42,7 @@ public ProjectileDefinition( this.destroyFilter = destroyFilter; this.coolDown = coolDown; this.throwable = throwable; + this.precise = precise; } public @Nullable String getName() { diff --git a/core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java b/core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java index 790c0160d7..7e36734688 100644 --- a/core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/projectile/ProjectileMatchModule.java @@ -7,6 +7,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Entity; +import org.bukkit.entity.Fireball; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; @@ -40,6 +41,7 @@ import tc.oc.pgm.filters.query.PlayerBlockQuery; import tc.oc.pgm.kits.tag.ItemTags; import tc.oc.pgm.util.bukkit.MetadataUtils; +import tc.oc.pgm.util.nms.NMSHacks; @ListenerScope(MatchScope.RUNNING) public class ProjectileMatchModule implements MatchModule, Listener { @@ -92,6 +94,9 @@ && isValidProjectileAction(event.getAction(), projectileDefinition.clickAction)) projectile = player.launchProjectile( projectileDefinition.projectile.asSubclass(Projectile.class), velocity); + if (projectile instanceof Fireball && projectileDefinition.precise) { + NMSHacks.setFireballDirection((Fireball) projectile, velocity); + } } else { projectile = player.getWorld().spawn(player.getEyeLocation(), projectileDefinition.projectile); diff --git a/core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java b/core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java index f31dfc4dce..89a2a39f08 100644 --- a/core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java +++ b/core/src/main/java/tc/oc/pgm/projectile/ProjectileModule.java @@ -69,6 +69,7 @@ public ProjectileModule parse(MapFactory factory, Logger logger, Document doc) Duration coolDown = XMLUtils.parseDuration(projectileElement.getAttribute("cooldown")); boolean throwable = XMLUtils.parseBoolean(projectileElement.getAttribute("throwable"), true); + boolean precise = XMLUtils.parseBoolean(projectileElement.getAttribute("precise"), true); ProjectileDefinition projectileDefinition = new ProjectileDefinition( @@ -81,7 +82,8 @@ public ProjectileModule parse(MapFactory factory, Logger logger, Document doc) potionKit, destroyFilter, coolDown, - throwable); + throwable, + precise); factory.getFeatures().addFeature(projectileElement, projectileDefinition); projectileModule.projectileDefinitions.add(projectileDefinition); diff --git a/util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java b/util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java index e65cb96396..0cdebd8091 100644 --- a/util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java +++ b/util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java @@ -1379,4 +1379,11 @@ static void freezeEntity(Entity entity) { tag.setBoolean("NoGravity", true); nmsEntity.f(tag); // load from tag } + + static void setFireballDirection(Fireball entity, Vector direction) { + EntityFireball fireball = ((CraftFireball) entity).getHandle(); + fireball.dirX = direction.getX() * 0.1D; + fireball.dirY = direction.getY() * 0.1D; + fireball.dirZ = direction.getZ() * 0.1D; + } }