Solved Despawn entity

Discussion in 'Plugin Development' started by Jbluesword, Mar 2, 2016.

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

    Jbluesword

    I am a new dev learning to build basic plugins step by step, I been working on a customTp plugin. I ran into the issue where i need the entity(bat) to despawn when the player is away from the entity in certain amount of blocks. I have tried different methods but they seem to work, or I am not doing it correctly.

    Code:
    if (!(from.getWorld().equals(to.getWorld())) || (from.distanceSquared(to) >= Config.minParticleDistanceSquared)) {
                       
                    spawnSmoke(from, 5);
                    spawnSmoke(from.add(0,1,0), 5);
                    from.getWorld().playEffect(from, Effect.MOBSPAWNER_FLAMES, null);
                    from.getWorld().spawnEntity(from, EntityType.BAT);
                    from.getWorld().spawnEntity(from, EntityType.BAT);
                    from.getWorld().spawnEntity(from, EntityType.BAT);
                    from.getWorld().spawnEntity(from, EntityType.BAT);
                   
                    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                        @Override
                        public void run() {
                            for (int i = 0; i<3 ; i++) {
                                spawnSmoke(to, 5);
                                spawnSmoke(to.add(0,1,0), 5);
                                to.getWorld().playEffect(to, Effect.MOBSPAWNER_FLAMES, null);
                                to.getWorld().spawnEntity(to, EntityType.BAT);
                                to.getWorld().spawnEntity(to, EntityType.BAT);
                                to.getWorld().spawnEntity(to, EntityType.BAT);
                                to.getWorld().spawnEntity(to, EntityType.BAT);
                               
                               
                            }
                        }
                    }, 1L);
                }
            }
        }
    I have fixed the plugin to be able to work with 1.9 minecraft
    Thank you for the assistance a head of time.
     
  2. as far as i know you can call the method "remove()" of the bat and it should vanish then. so there are multiple ways to go now.

    1. track player movement and check the distance to the bats. if the distance is huge enough, call remove
    2. run a timer and remove all bats after a specific amount of time
    3. remove the bats after your animation is done

    for way 1 and 2 you d have to save the bats you spawn into a Set<LivingEntity> or smth, since you won't be able to access the bats after the time or movement. if you do it tricky enough, you can do it without the set when using a timeter tho, too. id recommend the playermovement maybe in combination with a timer since the bats wont be removed if the player wont move away from them.
     
  3. Offline

    Jbluesword

    Alright, thank you so much for your assistance ^.^
     
Thread Status:
Not open for further replies.

Share This Page