Solved Strike lightning without sound

Discussion in 'Plugin Development' started by jojodmo, Feb 9, 2014.

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

    jojodmo

    I would like to strike lightning at a location without sound... My code is:

    Code:java
    1. EntityLightning el = new EntityLightning(((CraftWorld) Bukkit.getWorld(p.getWorld().getName())).getHandle(), loc1.getX(), loc1.getY(), loc1.getZ(), true);
    2. PacketPlayOutSpawnEntityWeather packet = new PacketPlayOutSpawnEntityWeather(el);
    3. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);


    As the only way you can do this is with packets, I'm pretty sure. Anyways, how could I make the lightning strike without the sound? Thanks!
     
  2. Offline

    Commander9292

    jojodmo2010 I may be wrong but I believe that the sound of the lightning is handled by the client.
     
  3. Offline

    jojodmo

    I found this on https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/EntityLightning.java:

    Code:java
    1. if (this.lifeTicks == 2) {
    2. this.world.makeSound(this.locX, this.locY, this.locZ, "ambient.weather.thunder", 10000.0F, 0.8F + this.random.nextFloat() * 0.2F);
    3. this.world.makeSound(this.locX, this.locY, this.locZ, "random.explode", 2.0F, 0.5F + this.random.nextFloat() * 0.2F);
    4. }

    Wouldn't that mean theres a way to change it?
     
  4. Offline

    Commander9292

    jojodmo2010 Ehh I believe you could create a CustomEntityLightning class and override the h() method, as that is where it appears to play the sounds.
     
  5. Offline

    jojodmo

    Okay, I would have to make it so that only certain times it doesn't play the sound... I'll try that.
     
  6. Offline

    xTrollxDudex

    jojodmo2010
    You wouldn't need to completely make a new Entity in this case, just use world.addEntity(...) on a new instance of your class that overrides EntityLightning.
     
  7. Offline

    Commander9292

  8. Offline

    jojodmo

    Will that make it so that theres no sound?

    That makes it so that you don't see the lightning, but you still hear the sound...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  9. Offline

    xTrollxDudex

  10. Offline

    jojodmo

    Sorry, but how exactly would I override it? :p
     
  11. Offline

    xTrollxDudex

    jojodmo2010
    Extend the class and mirror the constructor
    PHP:
    PacketPlayOutSpawnEntityWeather packet = new PacketSpawnEntityWeather(/* New entity here */);
    (
    CraftPlayerp).getHandle().playerConnection.sendPacket(packet);
     
  12. Offline

    jojodmo


    Did it, and it still wont work... My custom lightning class:

    Code:java
    1. public class CustomEntityLightning extends EntityWeather{
    2.  
    3.  
    4. private int lifeTicks;
    5. public long a;
    6. private int c;
    7.  
    8. public CustomEntityLightning(World world, double d0, double d1, double d2) {
    9. super(world);
    10. this.setPositionRotation(d0, d1, d2, 0.0F, 0.0F);
    11. this.lifeTicks = 2;
    12. this.a = this.random.nextLong();
    13. this.c = this.random.nextInt(3) + 1;
    14. }
    15.  
    16. @SuppressWarnings("rawtypes")
    17. public void h() {
    18. super.h();
    19.  
    20. --this.lifeTicks;
    21. if (this.lifeTicks < 0) {
    22. if (this.c == 0) {
    23. this.die();
    24. } else if (this.lifeTicks < -this.random.nextInt(10)) {
    25. --this.c;
    26. this.lifeTicks = 1;
    27. this.a = this.random.nextLong();
    28. }
    29. }
    30.  
    31. if (this.lifeTicks >= 0) {
    32. if (this.world.isStatic) {
    33. this.world.q = 2;
    34. } else {
    35. double d0 = 3.0D;
    36. List list = this.world.getEntities(this, AxisAlignedBB.a().a(this.locX - d0, this.locY - d0, this.locZ - d0, this.locX + d0, this.locY + 6.0D + d0, this.locZ + d0));
    37.  
    38. for (int l = 0; l < list.size(); ++l) {
    39. Entity entity = (Entity) list.get(l);
    40.  
    41. entity.a(this, G);
    42. }
    43. }
    44. }
    45. }
    46.  
    47. protected void c() {}
    48.  
    49. protected void a(NBTTagCompound nbttagcompound) {}
    50.  
    51. protected void b(NBTTagCompound nbttagcompound) {}
    52. }
    53.  


    Then to make the lightning I use:

    Code:java
    1. CustomEntityLightning el = new CustomEntityLightning((World) Bukkit.getWorld(p.getWorld().toString()), loc4.getX(), loc4.getY(), loc4.getZ());
    2. PacketPlayOutSpawnEntityWeather packet = new PacketPlayOutSpawnEntityWeather(el);
    3. ((CraftPlayer) ply).getHandle().playerConnection.sendPacket(packet);


    It still won't show the lightning, and I get no errors in console
     
  13. Offline

    xTrollxDudex

    jojodmo2010
    You're supposed to extend EntityLightning...
     
  14. Offline

    jojodmo


    Whoops :p, Now I'm getting a nullPointer

    PHP:
    Caused byjava.lang.NullPointerException
    >      at net.minecraft.server.v1_7_R1.EntityLightning.<init>(EntityLightning.java:35) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    >      
    at net.minecraft.server.v1_7_R1.EntityLightning.<init>(EntityLightning.java:17) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    >      
    at plugin.CustomEntityLightning.<init>(CustomEntityLightning.java:23) ~[?:?]
    >      
    at plugin.makeLightning(Magic.java:336) ~[?:?]
    Line 23 of CustomEntityLightning is:

    Code:java
    1. super(world, d0, d1, d2);


    in:

    Code:java
    1. public CustomEntityLightning(World world, double d0, double d1, double d2) {
    2. super(world, d0, d1, d2); //line 23
    3. this.setPositionRotation(d0, d1, d2, 0.0F, 0.0F);
    4. this.lifeTicks = 2;
    5. this.a = this.random.nextLong();
    6. this.c = this.random.nextInt(3) + 1;
    7. }


    When I create it, I use


    CustomEntityLightning el = new CustomEntityLightning((World) Bukkit.getWorld(p.getWorld().toString()), loc9.getX(), loc9.getY(), loc9.getZ()); //using just p.getWorld() doesn't seem to work, and it throws an exception.
     
  15. Offline

    tylersyme

    jojodmo2010
    This is because you have to use a CraftWorld, not a bukkit World

    Code:
    net.minecraft.server.v1_7_R1.World nmsWorld = ((CraftWorld) player.getLocation().getWorld()).getHandle();
    CustomEntityLightning el = new CustomEntityLightning(nmsWorld, loc9.getX(), loc9.getY(), loc9.getZ());
    
    Remember, you're working with NMS (net.minecraft.server), meaning that bukkit code won't work in most cases :)
     
  16. Offline

    jojodmo



    Wow, can't believe I missed that. Although it doesn't damage mobs or mobs now, I'll just set their fire ticks and damage them when they get struck by this lightning. Anyways, thanks!
     
Thread Status:
Not open for further replies.

Share This Page