Spawning Splash Potions

Discussion in 'Plugin Development' started by Codex Arcanum, Nov 14, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Codex Arcanum

    Short, but complicated question. How do you spawn splash potions at a certain point without having to use CraftBukkit?

    Edit:
    Clarification: I want to be able to spawn a thrown splash potion at a certain location with ceratin effects, without having to use anything besides normal Bukkit methods. Meaning, not having to import Craftbukkit and deal with the problems inherent with that.
     
  2. Not sure I understand? Do you mean in vanilla? I don't think that is possible.
     
  3. Offline

    ZeusAllMighty11

    As in apply effects of it? Drop the item? Give an itemstack? Please elaborate.
     
  4. Offline

    Codex Arcanum

    Clarification: I want to be able to spawn a thrown splash potion at a certain location with ceratin effects, without having to use anything besides normal Bukkit methods. Meaning, not having to import Craftbukkit and deal with the problems inherent with that.
     
  5. Offline

    Codex Arcanum

  6. Offline

    wristdirect

    I have an idea for how to do this that involves metadata, lemme try it out and see if it works :)
     
  7. Offline

    fireblast709

    spawn a ThrownPotion entity. Assume World world and Location loc
    Code:java
    1. ThrownPotion potion = (ThrownPotion)world.spawnEntity(loc, EntityType.SPLASH_POTION);
    2. // Now apply whatever to the potion
    3. Collection<PotionEffect>effects = potion.getEffects();
    4. effects.clear();
    5. effects.add(new PotionEffect(whatever));
    6.  

    Untested, excuse me if there is anything wrong :3
     
  8. Offline

    wristdirect

    Sadly this throws an IllegalArgumentException, which seems to be the big problem when trying to do something like this :(
     
  9. Offline

    fireblast709

    what is the error?
     
  10. Offline

    Codex Arcanum

    Code:
     
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    at net.minecraft.server.EntityArrow.j_(EntityArrow.java:202)
    at net.minecraft.server.World.entityJoinedWorld(World.java:1333)
    at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:546)
    at net.minecraft.server.World.playerJoinedWorld(World.java:1315)
    at net.minecraft.server.World.tickEntities(World.java:1193)
    at net.minecraft.server.WorldServer.tickEntities(WorldServer.java:444)
    at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:577)
    at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    Caused by: java.lang.IllegalArgumentException: Cannot spawn an entity for org.bukkit.entity.ThrownPotion
    at org.bukkit.craftbukkit.CraftWorld.spawn(CraftWorld.java:999)
    at org.bukkit.craftbukkit.CraftWorld.spawn(CraftWorld.java:779)
    at org.bukkit.craftbukkit.CraftWorld.spawnEntity(CraftWorld.java:326)
    at me.sleightofmind.alchemicalarrows.listeners.Listener_Entity.onProjectileHit(Listener_Entity.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:339)
    ... 14 more
    
    Happens any time you attempt to spawn a splash potion. Different error appears when you attempt world.spawn(location, ThrownPotion.class).
     
  11. Offline

    fireblast709

    That... is sooooo ugly, CraftBukkit... They never implemented ThrownPotions, but they implemented xp bottles, other projectiles, etc
     
  12. Offline

    Codex Arcanum

    I know, rather obnoxious isn't it? Not sure whether or who to be annoyed at, but this is rather sad. Hopefully wristdirect can figure something out.
     
  13. Offline

    wristdirect

    Sadly I haven't :( I've tried half a dozen ways and they all end up with some sort of exception ><
     
  14. Offline

    Codex Arcanum

    *Dispirited Bump*
     
  15. Offline

    Mathieu Legault

    Did anybody find a way to throw splash potions ? Or is it still not implemented?
     
  16. Offline

    Codex Arcanum

    Nope. Never found a real method, but I did find that you could spawn the image of a potion splashing with world.playEffect() and by getting nearby entities and applying the potion effect to them.
     
  17. Offline

    Mathieu Legault

    Alright, thanks. I'll do it your way then.
     
  18. Offline

    chasechocolate

    I am fairly sure this is possible with Packets. To find out how to spawn a potion, go here, and to see the objects you can spawn, go here.
     
  19. Offline

    fireblast709

    chasechocolate
     
  20. Offline

    chasechocolate

    Oh, thanks, didn't catch that :p
     
  21. Offline

    lolwel21

    Is there a way to get a thrown splash potion entity to have a certain color?
     
  22. Offline

    Omega Haxors

    If you change the little bit of the end of the playeffect line to the potion type you want, it will display that colour. If you want an orange one get the item ID for splash potion of fire res and enter that at the end of playeffect.

    event.getWorld().playEffect(location,effect,Potion ID)
     
  23. Offline

    Eniripsa96

    Sorry to revive an old thread but this is the only one I really found when looking for an answer. I found a way to spawn splash potions with just the Bukkit API though.
    Code:java
    1. // Create a potion type
    2. Potion potion = new Potion(PotionType, int);
    3.  
    4. // Make it a splash potion
    5. potion.setSplash(true);
    6.  
    7. // Set it to an item stack
    8. ItemStack itemStack = new ItemStack(Material.POTION);
    9. potion.apply(itemStack);
    10.  
    11. // Spawn the potion
    12. ThrownPotion thrownPotion = entity.launchProjectile(ThrownPotion.class);
    13. thrownPotion.setItem(itemStack);

    Hopefully this helps someone :)
     
    Tomass, blobic123, NathanWolf and 3 others like this.
  24. Offline

    xTrollxDudex

    Eniripsa96
    Very helpful. But you can't be serious about bumping a month old post.
     
Thread Status:
Not open for further replies.

Share This Page