HELP PLEASE! Do something on Left Click Entity.

Discussion in 'Plugin Development' started by Juancomaster1998, Mar 16, 2015.

Thread Status:
Not open for further replies.
  1. Hi!
    I`ve a Custom entity, but it`s absolutly invulnerable so entity damage isn`t being called when it`s damaged. So, is there another event that gets fired when someones left clicks the entity? Because I`m doing a custom entity that happens when a player interacts at that entity, PlayerInteractEntity will only be fired on RightClick. Thanks ^^
     
  2. Offline

    SuchSwegMuchWow

    Cycryl likes this.
  3. @SuchSwegMuchWow
    If you mean "EntityDamageByEntityEvent", I said that entity damage isn`t being called, and EntityDamageByEntity extends EntityDamage.
    If you mean "EntityDamagedByEntityEvent", that doesn`t exists.
    Thanks anyway
     
  4. Offline

    SuchSwegMuchWow

  5. @SuchSwegMuchWow
    Code:
    public class EntityDamageByEntity implements Listener {
       
        public EntityDamageByEntity(Plugin pl) {Bukkit.getPluginManager().registerEvents(this, pl);}
       
        @EventHandler
        public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
            if (e.getDamager() instanceof Player) {
                Player p = (Player) e.getDamager();
                if (e.getEntity().getType().equals(EntityType.VILLAGER)) {
                    NMSNpc target = (NMSNpc) ((CraftVillager)e.getEntity()).getHandle();
                    NPCs type = null;
                    boolean bol = false;
                    for (NPCs types : NPCs.values()) {
                        for (NMSNpc entity : NPCs.npcs.get(types).keySet()) if (entity.equals(target)) {
                            type = types;
                            bol = true;
                            break;
                        }
                        if (bol) break;
                    }
                    if (type != null) Bukkit.getPluginManager().callEvent(new NPCInteractEvent(p, Action.LEFT_CLICK, target, type));
                }
            }
        }
    }
    it isn`t being fired.
     
  6. Offline

    mine-care

    Entitydqmagebyentoty should have been called. Anyway on interact event check if three blocks in front of player are air (so he is interacting with air) and check the locations to see if a mob is there, if it is do stuff :)
     
  7. @mine-care
    Well, I supposed it should be called too, but it isn`t.
    Yes, I`d actually done that (with 5 blocks, not with 3). It works but half way. if I click the block the entity is, it won`t fire any event, but if I click the upper block, it will fire player interact.
    So the question is, how do I do to check if the player left clicks the entity block? (Actually just working with the upper block)
     
Thread Status:
Not open for further replies.

Share This Page