Can't launch projectile?

I’m trying to let a player launch a snowball, however it doesn’t work. I looked at my code and I really can’t find any mistakes.

I have this code:
@Listener public void onRightClick(InteractEvent e, @First Player p ){ ItemStack Hand = p.getItemInHand().orElse(null); TestItem TItem = TestItemSerializer.deserializeTestItem("TItem", main); if(Hand != null){ if(ItemStackComparators.ALL.compare(Hand, TItem.getItemStack()) == 0){ p.sendTitle(Title.of(Text.of("Holding TItem!"))); e.setCancelled(true); logger.info("User is holding a TItem!"); Optional<Snowball> sb = p.launchProjectile(Snowball.class); if(sb.isPresent()){ p.sendTitle(Title.of(Text.of("Shot snowball :'("))); } } } }

however it gives me this error:
Could not pass InteractBlockEvent$Secondary$Impl to Plugin{id=test, name=Test, version=0.01, source=mods\test-0.01.jar} java.lang.IllegalArgumentException: The cause does not have a SpawnCause! It has instead: {} [EntityPlayerMP['Lucurious'/262, l='world', x=-89.53, y=70.00, z=257.40]

1 Like

Can we see the full error, and which line it refers to. This is possibly a bug in sponge, I’ve seen this before when dropping items.

I thought so too…
Here’s my server log:

It’s definitely Sponge:

java.lang.IllegalArgumentException: The cause does not have a SpawnCause! It has instead: {} [EntityPlayerMP['Lucurious'/262, l='world', x=-89.61, y=70.00, z=257.36]]
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:148) ~[minecraft_server.1.8.9.jar:?]
    at org.spongepowered.common.event.SpongeCommonEventFactory.checkSpawnEvent(SpongeCommonEventFactory.java:696) ~[SpongeCommonEventFactory.class:1.8.9-4.1.0-BETA-263]
    at org.spongepowered.common.entity.projectile.ProjectileLauncher.doLaunch(ProjectileLauncher.java:237) ~[ProjectileLauncher.class:1.8.9-4.1.0-BETA-263]
    at org.spongepowered.common.entity.projectile.ProjectileLauncher.access$200(ProjectileLauncher.java:88) ~[ProjectileLauncher.class:1.8.9-4.1.0-BETA-263]
    at org.spongepowered.common.entity.projectile.ProjectileLauncher$4.createProjectile(ProjectileLauncher.java:321) ~[ProjectileLauncher$4.class:1.8.9-4.1.0-BETA-263]
    at org.spongepowered.common.entity.projectile.ProjectileLauncher$SimpleEntityLaunchLogic.launch(ProjectileLauncher.java:121) ~[ProjectileLauncher$SimpleEntityLaunchLogic.class:1.8.9-4.1.0-BETA-263]
    at org.spongepowered.common.entity.projectile.ProjectileLauncher$SimpleItemLaunchLogic.launch(ProjectileLauncher.java:166) ~[ProjectileLauncher$SimpleItemLaunchLogic.class:1.8.9-4.1.0-BETA-263]
    at org.spongepowered.common.entity.projectile.ProjectileLauncher.launch(ProjectileLauncher.java:178) ~[ProjectileLauncher.class:1.8.9-4.1.0-BETA-263]
    at net.minecraft.entity.player.EntityPlayerMP.launchProjectile(SourceFile:54) ~[lf.class:?]
    at nu.apiary.Main.Events.CheckTItemUse.onRightClick(CheckTItemUse.java:48) ~[CheckTItemUse.class:?]
    at org.spongepowered.common.event.listener.InteractEventListener_CheckTItemUse_onRightClick5.handle(Unknown Source) ~[?:?]
    at org.spongepowered.common.event.RegisteredListener.handle(RegisteredListener.java:86) ~[RegisteredListener.class:1.8.9-4.1.0-BETA-263]
    at org.spongepowered.common.event.SpongeEventManager.post(SpongeEventManager.java:258) [SpongeEventManager.class:1.8.9-4.1.0-BETA-263]
    at org.spongepowered.common.event.SpongeEventManager.post(SpongeEventManager.java:269) [SpongeEventManager.class:1.8.9-4.1.0-BETA-263]
    at org.spongepowered.common.SpongeImpl.postEvent(SpongeImpl.java:130) [SpongeImpl.class:1.8.9-4.1.0-BETA-263]
    at net.minecraft.network.NetHandlerPlayServer.redirect$tryUseItem$0(SourceFile:144) [lm.class:?]
    at net.minecraft.network.NetHandlerPlayServer.func_147346_a(SourceFile:503) [lm.class:?]
    at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.func_148833_a(SourceFile:59) [ja.class:?]
    at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.func_148833_a(SourceFile:10) [ja.class:?]
    at org.spongepowered.common.network.PacketUtil.onProcessPacket(PacketUtil.java:106) [PacketUtil.class:1.8.9-4.1.0-BETA-263]
    at net.minecraft.network.PacketThreadUtil$1.redirect$onProcessPacket$0(SourceFile:51) [fh$1.class:?]
    at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) [fh$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_74]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_74]
    at net.minecraft.util.Util.func_181617_a(SourceFile:44) [g.class:?]
    at net.minecraft.server.MinecraftServer.func_71190_q(SourceFile:143) [MinecraftServer.class:?]
    at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(SourceFile:299) [ko.class:?]
    at net.minecraft.server.MinecraftServer.func_71217_p(SourceFile:535) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.run(SourceFile:451) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_74]

If you look, the root methods are:

at com.google.common.base.Preconditions.checkArgument(Preconditions.java:148) ~[minecraft_server.1.8.9.jar:?]
at org.spongepowered.common.event.SpongeCommonEventFactory.checkSpawnEvent(SpongeCommonEventFactory.java:696) ~[SpongeCommonEventFactory.class:1.8.9-4.1.0-BETA-263]
at org.spongepowered.common.entity.projectile.ProjectileLauncher.doLaunch(ProjectileLauncher.java:237) ~[ProjectileLauncher.class:1.8.9-4.1.0-BETA-263]

I think what’s happening is SpawnCause has changed, especially in the API and part of the event factory, but hasn’t yet been fully updated in the implementation. I’d suggest posting this as a bug on github.

Try to set the Shooter:

p.launchProjectile(Snowball.class).get().setShooter(p);

Maybe this make the SpawnCause to player!

Hello, i have the same problem, … i have this code:

Optional<Snowball> snowball = p.launchProjectile(Snowball.class);
snowball.get().setShooter(p);

but i have the same error at the first line.
how can i launch the projectile without a bug?
thx

You can wait until Sponge is updated…

it will not being solved scratic, if you see this post

  • “Refactor SpawnCause for proper implementation, provides abstract SpawnCauses for plugin extension”

i don’t know if it is a bug or if there is an other way

Of course it will be solved…

This means its updated in the API, the problem is in the implementation, where it is not updated (all the way) to the new API requirements. It is a bug, there is an issue open on github, and it will be fixed eventually.

There is an open issue for this. It will be fixed when someone gets round to it.
https://github.com/SpongePowered/SpongeAPI/issues/1135