Skip to content

Commit

Permalink
Allow fireballs to be precise when shot (#1110)
Browse files Browse the repository at this point in the history
Signed-off-by: Pugzy <[email protected]>
  • Loading branch information
Pugzy authored Dec 13, 2022
1 parent 61c13f7 commit 073f52d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,7 +30,8 @@ public ProjectileDefinition(
List<PotionEffect> potion,
Filter destroyFilter,
Duration coolDown,
boolean throwable) {
boolean throwable,
boolean precise) {
super(id);
this.name = name;
this.damage = damage;
Expand All @@ -40,6 +42,7 @@ public ProjectileDefinition(
this.destroyFilter = destroyFilter;
this.coolDown = coolDown;
this.throwable = throwable;
this.precise = precise;
}

public @Nullable String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions util/src/main/java/tc/oc/pgm/util/nms/NMSHacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 073f52d

Please sign in to comment.