Tutorial How to set custom entity to unmovable && unpushable!

Discussion in 'Resources' started by Reynergodoy, Oct 21, 2015.

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

    Reynergodoy

    Hi guys, I'm here to share a thing that I found :)
    I don't know if someone shared it before me, but there are people that don't know about this, they say you need to set the entity to it's location every second.
    But instead, let's do this-

    :
    We have to set a simple entity ->
    Code:
          public static void stafflist(Player player){
            Villager stafflisting = (Villager) player.getLocation().getWorld().spawn(player.getLocation(), Villager.class);
            stafflisting.setCustomName("§5§l<§4§k|||§5§l<§2§k|||§5§l<§4§k|||§5§l<§2§k|||§5§l<§6Staff List§5§l>§2§k|||§5§l>§4§k|||§5§l>§2§k|||§5§l>§4§k|||§5§l>");
            stafflisting.setCustomNameVisible(true);

    :
    We set the entity to passenger of itself ->
    Code:
            stafflisting.setPassenger(stafflisting);
    It won't move or be pushed anymore!

    : (EDIT - IT MEANS THAT I FOUND THIS ANOTHER LITTLE TRICK AFTER POSTING THIS THREAD)
    We have to remove the entity if it is killed, when we set the entity to its own passenger, the entity will bug if killed, normal players won't be able to see.
    But if your server hasn't got a good host, players who enter the game, might see this little bug, of entities being killed and vanishing in smoke.
    What can I do then?
    Remove the entity on the death event
    Code:
        @EventHandler
        public void onPlayerKillEntity(EntityDeathEvent e) {
            if(e.getEntity() instanceof Villager){
                  Entity mob = e.getEntity();
               if(mob.getCustomName()!=null){
              mob.remove();
           }
            }
        }
    ( Observation: Don't worry about these weird positioned braces("}") ok :) )
    What this does?
    It removes the entity that does have custom name ( !=null ), the "null" means the normal villagers without name ( So, this event does not apply to them ).
    And the villagers with names like "The Savior" or "Bob" ( just examples ( but these examples work as well)) will vanish without leaving a trace of smoke and won't die again every time a new player enters.

    Final code:
    Code:
          public static void stafflist(Player player){
            Villager stafflisting = (Villager) player.getLocation().getWorld().spawn(player.getLocation(), Villager.class);
            stafflisting.setCustomName("§5§l<§4§k|||§5§l<§2§k|||§5§l<§4§k|||§5§l<§2§k|||§5§l<§6Staff List§5§l>§2§k|||§5§l>§4§k|||§5§l>§2§k|||§5§l>§4§k|||§5§l>");
            stafflisting.setCustomNameVisible(true);
            stafflisting.setPassenger(stafflisting);
    @EventHandler
        public void onPlayerKillEntity(EntityDeathEvent e) {
            if(e.getEntity() instanceof Villager){
                  Entity mob = e.getEntity();
               if(mob.getCustomName()!=null){
              mob.remove();
           }
            }
        }
     
    Last edited by a moderator: Oct 23, 2015
  2. Offline

    mcdorli

    You messed up the code in your signature
     
  3. Offline

    FabeGabeMC

    *OCD Alert* Ch.......aaaa....tttt....Coolll....or..... *Television feedback noise*
    The tape ends there.
    bruh
     
  4. Offline

    Reynergodoy

    i know that :)
     
  5. Offline

    Reynergodoy

    Fixed a "bug" created by using the x.setPassenger(x);
    Updated the Final Code
     
  6. Offline

    ChipDev

    Some glitches have happened in the past with this, I don't find this that reliable.
    I would use my old thread, or NMS (I used wither skulls, just like sethbling.)
     
  7. Offline

    Reynergodoy

    what "glitches"?
     
  8. Offline

    ChipDev

    Well, I mean some more unknown things. sorry :p
    EDIT: Meaning like servers have crashed with errors on who the passenger is, etc. Confusing; memory leaks?
     
  9. Offline

    FabeGabeMC

    Why not just use a Silverfish instead? (It's way smaller.)
    Or possibly an item or snowball/projectile/eye of ender?
    *cue the Jeopardy think music.*
     
    ChipDev likes this.
  10. Offline

    Hawktasard

    @FabeGabeMC
    I'm pretty sure wither skulls don't get rendered if they're not moving.
     
    ChipDev likes this.
  11. Offline

    ChipDev

    True, my old thread still works :D #Witherskulls. I forgot the name though .-.
     
  12. Offline

    Reynergodoy

    how can i check if a server has memory leaks due to a specific plugin?
     
  13. Offline

    ChipDev

    Check the console.
     
  14. Offline

    Reynergodoy

    Are they these: Server can't keep up...
    ?
     
  15. Offline

    ChipDev

    Yep.
     
  16. Offline

    Reynergodoy

    oh, i though it was just because of the small amount of RAM '-'
    btw i think that 100% of the plugins cause this '-'
     
    ChipDev likes this.
  17. Offline

    ChipDev

    :) Good talk.
     
  18. I found a method that can make an entity unpushable:
    Code:
        @Override
        public void g(double d0, double d1, double d2) {
            return;
        }
    
     
Thread Status:
Not open for further replies.

Share This Page