Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

About Mobs

Comments in 'Plugin Development' started by JackboyPlay, Jul 11, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Hi, how can I make that I cant slide mobs?
  2. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    PHP:
    $mobpos = new Vector3(xyz);
    $mob //mobobject
    public function onMove(PlayerMoveEvent $event){
    $p $event->getPlayer();
    if(!
    in_array($mob$p->getLevel()->getEntities()) return;
    foreach(
    $p->getLevel()->getEntities() as $e){

    if(
    $mob === $e){
    if(
    $mobpos != $e->getPosition()) $e->teleport($mobpos);
    }
    }}
    JackboyPlay likes this.
  3. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    You can't prevent mobs from sliding, because mobs don't slide at all. It is only client-side. You just need to resend the entity positions.
    You don't need to be at the exactly same position as the mob. Due to the nature of double precision floating points, it is basically impossible that two entities are at the same place unless you teleport them together. You should use the AxisAlignedBB methods from Entity::getBoundingBox().

    You only want to prevent collision with $mob, but you handle a PlayerMoveEvent, and then you check all entities in that level rather than only that player. What's the sense of using $p then?

    Just respawn the entity whenever collision with player is detected.
    PHP:
    public function onMove(PlayerMoveEvent $event){
      
    $player $event->getPlayer();
      
    // provided: $mob the mob that is moved
      
    if($player->getBoundingBox()->intersectsWith($mob)){
        
    $mob->despawnFrom($player);
        
    $mob->spawnTo($player);
      }
    }
    BalAnce likes this.

Share This Page

Advertisement