Advertisement
Guest User

Entity Earth Spike

a guest
Oct 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. public class EntityEarthSpike extends AvatarEntity {
  2.  
  3.  
  4.  
  5. private float damageMult;
  6.  
  7. /**
  8. * @param world
  9. */
  10. public EntityEarthSpike(World world) {
  11. super(world);
  12. setSize(1, 1);
  13. this.damageMult = 1.6F;
  14. }
  15.  
  16. public void setDamageMult(float mult) {
  17. this.damageMult = mult;
  18. }
  19. @Override
  20. protected void readEntityFromNBT(NBTTagCompound nbt) {
  21. super.readEntityFromNBT(nbt);
  22. }
  23.  
  24. @Override
  25. protected void writeEntityToNBT(NBTTagCompound nbt) {
  26. super.writeEntityToNBT(nbt);
  27. setDead();
  28. }
  29.  
  30. @Override
  31. public void onEntityUpdate() {
  32.  
  33. super.onEntityUpdate();
  34.  
  35. setVelocity(Vector.ZERO);
  36.  
  37. if (ticksExisted >= 15) {
  38. this.setDead();
  39. }
  40. // amount of entities which were successfully attacked
  41. int attacked = 0;
  42.  
  43. // Push collided entities back
  44. if (!world.isRemote) {
  45. List<Entity> collided = world.getEntitiesInAABBexcluding(this, getEntityBoundingBox(),
  46. entity -> entity != getOwner());
  47. if (!collided.isEmpty()) {
  48. for (Entity entity : collided) {
  49. if (attackEntity(entity)) {
  50. attacked++;
  51. }
  52. }
  53. }
  54. }
  55.  
  56. if (!world.isRemote && getOwner() != null) {
  57. BendingData data = BendingData.get(getOwner());
  58. if (data != null) {
  59. data.getAbilityData("earthspike").addXp(SKILLS_CONFIG.earthspikeHit * attacked);
  60. }
  61. }
  62.  
  63. }
  64.  
  65. private boolean attackEntity(Entity entity) {
  66.  
  67. if (!(entity instanceof EntityItem && entity.ticksExisted <=
  68. 10) && canCollideWith(entity)) {
  69.  
  70. Vector push = velocity().withY(.8).times(STATS_CONFIG.ravineSettings.push);
  71. entity.addVelocity(push.x(), push.y(), push.z());
  72. AvatarUtils.afterVelocityAdded(entity);
  73.  
  74. DamageSource ds = AvatarDamageSource.causeRavineDamage(entity, getOwner());
  75. float damage = STATS_CONFIG.ravineSettings.damage * damageMult;
  76. return entity.attackEntityFrom(ds, damage);
  77.  
  78.  
  79. }
  80.  
  81. return false;
  82.  
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement