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

Fix Villager

Comments in 'Plugin Development' started by Primus, Jul 16, 2015.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Made my own Coins API and the idea i want is - when player hit Villager it will send popup with how much coins have but i have these problem, with first hit Villager gets damage but only with second time my code works and it cancels the event and send popups, and the second problem... How can i make villager unpushable? And when i join the server the entity jumps in wall xD
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Btw is it possible to make entity move? Cuz $entity->move(); didnt work
  3. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Lol bro been trying to figure out the exact same thing should have talk to me cause i made a coins api too :p
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Did u made Villager too xd?
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $entity->setMotion()
    Sets speed per tick.
  6. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    PHP:
        public function playerInteract(EntityDamageByEntityEvent $ev){
            
    $entity $ev->getEntity();
            if (
    $entity instanceof Entity){
            if (
    $entity instanceof Villager){
                
    $ev->setCancelled(true);
                
    $player $ev->getDamager();
                if (
    $player instanceof Player){
                    
    $pm $this->getServer()->getPluginManager();
                    
    $sc $pm->getPlugin("SimpleTockens");
                    
    $coins $sc->getTockens($player->getName());
                    
    $player->sendMessage(TextFormat::GREEN."[SimpleCoins] You coins are ".$coins);
                }
            }
        }}
    This is the code i used for my api.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The question is about the villager, not the coins...
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    When i do setMotion() it lags xD i used it with timer per second.
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Doesn't It have to be:
    public function playerInteract(EntityDamageEvent $ev){
    ?
    PEMapModder likes this.
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    It could be either event, EntityDamageByEntityEvent just eliminates other damage causes and therefore can cause less lag.
  11. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Also, the way around your problem('s) is to add a Villager Mob packet and that way you can keep track of whenever a player interacts with an Entity and check to see if the Entity has the same ID as the one you added.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    NO.
    EntityDamageByEntityEvent cannot be used as an event handler type because it doesn't have its own handler list. It will use the inherited one from EntityDamageEvent, and all EntityDamageEvent will be handled. But since you type-hinted, it will fail with errors.
    CrazedMiner likes this.
  13. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    So it's just a child of EntityDamageEvent?
  14. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    I guess
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, and you shouldn't hook to it
    CrazedMiner likes this.
  16. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Soo is there any way to make the villager look at player when is in 5 block radius?
    PEMapModder likes this.
  17. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Like in MinePlex PC?
    @PEMapModder so add a if($ev instanceof EntityBlahBlahBlahEvent){
    PEMapModder likes this.
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes. Just open the source PHP file for the event. If you don't see public static $handlerList in that class, you shouldn't hook to it.

Share This Page

Advertisement