Zombie NMS

Discussion in 'Plugin Development' started by Jalau, Jan 21, 2014.

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

    Jalau

    I'm modifying the zombie ai and the problem is that the zombies attack like 5 times per second so damage you 5 times per second! So something in this has to affect the attackspeed but i can't find the error :p
    Can you help me?
    Code:java
    1. package me.jalau.mob;
    2.  
    3. import java.util.UUID;
    4. import net.minecraft.server.v1_7_R1.AttributeInstance;
    5. import net.minecraft.server.v1_7_R1.AttributeModifier;
    6. import net.minecraft.server.v1_7_R1.Block;
    7. import net.minecraft.server.v1_7_R1.Blocks;
    8. import net.minecraft.server.v1_7_R1.EntityHuman;
    9. import net.minecraft.server.v1_7_R1.EnumMonsterType;
    10. import net.minecraft.server.v1_7_R1.GenericAttributes;
    11. import net.minecraft.server.v1_7_R1.GroupDataEntity;
    12. import net.minecraft.server.v1_7_R1.IRangedEntity;
    13. import net.minecraft.server.v1_7_R1.MobEffect;
    14. import net.minecraft.server.v1_7_R1.MobEffectList;
    15. import net.minecraft.server.v1_7_R1.NBTTagCompound;
    16. import net.minecraft.server.v1_7_R1.PathfinderGoalArrowAttack;
    17. import net.minecraft.server.v1_7_R1.PathfinderGoalFloat;
    18. import net.minecraft.server.v1_7_R1.PathfinderGoalHurtByTarget;
    19. import net.minecraft.server.v1_7_R1.PathfinderGoalLookAtPlayer;
    20. import net.minecraft.server.v1_7_R1.PathfinderGoalMeleeAttack;
    21. import net.minecraft.server.v1_7_R1.PathfinderGoalMoveTowardsRestriction;
    22. import net.minecraft.server.v1_7_R1.PathfinderGoalNearestAttackableTarget;
    23. import net.minecraft.server.v1_7_R1.PathfinderGoalRandomLookaround;
    24. import net.minecraft.server.v1_7_R1.PathfinderGoalRandomStroll;
    25. import net.minecraft.server.v1_7_R1.World;
    26. import net.minecraft.server.v1_7_R1.WorldServer;
    27.  
    28. import org.bukkit.craftbukkit.v1_7_R1.CraftWorld;
    29. import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftItemStack;
    30.  
    31. public class CustomZombie extends MobBase {
    32.  
    33. private static final UUID bq = UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836");
    34. private static final AttributeModifier br = new AttributeModifier(bq, "Baby speed boost", 0.2D, 1);
    35. private int bt;
    36. private String customType;
    37. private int tier;
    38.  
    39. public CustomZombie(World world, int dropequip) {
    40. this(world, 20F, dropequip);
    41. }
    42.  
    43. public CustomZombie(org.bukkit.World world, String name, int tier, String typemob, float maxHealth, org.bukkit.inventory.ItemStack[] drops, int[] dropC, int[] dropA, int dropequip, org.bukkit.inventory.ItemStack[] equipment) {
    44. this(((CraftWorld)world).getHandle(), maxHealth, dropequip);
    45.  
    46. this.setCustomName(name);
    47.  
    48. this.tier = tier;
    49. this.drops = drops;
    50. this.dropC = dropC;
    51. this.dropA = dropA;
    52. customType = typemob;
    53.  
    54. for(int e = 0; e < equipment.length ;e++) {
    55. this.setEquipment(e, CraftItemStack.asNMSCopy(equipment[e]));
    56. }
    57. }
    58.  
    59. public CustomZombie(World world) {
    60. this(world, 1);
    61. }
    62.  
    63. public CustomZombie(World world, float health, int dropequip) {
    64. super(world, health, dropequip);
    65. this.getNavigation().b(true);
    66. this.goalSelector.a(0, new PathfinderGoalFloat(this));
    67. this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
    68. this.goalSelector.a(4, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
    69. this.goalSelector.a(6, new PathfinderGoalRandomStroll(this, 1.0D));
    70. this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
    71. this.goalSelector.a(7, new PathfinderGoalRandomLookaround(this));
    72. this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
    73. this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
    74. if (this.world != null && !this.world.isStatic) {
    75. AttributeInstance attributeinstance = this.getAttributeInstance(GenericAttributes.d);
    76.  
    77. attributeinstance.b(br);
    78. attributeinstance.a(br);
    79. }
    80. }
    81.  
    82. @Override
    83. protected void aD() {
    84. super.aD();
    85. this.getAttributeInstance(GenericAttributes.b).setValue(40.0D);
    86. this.getAttributeInstance(GenericAttributes.d).setValue(0.23000000417232513D);
    87. this.getAttributeInstance(GenericAttributes.e).setValue(3.0D);
    88. }
    89.  
    90. @Override
    91. protected void c() {
    92. super.c();
    93. this.getDataWatcher().a(12, Byte.valueOf((byte) 0));
    94. this.getDataWatcher().a(13, Byte.valueOf((byte) 0));
    95. this.getDataWatcher().a(14, Byte.valueOf((byte) 0));
    96. }
    97.  
    98. @Override
    99. public int aV() {
    100. int v = super.aV() + 2;
    101.  
    102. if (v > 20) {
    103. v = 20;
    104. }
    105.  
    106. return v;
    107. }
    108.  
    109.  
    110. @Override
    111. protected boolean bk() {
    112. return true;
    113. }
    114.  
    115. @Override
    116. public boolean isBaby() {
    117. return this.getDataWatcher().getByte(12) == 1;
    118. }
    119.  
    120. public void setBaby(boolean flag) {
    121. this.getDataWatcher().watch(12, Byte.valueOf((byte) (flag ? 1 : 0)));
    122. if (this.world != null && !this.world.isStatic) {
    123. AttributeInstance attributeinstance = this.getAttributeInstance(GenericAttributes.d);
    124.  
    125. attributeinstance.b(br);
    126. if (flag) {
    127. attributeinstance.a(br);
    128. }
    129. }
    130. }
    131.  
    132. public boolean isVillager() {
    133. return this.getDataWatcher().getByte(13) == 1;
    134. }
    135.  
    136. public void setVillager(boolean flag) {
    137. this.getDataWatcher().watch(13, Byte.valueOf((byte) (flag ? 1 : 0)));
    138. }
    139.  
    140. @Override
    141. protected String t() {
    142. switch(customType) {
    143. case "Human":
    144. return "";
    145. case "Orc":
    146. return "mob.zombiepig.zpig";
    147. default:
    148. return "mob.zombie.say";
    149. }
    150. }
    151.  
    152. @Override
    153. protected String aT() {
    154. switch(customType) {
    155. case "Human":
    156. return "random.hurt";
    157. case "Orc":
    158. return "mob.zombiepig.zpighurt";
    159. default:
    160. return "mob.zombie.hurt";
    161. }
    162. }
    163.  
    164. @Override
    165. protected String aU() {
    166. switch(customType) {
    167. case "Human":
    168. return "random.hurt";
    169. case "Orc":
    170. return "mob.zombiepig.zpigdeath";
    171. default:
    172. return "mob.zombie.death";
    173. }
    174. }
    175.  
    176. @Override
    177. protected void a(int i, int j, int k, Block block) {
    178. this.makeSound("mob.zombie.step", 0.15F, 1.0F);
    179. }
    180.  
    181. @Override
    182. public EnumMonsterType getMonsterType() {
    183. return EnumMonsterType.UNDEFINED;
    184. }
    185.  
    186. @Override
    187. public void b(NBTTagCompound nbttagcompound) {
    188. super.b(nbttagcompound);
    189. if (this.isBaby()) {
    190. nbttagcompound.setBoolean("IsBaby", true);
    191. }
    192.  
    193. if (this.isVillager()) {
    194. nbttagcompound.setBoolean("IsVillager", true);
    195. }
    196.  
    197. nbttagcompound.setString("customType", this.customType);
    198. nbttagcompound.setInt("dropequipment", this.dropequipment);
    199. }
    200. @Override
    201. public void a(NBTTagCompound nbttagcompound) {
    202. super.a(nbttagcompound);
    203. if (nbttagcompound.getBoolean("IsBaby")) {
    204. this.setBaby(true);
    205. }
    206.  
    207. if (nbttagcompound.getBoolean("IsVillager")) {
    208. this.setVillager(true);
    209. }
    210.  
    211.  
    212. this.customType = nbttagcompound.getString("customType");
    213. this.dropequipment = nbttagcompound.getInt("dropequipment");
    214. }
    215. @Override
    216. public GroupDataEntity a(GroupDataEntity groupdataentity) {
    217. Object object = super.a(groupdataentity);
    218. float v = this.world.b(this.locX, this.locY, this.locZ);
    219.  
    220. this.h(this.random.nextFloat() < 0.55F * v);
    221. if (object == null) {
    222. object = new GroupDataZombie(this, this.world.random.nextFloat() < 0.05F, this.world.random.nextFloat() < 0.05F, (EmptyClass4) null);
    223. }
    224.  
    225. if (object instanceof GroupDataZombie) {
    226. GroupDataZombie groupdatazombie = (GroupDataZombie) object;
    227.  
    228. if (groupdatazombie.b) {
    229. this.setVillager(true);
    230. }
    231.  
    232. if (groupdatazombie.a) {
    233. this.setBaby(true);
    234. }
    235. }
    236.  
    237. this.bA();
    238. this.bB();
    239.  
    240. return (GroupDataEntity) object;
    241. }
    242.  
    243. protected void a(int i)
    244. {
    245. this.bt = i;
    246. getDataWatcher().watch(14, Byte.valueOf((byte)1));
    247. m(MobEffectList.WEAKNESS.id);
    248. addEffect(new MobEffect(MobEffectList.INCREASE_DAMAGE.id, i, Math.min(this.world.difficulty.a() - 1, 0)));
    249. this.world.broadcastEntityEffect(this, (byte)16);
    250. }
    251.  
    252. @Override
    253. protected boolean isTypeNotPersistent() {
    254. return !this.ca();
    255. }
    256.  
    257. public boolean ca() {
    258. return this.getDataWatcher().getByte(14) == 1;
    259. }
    260.  
    261.  
    262. protected int cc() {
    263. int i = 1;
    264.  
    265. if (this.random.nextFloat() < 0.01F) {
    266. int j = 0;
    267.  
    268. for (int k = (int)this.locX - 4; (k < (int)this.locX + 4) && (j < 14); k++) {
    269. for (int l = (int)this.locY - 4; (l < (int)this.locY + 4) && (j < 14); l++) {
    270. for (int i1 = (int)this.locZ - 4; (i1 < (int)this.locZ + 4) && (j < 14); i1++) {
    271. Block block = this.world.getType(k, l, i1);
    272.  
    273. if ((block == Blocks.IRON_FENCE) || (block == Blocks.BED)) {
    274. if (this.random.nextFloat() < 0.3F) {
    275. i++;
    276. }
    277.  
    278. j++;
    279. }
    280. }
    281. }
    282. }
    283. }
    284.  
    285. return i;
    286. }
    287. }
    288.  
     
  2. Offline

    Jalau

    Bump! ;=)
     
  3. Offline

    Deleted user

    Jalau
    Umm

    Do you want to just limit the amount of zombies spawning?
     
  4. Offline

    Jalau

    zombiekiller753
    I'm modifying the zombie ai and the problem is that the zombies attack like 5 times per second so damage you 5 times per second! So something in this has to affect the attackspeed but i can't find the error :p
     
  5. Offline

    Deleted user

    Jalau
    Wait.
    So you want the zombies to attack 5 times per second? Or you don't want to, but they are because of something you did?
     
  6. Offline

    Jalau

    Bump, help is apreciated ;)
     
  7. Offline

    Mathias Eklund

    You could make a cool down for the attacks.
     
  8. Offline

    Jalau

    Mathias Eklund
    Vanilla Zombies simply aren't doing that so why are mine doing that? :D :D Also if i would know where the attack speed is set i would change it!

    Bump.... :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page