Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. package maxmos.zelda.particles;
  2.  
  3. import com.mojang.blaze3d.platform.GlStateManager;
  4.  
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.particle.IParticleFactory;
  7. import net.minecraft.client.particle.IParticleRenderType;
  8. import net.minecraft.client.particle.Particle;
  9. import net.minecraft.client.particle.TexturedParticle;
  10. import net.minecraft.client.renderer.ActiveRenderInfo;
  11. import net.minecraft.client.renderer.BufferBuilder;
  12. import net.minecraft.client.renderer.RenderHelper;
  13. import net.minecraft.client.renderer.Tessellator;
  14. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  15. import net.minecraft.client.renderer.vertex.VertexFormat;
  16. import net.minecraft.particles.IParticleData;
  17. import net.minecraft.util.ResourceLocation;
  18. import net.minecraft.util.math.BlockPos;
  19. import net.minecraft.world.World;
  20. import net.minecraftforge.api.distmarker.Dist;
  21. import net.minecraftforge.api.distmarker.OnlyIn;
  22.  
  23. @OnlyIn(Dist.CLIENT)
  24. public class MasterParticleTexture extends TexturedParticle
  25. {
  26. private ResourceLocation texture;
  27. private static final VertexFormat VERTEX_FORMAT = (new VertexFormat()).addElement(DefaultVertexFormats.POSITION_3F).addElement(DefaultVertexFormats.TEX_2F).addElement(DefaultVertexFormats.COLOR_4UB).addElement(DefaultVertexFormats.TEX_2S).addElement(DefaultVertexFormats.NORMAL_3B).addElement(DefaultVertexFormats.PADDING_1B);
  28.  
  29. public MasterParticleTexture(World world, ResourceLocation texture, double posX, double posY, double posZ, double motionX, double motionY, double motionZ)
  30. {
  31. super(world, posX, posY, posZ, 0.0D, 0.0D, 0.0D);
  32. this.texture = texture;
  33. this.maxAge = 30 + this.rand.nextInt(10);
  34. this.age = 0;
  35. this.particleScale = 5.0F;
  36. this.particleGravity = 0F;
  37. this.setColor(1.0F, 1.0F, 1.0F);
  38. this.canCollide = false;
  39.  
  40. this.motionX = motionX;
  41. this.motionY = motionY;
  42. this.motionZ = motionZ;
  43. }
  44.  
  45. @Override
  46. public void renderParticle(BufferBuilder buffer, ActiveRenderInfo info, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
  47. {
  48. Minecraft.getInstance().textureManager.bindTexture(this.texture);
  49.  
  50. float scale = 0.1F * this.particleScale;
  51. float x = (float) (this.prevPosX + (this.posX - this.prevPosX) * partialTicks - interpPosX);
  52. float y = (float) (this.prevPosY + (this.posY - this.prevPosY) * partialTicks - interpPosY);
  53. float z = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * partialTicks - interpPosZ);
  54.  
  55. GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  56. GlStateManager.disableLighting();
  57. RenderHelper.disableStandardItemLighting();
  58. buffer.begin(7, VERTEX_FORMAT);
  59. buffer.pos(x - rotationX * scale - rotationXY * scale, y - rotationZ * scale, z - rotationYZ * scale - rotationXZ * scale).tex(1, 1).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(0, 240).normal(0.0F, 1.0F, 0.0F).endVertex();
  60. buffer.pos(x - rotationX * scale + rotationXY * scale, y + rotationZ * scale, z - rotationYZ * scale + rotationXZ * scale).tex(1, 0).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(0, 240).normal(0.0F, 1.0F, 0.0F).endVertex();
  61. buffer.pos(x + rotationX * scale + rotationXY * scale, y + rotationZ * scale, z + rotationYZ * scale + rotationXZ * scale).tex(0, 0).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(0, 240).normal(0.0F, 1.0F, 0.0F).endVertex();
  62. buffer.pos(x + rotationX * scale - rotationXY * scale, y - rotationZ * scale, z + rotationYZ * scale - rotationXZ * scale).tex(0, 1).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(0, 240).normal(0.0F, 1.0F, 0.0F).endVertex();
  63. Tessellator.getInstance().draw();
  64. GlStateManager.enableLighting();
  65. }
  66.  
  67. @Override
  68. public void tick()
  69. {
  70. this.prevPosX = this.posX;
  71. this.prevPosY = this.posY;
  72. this.prevPosZ = this.posZ;
  73. if(this.particleGravity != 0)
  74. this.motionY = -0.04D * this.particleGravity;
  75.  
  76. this.move(this.motionX, this.motionY, this.motionZ);
  77. this.motionX *= 0.99D;
  78. this.motionY *= 0.99D;
  79. this.motionZ *= 0.99D;
  80.  
  81. if (this.age++ >= this.maxAge || this.onGround)
  82. this.setExpired();
  83. }
  84.  
  85. public MasterParticleTexture setParticleAlpha(float f) { this.setAlphaF(f); return this; }
  86. public MasterParticleTexture setParticleScale(float f) { this.particleScale = f; return this; }
  87. public MasterParticleTexture setParticleGravity(float f) { this.particleGravity = f; return this; }
  88. public MasterParticleTexture setParticleAge(int i) { this.maxAge = i + this.rand.nextInt(10); return this; }
  89. public MasterParticleTexture setParticleTexture(ResourceLocation rs)
  90. {
  91. this.texture = rs;
  92. return this;
  93. }
  94.  
  95. public BlockPos getPos()
  96. {
  97. return new BlockPos(this.posX, this.posY, this.posZ);
  98. }
  99.  
  100. public MasterParticleTexture clone(double posX, double posY, double posZ)
  101. {
  102. return clone(posX, posY, posZ, 0, 0, 0);
  103. }
  104.  
  105. public MasterParticleTexture clone(double posX, double posY, double posZ, double motionX, double motionY, double motionZ)
  106. {
  107. MasterParticleTexture clone = new MasterParticleTexture(this.world, this.texture,
  108. posX, posY, posZ,
  109. motionX, motionY, motionZ)
  110. .setParticleScale(this.particleScale).setParticleGravity(this.particleGravity).setParticleAge(this.maxAge);
  111.  
  112. return clone;
  113. }
  114.  
  115. @Override
  116. public IParticleRenderType getRenderType()
  117. {
  118. return IParticleRenderType.CUSTOM;
  119. }
  120.  
  121. @Override
  122. protected float getMaxU()
  123. {
  124. return 0;
  125. }
  126.  
  127. @Override
  128. protected float getMaxV()
  129. {
  130. return 0;
  131. }
  132.  
  133. @Override
  134. protected float getMinU()
  135. {
  136. return 0;
  137. }
  138.  
  139. @Override
  140. protected float getMinV()
  141. {
  142. return 0;
  143. }
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement