Solved Stop loop for mob replacing

Discussion in 'Plugin Development' started by drThunderbuckle, Dec 18, 2020.

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

    drThunderbuckle

    I have been creating my first plugin, and I ran into a problem that I don't know how to fix (I am still very new to coding). I want to make it so, for example, all creepers in the world will be replaced with zombies when they spawn, or all cows will be replaced with blazes etc., but I noticed that if I change all creepers to zombies, but have all zombies change to skeletons, the creepers will also change to skeletons. here is my code.
    Code:
    public void creatureSpawn(CreatureSpawnEvent Event) {
           
            if (Event.getEntityType() == EntityType.CREEPER)
            {
                Creeper creeper = (Creeper) Event.getEntity();
                Location Loc = creeper.getLocation();
                World w = creeper.getWorld();
                w.spawnEntity(Loc, EntityType.ZOMBIE);
                creeper.remove();           
               
            }
           
            if (Event.getEntityType() == EntityType.ZOMBIE)
            {
                Zombie zombie = (Zombie) Event.getEntity();
                Location Loc = zombie.getLocation();
                World w = zombie.getWorld();
                w.spawnEntity(Loc, EntityType.SKELETON);
                zombie.remove();
            }
           
           
        }
    How do I make the creeper stay a zombie, and not turn into a skeleton? I plan on randomizing all 72 mobs, so this will cause all of them to go in a chain and all wind up turning into the same mob. I was thinking of making it damage the new mob by half a heart, and only change mobs if their health is at full, but I don't know if this is the best way of handling the problem. Once again, any help would be appreciated (I don't need you to write the code for me, just point me in the right direction) and I am sorry if I missed something obvious, because I am very very new to coding.
     
  2. Offline

    CraftCreeper6

    @drThunderbuckle
    Store the entity returned from w.spawnEntity in a list, when CreatureSpawnEvent runs, check if the entity is in that list, if it is, cancel the event, remove the entity from the list.
     
  3. Offline

    drThunderbuckle

    Ok. I think I might just need more experience with Java. Thanks for the help though.
     
    Last edited: Dec 18, 2020
  4. Offline

    bowlerguy66

    You can get the spawn reason from CreatureSpawnEvent, no need to store entities
     
    drThunderbuckle likes this.
  5. Offline

    drThunderbuckle

    Thank you! That worked!
     
    bowlerguy66 likes this.
Thread Status:
Not open for further replies.

Share This Page