Solved Freeze certain entity

Discussion in 'Plugin Development' started by EpicCraft21, Mar 24, 2015.

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

    EpicCraft21

    Is there any way to freeze an entity's movement. For example a pig?

    Code:
    //like this
    Public void onMove(//Some event here, help here!){
    Entity e = event.getEntity();
    event.setCancelled(true);
    }
    
    But how do I make only a specific spawned entity frozen, not ALL entities?
     
  2. Offline

    sgavster

    @EpicCraft21 When you spawn the entity(You could use CreatureSpawnEvent, get the CreatureType) and add a potion effect. (Slowness.) Any questions, just ask. :)
     
  3. Offline

    EpicCraft21

    Thanks, that sounds like a good idea, but is there any way to completely freeze?
     
  4. Offline

    sgavster

    @EpicCraft21 What do you mean? Like, so it can't move or so it can't hit? It really depens on what you mean by freeze :p
     
  5. Offline

    EpicCraft21

    Oh, sorry, I should have been more specific. It would be preferred for both attack and move, but all I really need is the movement to be cancelled.
     
  6. Offline

    sgavster

    @EpicCraft21 Well, I would use slowness to cancel the movement. If you wanted to, you could put some tag on the mob (I'm not sure how you would put a custom 'tag' on the mob, I mean to tell it apart from the others) or you could put it in an ArrayList I think. You could check EntityDamageByEntityEvent, if the damager has the custom tag or arraylist, cancel it? Let me know if that was confusing. I'm not very good at explaining.
     
  7. Offline

    EpicCraft21

    I just thought up of a way to do this. I can get the spawned entity and get its location, and use a loop to constantly teleport it to that location. So while the entity is not in the location, teleport it back. Thanks for your help though!
     
  8. Offline

    sgavster

    @EpicCraft21 Great idea! Glad you figured it out. Sorry for being confusing :p
     
  9. Offline

    EpicCraft21

    And for others in case they need this as well:
    Code:
    Location loc = entity.getLocation();//this is the location on spawn
    while(Entity.getLocation() != loc){
    teleport(entity, loc);
    }
    Note that this is not the exact code.
     
    sgavster likes this.
Thread Status:
Not open for further replies.

Share This Page