Allowing spiders to attack in daylight

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

Thread Status:
Not open for further replies.
  1. Hello. I am trying to be able to spawn spiders that attack in daylight. I know this is possible, but I just don't know how to achieve this.

    I currently have this, but I am pretty sure it's not going to work:

    Code:
    package me.HeyAwesomePeople.kitpvp.custommobs;
    
    import me.HeyAwesomePeople.kitpvp.KitPVP;
    import net.minecraft.server.v1_8_R2.EntitySpider;
    import net.minecraft.server.v1_8_R2.GenericAttributes;
    import net.minecraft.server.v1_8_R2.PathfinderGoalHurtByTarget;
    import net.minecraft.server.v1_8_R2.World;
    
    import org.bukkit.entity.Player;
    
    public class AgroSpider extends EntitySpider {
        private KitPVP plugin = KitPVP.instance;
        private Player toIgnore;
    
        public AgroSpider(World world, Player p) {
            super(world);
            this.toIgnore = p;
          
            this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true, new Class[0]));
        }
    
        @Override
        protected void initAttributes() {
            super.initAttributes();
            getAttributeInstance(GenericAttributes.maxHealth).setValue(20.0D);
        }
    
    
    
    }
    I'm new to NMS and still don't know how to use it properly. I also don't know how I am supposed to read method a() and find out what it does. Is there like a document or something somewhere I can go to figure out how do edit the NMS. It seems others do it easily.

    Thanks,
    HeyAwesomePeople

    EDIT: Someone suggested I do this, with no NMS:

    Code:
      @EventHandler
       public void onEvent(PlayerMoveEvent event) {
        
         for(Entity e : event.getPlayer().getNearbyEntities(15, 15, 15)) { //Replace '15' with the radius you want the spiders to attack you
          
           if(e instanceof Spider) {
            
             if(((Spider) e).getTarget() == null && event.getPlayer().getGameMode() != GameMode.CREATIVE && event.getPlayer().getGameMode() != GameMode.SPECTATOR) {
            
               ((Spider) e).setTarget(event.getPlayer());
            
             } else if(((Spider) e).getTarget() == event.getPlayer() && (event.getPlayer().getGameMode() == GameMode.CREATIVE || event.getPlayer().getGameMode() == GameMode.SPECTATOR)) {
              
               ((Spider) e).setTarget(null);
              
             }
              
           }
          
         }
        
       }
    But I would think that would effect server performance if 100 people are online, constantly checking a 15 wide area for spiders?
     
  2. @HeyAwesomePeople
    Well, I think you shall do it the nms way.
    1 important thing: You`re forgeting to register that entity.
    And I think you should check if there`s any target Selectors that cancells entity targeting when it`s day, if there`s one, you should delete it.
     
  3. @Juancomaster1998 I know I have to register the entity, but how do I know which selector controls whether or not the spider should attack in the daytime or not?
     
Thread Status:
Not open for further replies.

Share This Page