Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. public class ElectricBallEntity extends DamagingProjectileEntity {
  2. private static final DataParameter<Float> BALL_SIZE = EntityDataManager.createKey(ElectricBallEntity.class, DataSerializers.FLOAT);
  3. private double charge;
  4.  
  5. public ElectricBallEntity(EntityType<? extends ElectricBallEntity> p_i50173_1_, World p_i50173_2_) {
  6. super(p_i50173_1_, p_i50173_2_);
  7. }
  8.  
  9. public ElectricBallEntity(World worldIn, LivingEntity shooter, double accelX, double accelY, double accelZ, double charge) {
  10. super(ModEntityType.electric_ball_entity, shooter, accelX, accelY, accelZ, worldIn);
  11. this.charge = charge;
  12. float size = MathHelper.clamp((float)(charge/2), 1, 2);
  13. System.out.println(size);
  14. this.setBallSize((int)(size));
  15. }
  16.  
  17. public void tick() {
  18. super.tick();
  19. System.out.println(this.getBallSize());
  20. }
  21.  
  22. /** Impact effect */
  23. @Override
  24. protected void onImpact(RayTraceResult result) {
  25. if (!this.world.isRemote()) {
  26. if (result.getType() == RayTraceResult.Type.ENTITY) {
  27. Entity entity = ((EntityRayTraceResult)result).getEntity();
  28. entity.attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity)this.shootingEntity).setDamageBypassesArmor(), 6F * (float)this.charge);
  29. }
  30. else {
  31. this.remove();
  32. }
  33. }
  34. }
  35.  
  36. public float getBallSize() {
  37. return this.dataManager.get(BALL_SIZE);
  38. }
  39.  
  40. public void setBallSize(float size) {
  41. this.dataManager.set(BALL_SIZE, size);
  42. this.setPosition(this.posX, this.posY, this.posZ);
  43. this.recalculateSize();
  44. }
  45.  
  46. public EntitySize getSize(Pose poseIn) {
  47. return super.getSize(poseIn).scale(this.getBallSize());
  48. }
  49.  
  50. @Override
  51. protected float getMotionFactor() {
  52. return 1F;
  53. }
  54.  
  55. @Override
  56. public boolean isBurning() {
  57. return false;
  58. }
  59.  
  60. protected boolean isFireballFiery() {
  61. return false;
  62. }
  63.  
  64. protected IParticleData getParticle() {
  65. return ModParticleTypes.electric_spark;
  66. }
  67.  
  68. /**
  69. * Returns true if other Entities should be prevented from moving through this Entity.
  70. */
  71. public boolean canBeCollidedWith() {
  72. return false;
  73. }
  74.  
  75. /**
  76. * Called when the entity is attacked.
  77. */
  78. public boolean attackEntityFrom(DamageSource source, float amount) {
  79. return false;
  80. }
  81.  
  82. protected void registerData() {
  83. this.dataManager.register(BALL_SIZE, 1F);
  84. super.registerData();
  85. }
  86.  
  87. public void writeAdditional(CompoundNBT compound) {
  88. super.writeAdditional(compound);
  89. compound.putFloat("Size", this.getBallSize());
  90. }
  91.  
  92. /**
  93. * Protected helper method to read subclass entity data from NBT.
  94. */
  95. public void readAdditional(CompoundNBT compound) {
  96. super.readAdditional(compound);
  97. float i = compound.getFloat("Size");
  98. this.setBallSize(i);
  99. }
  100.  
  101. public void notifyDataManagerChange(DataParameter<?> key) {
  102. if (BALL_SIZE.equals(key)) {
  103. this.recalculateSize();
  104. }
  105. super.notifyDataManagerChange(key);
  106. }
  107.  
  108. @Override
  109. public IPacket<?> createSpawnPacket()
  110. {
  111. return NetworkHooks.getEntitySpawningPacket(this);
  112. }
  113.  
  114. public static ElectricBallEntity spawnOnClient(FMLPlayMessages.SpawnEntity spawnPacket, World world) {
  115. return new ElectricBallEntity(ModEntityType.electric_ball_entity, world);
  116. }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement