Solved How I can make a Fireball invisible?

Discussion in 'Plugin Development' started by Stephanech, Feb 23, 2017.

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

    Stephanech

    Well, I'm trying to make a "Magical Attack System", it works with fireballs and particles (I only use the fireball to guide the particles, make damage and get a killer and a killed more easily):

    Code:java
    1.  
    2. //I put this here because I think it'll be useful
    3.  
    4.  
    5. Location loc = player.getEyeLocation().toVector()
    6. .add(player.getLocation().getDirection().multiply(13)).toLocation(player.getWorld(),
    7. player.getLocation().getYaw(), player.getLocation().getPitch());
    8. //Creating a location based on the angle wich the player is facing, and it'll "skip" some blocks
    9.  
    10.  
    11.  
    12. Fireball fireball = player.getWorld().spawn(loc, Fireball.class); //Spawning the Fireball
    13. Vector vel = fireball.getDirection(); //Getting a direction/velocity vector
    14. fireball.setBounce(false);
    15.  
    16. fireball.setVelocity(vel.multiply(9)); //Setting a velocity for the fireball, it looks glitchy
    17. fireball.setDirection(vel.multiply(9)); // Correcting the fireball so it doesn't looks so glitchy
    18.  
    19. fireball.setShooter(player); //Setting the shooter to the player, so I can call it later and know what player killed another entity
    20.  
    21.  
    22.  
    23. // . . . Particle's code using ParticleEffects Library by DarkBlade12
    24.  
    25.  


    It looks well, but, there's a thing: The Fireball is still visible and it "ruins" the look of the attack

    There aren't methods for making the Fireball invisible, like addPotionEffect or something like that

    If anyone know a way for making the Fireball invisible, I would appreciate some help :)
     
  2. Offline

    Zombie_Striker

    @Stephanech
    Well, this does not mean you need to use fireballs.

    Use Schedulers and a final, normalized vector and location to have a location move in the direction you are looking. Every time the scheduler runs, check if there is a player/entity within 0.7M of the location. If so, you got the "killed" player. If not, add the normalized vector to the location. This achieves the same thing as the fireball. Also, you want to store the "shooter" if you want to keep the killer.

    If you still want to use fireballs though, you will need to use ProtocolLib to send the destroy entity packet. The player will no longer see the fireball, but it will exist.
     
  3. Offline

    mine2012craft

  4. Offline

    Stephanech

    @Zombie_Striker @mine2012craft

    I think those are better ways to create what I want, but I already coded all this system and implemented it in most of the plugin (It's not just the code of the top, I created classes, voids and maps for storing/using information of each attack, attacker and attacked), and I don't want just delete all that work and replace it with the work of someone else (And it'll be more difficult because the Main target for the attacks are EnderDragons, I will need to code more for the complex parts).

    Thanks to both for the help, I'll use ProtocolLib and try to hide the Fireball.
     
  5. Offline

    Zombie_Striker

    @Stephanech
    If your problem has been solved, mark this thread as solved.
     
  6. Offline

    Stephanech

    @Zombie_Striker Sorry, I forgot to do that

    For anyone who wants to hide a entity here's how I solved my problem:

    Obviously, you must download ProtocolLib and put it in the build path of your plugin (External Jar - ProtocolLib.jar)

    Then, I used a class created by another person for hiding entities, but it throwed an error, so I used a modified version of that class, link: https://gist.github.com/gabixdev/b41f175a703ccbf81655
    (If you wanna understand what that class do, you can read the comments in the code and learn)

    Later, you need to create a Private and declare the class for using the methods, you do that in your onEnable()
    And, get the ProtocolManager


    Code:java
    1.  
    2. private ProtocolManager protocolManager;
    3. private EntityHider entityHider;
    4.  
    5. public void onEnable() {
    6. entityHider = new EntityHider(this, Policy.PICK_A_POLICY);
    7.  
    8. //What's a policy? Read the code's comments !
    9.  
    10. protocolManager = ProtocolLibrary.getProtocolManager();
    11.  
    12. }
    13.  


    Then, create a void that you will use for hiding entities

    Code:java
    1.  
    2. void hideEntity(Player p, Entity e) {
    3. entityHider.hideEntity(p, e);
    4. }
    5.  


    You are ready!, just use the void and..

    Code:java
    1.  
    2. hideEntity(player, fireball(or another entity you want));
    3.  
    4. //If you wanna hide the entity from all the players, just loop through getOnlinePlayers()
    5.  
     
    Last edited: Feb 25, 2017
Thread Status:
Not open for further replies.

Share This Page