Guest User

Untitled

a guest
Apr 10th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. package com.turtledove.necropolisofnostalgia.server.ai;
  2.  
  3. import com.google.common.base.Predicates;
  4. import net.minecraft.entity.EntityLiving;
  5. import net.minecraft.entity.ai.EntityAIBase;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.EntityCreature;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.pathfinding.Path;
  10. import net.minecraft.util.EntitySelectors;
  11.  
  12. import net.minecraft.util.math.MathHelper;
  13.  
  14. public class Spiral_DracoChargeTargetAI extends EntityAIBase
  15. {
  16. protected EntityLiving entity;
  17. protected Class <? extends Entity > targetEntity;
  18. protected Entity closestEntity;
  19. private Path path;
  20.  
  21. public boolean isCharging;
  22. protected float maxDistanceForPlayer;
  23. protected final double speed;
  24. protected double x;
  25. protected double y;
  26. protected double z;
  27. protected double overshoot = 2;
  28.  
  29. protected int charge_ticks;
  30. protected int turn_tick;
  31.  
  32. public Spiral_DracoChargeTargetAI(EntityCreature entity, Class<? extends Entity> targetClass, float maxDistance, float speed)
  33. {
  34. this.isCharging = false;
  35. this.entity = entity;
  36. this.targetEntity = targetClass;
  37. this.maxDistanceForPlayer = maxDistance;
  38. this.speed = speed;
  39. charge_ticks = 0;
  40. turn_tick = 0;
  41. this.setMutexBits(1);
  42. }
  43.  
  44. @Override
  45. public boolean shouldExecute()
  46. {
  47. System.out.printf("%d\n",charge_ticks);
  48. if (this.targetEntity == EntityPlayer.class && this.charge_ticks >=100)
  49. {
  50. this.closestEntity = this.entity.world.getClosestPlayer(this.entity.posX, this.entity.posY, this.entity.posZ, (double)this.maxDistanceForPlayer, Predicates.and(EntitySelectors.CAN_AI_TARGET, EntitySelectors.notRiding(this.entity)));
  51. if (this.closestEntity != null)
  52. {
  53. x = this.closestEntity.posX;
  54. y = this.closestEntity.posY;
  55. z = this.closestEntity.posZ;
  56. double f = (double)MathHelper.sqrt(x * x + z * z);
  57. double unit_x = x / f;
  58. double unit_z = z / f;
  59. x += unit_x * overshoot;
  60. z += unit_z * overshoot;
  61. this.entity.getNavigator().tryMoveToXYZ(this.x, this.y, this.z, this.speed);
  62. }
  63. }
  64. ++charge_ticks;
  65. return this.closestEntity != null;
  66. }
  67. public boolean shouldContinueExecuting()
  68. {
  69. ++charge_ticks;
  70. if ((int)this.entity.posX == (int)this.x && (int)this.entity.posZ == (int)this.z)
  71. {
  72. charge_ticks = 0;
  73. turn_tick = 0;
  74. return false;
  75. }
  76. else
  77. {
  78. return true;
  79. }
  80. }
  81. public void resetTask()
  82. {
  83. this.closestEntity = null;
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment