Setting Entities Around another entity on fire

Discussion in 'Plugin Development' started by iWareWolf, Jun 1, 2014.

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

    iWareWolf

    I'm using:

    Code:java
    1. for (World world : getServer().getWorlds()) {
    2. for (Entity ent : world.getEntities()) {
    3. if (ent.getUniqueId().toString().equals(uuid)) {
    4. for (Entity entity : ent.getNearbyEntities(2, 2, 2)) {
    5. if (entity.getFireTicks() == 0) {
    6. entity.setFireTicks(100);
    7. }
    8. }
    9. }
    10. }
    11. }


    but it is not working.
     
  2. Offline

    JBoss925

    Why on Earth are you using so many nested for loops? I would just straight up do this.

    Code:java
    1. Player p = (Player) e.getEntity();
    2. for(Entity en: p.getNearbyEntities()){
    3. if(en.getFireTicks() == 0){
    4. en.setFireTicks(100);
    5. }
    6. }
     
  3. Offline

    iWareWolf

    JBoss925

    I'm basically making a flame thrower. I made a diamond hoe that shoots out flame item entities. Then I made a repeating task every 1/4 of a second to check entities close to the flame entity and set them on fire.

    Also your code looks like mine. No Change .-.
     
  4. Offline

    JBoss925

    Yes but that's how it's done. Why isn't it working? Do you have a struck trace?
     
  5. Offline

    iWareWolf

    JBoss925

    There is no stracetrace and nothing works. The fire item entity doesn't set all entities around it on fire. Here is full code. The fire entities dissapears after a certain time.

    Code:java
    1. ArrayList<String> newFlameThrower = new ArrayList<>();
    2.  
    3. for (String s : kitManager.flamethrowerProjectile) {
    4. String[] split = s.split("\\|");
    5. String uuid = split[0];
    6. Double time = Double.valueOf(split[1]);
    7. for (World world : getServer().getWorlds()) {
    8. for (Entity ent : world.getEntities()) {
    9. if (ent.getUniqueId().toString().equals(uuid)) {
    10. for (Entity entity : ent.getNearbyEntities(2, 2, 2)) {
    11. if (entity.getFireTicks() == 0) {
    12. entity.setFireTicks(100);
    13. }
    14. }
    15. }
    16. }
    17. }
    18. time -= .25;
    19. if (time != 0) {
    20. newFlameThrower.add(uuid + "|" + time);
    21. } else {
    22. for (World world : getServer().getWorlds()) {
    23. for (Entity ent : world.getEntities()) {
    24. if (ent.getUniqueId().toString().equals(uuid)) {
    25. ent.remove();
    26. }
    27. }
    28. }
    29. }
    30. }
    31.  
    32. kitManager.flamethrowerProjectile.clear();
    33.  
    34. for (String s : newFlameThrower) {
    35. kitManager.flamethrowerProjectile.add(s);
    36. }
     
  6. Offline

    AoH_Ruthless

    iWareWolf
    JBoss925 's code looks a lot better because it doesn't involve nested for loops ... The more for loops you have, the worse the code is and it just looks plain ugly and unnecessary.
     
  7. Offline

    JBoss925

    I'm gonna guess it has something to do with uuid string.
     
  8. Offline

    iWareWolf

    JBoss925

    No getting the entity with UUID is fine since I can remove it but the fire effect is not working.
     
  9. Offline

    JBoss925

    How about instead of checking if their fire ticks are equal to 0, just set their fire ticks to 100. I think the value 0 isn't representative of the number of ticks before they stop being on fire. So either remove the check to see if the fire ticks are equal to 0 or perhaps try checking if the fire ticks are null?
     
  10. Offline

    iWareWolf

    JBoss925

    It works! ;) But I don't want the fire to be unlimited. How can I check if the entity is on fire already?
     
  11. Offline

    Webster56

    getFireTicks() (returns ticks until it is no longer on fire, that means it returns 0 if it's not on fire at all)
     
  12. Offline

    JBoss925

    Code:java
    1. if(ent.getFireTicks() >= 0){
    2. return;
    3. }
     
Thread Status:
Not open for further replies.

Share This Page