Shoot snowball?

Hello, i want to shoot an snowball in front of player, but i don’t know how can i do this?
do you have some idea?

(and a fireball on the future plz)

1 Like

Both Snowballs and Fireballs are Projectiles in the API.
Player is a ProjectileSource and has the method launchProjectile

It would look something like this:

Optional<Snowball> optSnowball = player.launchProjectile(Snowball.class);

i have an error, i think it’s not implemented yet…
[15:52:59] [Server thread/ERROR] [Sponge]: Could not pass InteractBlockEvent$Sec
ondary$Impl to SpongePlugin:MyPluin{1.0}
java.lang.AbstractMethodError: Method net/minecraft/entity/player/EntityPlayerMP
.launchProjectile(Ljava/lang/Class;)Ljava/util/Optional; is abstract
at net.minecraft.entity.player.EntityPlayerMP.launchProjectile(EntityPla ~[qw.class:?]
at be.thesebakl.multiserve.MyPlugin.Main.oninteract(
at org.spongepowered.common.event.listener.InteractEventListener_Main_on
interact8.handle(Unknown Source) ~[?:?]
at org.spongepowered.common.event.RegisteredListener.handle(RegisteredLi ~[RegisteredListener.class:1.8-1568-2.1-DEV-833]
at [SpongeModEventManager.class:1.8-1568-2.1-DEV-833]
at [SpongeModEventManager.class:1.8-1568-2.1-DEV-833]
at [SpongeModEventManager.class:1.8-1568-2.1-DEV-833]
at [SpongeModEventManager.class:1.8-1568-2.1-DEV-833]
at org.spongepowered.common.Sponge.postEvent( [
at net.minecraftforge.event.ForgeEventFactory.onPlayerInteract(ForgeEven [ForgeEventFactory.class:?]
at [rj.class:?]
180769_a(SourceFile:59) [mx.class:?]
148833_a(SourceFile:10) [mx.class:?]
3) [ih.class:?]
at$ [ih.class
at java.util.concurrent.Executors$ Source) [
at Source) [?:1.8.0_60]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHa [FMLCommonHandler.class:?]
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.jav
a:656) [MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(Dedicated [po.class:?]
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.jav
a:598) [MinecraftServer.class:?]
at [M
at Source) [?:1.8.0_60]

You are correct, I had implemented this but it’s not in the master branch yet

Depending on your setup it may be possible to checkout to the branch feature/projectilesource to get the implementation if you need it.

oki, but how can i do??? i explain you
i want do an event who launch the projectile with shooter is the player,
and if the snowball touch an another player (another event), i want to get the shooter of the snowball, and the victim, and damage him (a gun)

how can i do it?

Projectile launching is now implemented so you can test it.

For your question, there’s a few things going on there.
To make a player shoot a snowball, it’s simply:

Player thePlayer = getThePlayer(); // Whatever
Optional<Snowball> snowball = thePlayer.launchProjectile(Snowball.class);

To make the snowball damage the player, listen to CollideEntityEvent and inspect the entities that are colliding.

1 Like

thx, but can i choose the speed? i want the snowball go fast
and if i can choose an another vector?

Yes, the launchProjectile takes a second argument called velocity

oki thx, but can you help me for the event? how can i get if there is an collision with a player and a snowball?
i have to do event.getCause.first(snowball.class) pour la classe et event.getCause.firste(player.class) pour le joeuur.
i’m no sure…

Something like this:

public void onEntityCollide(CollideEntityEvent event) {
    Optional<Snowball> optSnowball = event.getCause().first(Snowball.class);
    if (!optSnowball.isPresent()) {
    Snowball snowball = optSnowball.get();
    for (Entity entity : event.getEntities()) {
        if (entity instanceof Player) {
            Player player = (Player) entity;
            System.out.println(player + " hit by " + snowball);

Yes, chute door.