Guest User

Untitled

a guest
Apr 25th, 2018
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. package com.TheRPGAdventurer.ROTD.client.render;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.TheRPGAdventurer.ROTD.server.entity.helper.breath.BreathNode;
  6. import com.TheRPGAdventurer.ROTD.util.breath.EntityMoveAndResizeHelper;
  7. import com.TheRPGAdventurer.ROTD.util.breath.RotatingQuad;
  8.  
  9. import net.minecraft.client.Minecraft;
  10. import net.minecraft.client.renderer.BufferBuilder;
  11. import net.minecraft.client.renderer.texture.TextureAtlasSprite;
  12. import net.minecraft.entity.Entity;
  13. import net.minecraft.entity.MoverType;
  14. import net.minecraft.nbt.NBTTagCompound;
  15. import net.minecraft.util.EnumParticleTypes;
  16. import net.minecraft.util.ResourceLocation;
  17. import net.minecraft.util.math.Vec3d;
  18. import net.minecraft.world.World;
  19.  
  20. /**
  21. * Created by TGG on 21/06/2015.
  22. * EntityFX that makes up the flame breath weapon; client side.
  23. *
  24. * Usage:
  25. * (1) create a new FlameBreathFX using createFlameBreathFX
  26. * (2) spawn it as per normal
  27. *
  28. */
  29. public class FlameBreathFX extends Entity {
  30.  
  31. private final float SMOKE_CHANCE = 0.1f;
  32. private final float LARGE_SMOKE_CHANCE = 0.3f;
  33.  
  34. private static final float MAX_ALPHA = 0.99F;
  35. public float particleScale;
  36. private BreathNode breathNode;
  37.  
  38. private FlameBreathFX(World world, double x, double y, double z, Vec3d motion,
  39. BreathNode i_breathNode) {
  40. super(world);
  41.  
  42. breathNode = i_breathNode;
  43. this.setPosition(x, y, z);
  44. this.particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F;
  45.  
  46. //undo random velocity variation of vanilla EntityFX constructor
  47. motionX = motion.x;
  48. motionY = motion.y;
  49. motionZ = motion.z;
  50.  
  51. entityMoveAndResizeHelper = new EntityMoveAndResizeHelper(this);
  52. }
  53.  
  54. /** call once per tick to update the EntityFX size, position, collisions, etc
  55. */
  56. @Override
  57. public void onUpdate() {
  58. final float YOUNG_AGE = 0.25F;
  59. final float OLD_AGE = 0.75F;
  60.  
  61. float lifetimeFraction = breathNode.getLifetimeFraction();
  62.  
  63. final float PARTICLE_SCALE_RELATIVE_TO_SIZE = 5.0F; // factor to convert from particleSize to particleScale
  64. float currentParticleSize = breathNode.getCurrentRenderDiameter();
  65. particleScale = PARTICLE_SCALE_RELATIVE_TO_SIZE * currentParticleSize;
  66.  
  67. // spawn a smoke trail after some time
  68. if (SMOKE_CHANCE != 0 && rand.nextFloat() < lifetimeFraction && rand.nextFloat() <= SMOKE_CHANCE) {
  69. world.spawnParticle(getSmokeParticleID(), posX, posY, posZ, motionX * 0.5, motionY * 0.5, motionZ * 0.5);
  70. }
  71.  
  72. // smoke / steam when hitting water. node is responsible for aging to death
  73. if (handleWaterMovement()) {
  74. world.spawnParticle(getSmokeParticleID(), posX, posY, posZ, 0, 0, 0);
  75. }
  76.  
  77. float newAABBDiameter = breathNode.getCurrentAABBcollisionSize();
  78.  
  79. prevPosX = posX;
  80. prevPosY = posY;
  81. prevPosZ = posZ;
  82. entityMoveAndResizeHelper.moveAndResizeEntity(motionX, motionY, motionZ, newAABBDiameter, newAABBDiameter);
  83.  
  84. if (isCollided && onGround) {
  85. motionY -= 0.01F; // ensure that we hit the ground next time too
  86. }
  87. breathNode.updateAge(this);
  88. if (breathNode.isDead()) {
  89. setDead();
  90. }
  91. }
  92.  
  93. /**
  94. * creates a single EntityFX from the given parameters. Applies some random spread to direction.
  95. * @param world
  96. * @param x world [x,y,z] to spawn at (inates are the centre point of the fireball)
  97. * @param y
  98. * @param z
  99. * @param directionX initial world direction [x,y,z] - will be normalised.
  100. * @param directionY
  101. * @param directionZ
  102. * @param power the power of the ball
  103. * @param partialTicksHeadStart if spawning multiple EntityFX per tick, use this parameter to spread the starting
  104. * location in the direction
  105. * @return the new FlameBreathFX
  106. */
  107. public static FlameBreathFX createFlameBreathFX(World world, double x, double y, double z,
  108. double directionX, double directionY, double directionZ,
  109. BreathNode.Power power,
  110. float partialTicksHeadStart) {
  111. Vec3d direction = new Vec3d(directionX, directionY, directionZ).normalize();
  112.  
  113. Random rand = new Random();
  114. BreathNode breathNode = new BreathNode(power);
  115. breathNode.randomiseProperties(rand);
  116. Vec3d actualMotion = breathNode.getRandomisedStartingMotion(direction, rand);
  117.  
  118. x += actualMotion.x * partialTicksHeadStart;
  119. y += actualMotion.y * partialTicksHeadStart;
  120. z += actualMotion.z * partialTicksHeadStart;
  121. FlameBreathFX newFlameBreathFX = new FlameBreathFX(world, x, y, z, actualMotion, breathNode);
  122. return newFlameBreathFX;
  123. }
  124.  
  125. protected EnumParticleTypes getSmokeParticleID() {
  126. if (LARGE_SMOKE_CHANCE != 0 && rand.nextFloat() <= LARGE_SMOKE_CHANCE) {
  127. return EnumParticleTypes.SMOKE_LARGE;
  128. } else {
  129. return EnumParticleTypes.SMOKE_NORMAL;
  130. }
  131. }
  132.  
  133. /** Vanilla moveEntity does a pile of unneeded calculations, and also doesn't handle resize around the centre properly,
  134. * so replace with a custom one
  135. * @param dx the amount to move the entity in world inates [dx, dy, dz]
  136. * @param dy
  137. * @param dz
  138. */
  139. @Override
  140. public void move(MoverType mover, double dx, double dy, double dz) {
  141. entityMoveAndResizeHelper.moveAndResizeEntity(dx, dy, dz, this.width, this.height);
  142. }
  143.  
  144. private EntityMoveAndResizeHelper entityMoveAndResizeHelper;
  145.  
  146. @Override
  147. protected void entityInit() {
  148.  
  149. }
  150.  
  151. @Override
  152. protected void readEntityFromNBT(NBTTagCompound compound) {
  153.  
  154. }
  155.  
  156. @Override
  157. protected void writeEntityToNBT(NBTTagCompound compound) {
  158.  
  159. }
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment