NMS how to make villagers attack selected players.

Discussion in 'Plugin Development' started by deivisxm, Jan 24, 2014.

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

    deivisxm

    Hi. Currently im learning to use nsm to controll mobs. I want that each spawned villager would attack selected player on command, like /attack (player name) but could someone please explain me how to modify villager class so they could actually attack? I want them to be melee and some of them ranged
     
  2. Offline

    L33m4n123

  3. Offline

    bennie3211

  4. Offline

    xTrollxDudex

    deivisxm
    Add pathfinders in the entity constructor.
     
  5. Offline

    deivisxm

    Well i know that tutorial but there i only saw how to change damage, or make zombies to not attack villagers, instead attack skeletons. Could someone atleast give me a sample code of making villagers attack something?
     
  6. Offline

    xTrollxDudex

    deivisxm
    Again, add the pathfinders to the class. Preferably, take a look at EntityCreeper and see what pathfinders cause it to attack players.
     
  7. Offline

    deivisxm

    Ok thanks. So wait... I only need to change pathfindings so they would attack? And this is offtopic, but how would i summon modified mobs and not make every mob in a world modified?
     
  8. Offline

    RawCode

    You can get everything you need from creeper and ocelot classes.

    If you override mobs all mobs will be modded, if you replace AI for specific mobs - only specific mobs will be special.
     
  9. Offline

    deivisxm

    Ok. But again about the villager class... How can i modify ai for specific profession villager?


    Hello im having a problem. I made villagers pathfinding similar to zombies but villagers just stand still and dont do anything. Could someone explain me what am i doing wrong?
    Code:java
    1. /*
    2. * To change this template, choose Tools | Templates
    3. * and open the template in the editor.
    4. */
    5. package com.gmail.blazer;
    6.  
    7. import java.lang.reflect.Field;
    8. import net.minecraft.server.v1_7_R1.EntityCow;
    9. import net.minecraft.server.v1_7_R1.EntityVillager;
    10. import net.minecraft.server.v1_7_R1.GenericAttributes;
    11. import net.minecraft.server.v1_7_R1.PathfinderGoalBreakDoor;
    12. import net.minecraft.server.v1_7_R1.PathfinderGoalFloat;
    13. import net.minecraft.server.v1_7_R1.PathfinderGoalHurtByTarget;
    14. import net.minecraft.server.v1_7_R1.PathfinderGoalInteract;
    15. import net.minecraft.server.v1_7_R1.PathfinderGoalLookAtPlayer;
    16. import net.minecraft.server.v1_7_R1.PathfinderGoalMeleeAttack;
    17. import net.minecraft.server.v1_7_R1.PathfinderGoalMoveIndoors;
    18. import net.minecraft.server.v1_7_R1.PathfinderGoalMoveTowardsRestriction;
    19. import net.minecraft.server.v1_7_R1.PathfinderGoalNearestAttackableTarget;
    20. import net.minecraft.server.v1_7_R1.PathfinderGoalRandomLookaround;
    21. import net.minecraft.server.v1_7_R1.PathfinderGoalRandomStroll;
    22. import net.minecraft.server.v1_7_R1.PathfinderGoalSelector;
    23. import net.minecraft.server.v1_7_R1.World;
    24. import org.bukkit.craftbukkit.v1_7_R1.util.UnsafeList;
    25.  
    26. /**
    27. *
    28. * @author User
    29. */
    30. public class CustomEntityVillager extends EntityVillager{
    31. /**
    32. *
    33. * @param world
    34. */
    35. public CustomEntityVillager(World world) {
    36. super(world);
    37. try {
    38. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    39. bField.setAccessible(true);
    40. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    41. cField.setAccessible(true);
    42. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    43. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    44. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    45. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    46. }
    47.  
    48. }
    49. public CustomEntityVillager(World world,int i) {
    50. super(world);
    51.  
    52.  
    53. this.goalSelector.a(0, new PathfinderGoalFloat(this));
    54. this.goalSelector.a(1, new PathfinderGoalBreakDoor(this));
    55. this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityCow.class, 1.0D, true));
    56. this.goalSelector.a(4, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
    57. this.goalSelector.a(6, new PathfinderGoalRandomStroll(this, 1.0D));
    58. this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityCow.class, 8.0F));
    59. this.goalSelector.a(7, new PathfinderGoalRandomLookaround(this));
    60. this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
    61. this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityCow.class, 0, true));
    62. this.goalSelector.a(2, new PathfinderGoalMoveIndoors(this));
    63. this.goalSelector.a(9, new PathfinderGoalInteract(this, EntityCow.class, 3.0F, 1.0F));
    64. }
    65.  
    66. @Override
    67. protected void aD() {
    68. super.aD();
    69. this.getAttributeInstance(GenericAttributes.b).setValue(20.0D);
    70. this.getAttributeInstance(GenericAttributes.d).setValue(0.23000000417232513D);
    71.  
    72.  
    73. }
    74. }
    75.  

    New problem... Fixed that one but how would i set villager damage?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  10. Offline

    bennie3211

    You have to set the attribute's for it, but im not sure you can make it so a village can damage a player, because you edit the entity's behaviour, and im not sure if he has a melee attack xd
     
  11. Offline

    deivisxm

    I set the pathfinders. Its not the same as atributes? Also how wild boars did it then?
     
  12. Offline

    deivisxm

    Bump

    Ok if no one cant help me with nms, maybe someone could explain me how to get mob, villager is looking at and deal him damage?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  13. Offline

    Jnorr44

  14. Offline

    deivisxm

    Thank you so much!!! So i dont need nms?
    Edit:
    looked up your plugin. Cant understand how to make villagers do damage with pathfinding
     
Thread Status:
Not open for further replies.

Share This Page