Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
19,786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. package de.krokoyt.fa.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.renderer.ActiveRenderInfo;
  10. import net.minecraft.client.renderer.BufferBuilder;
  11. import net.minecraft.client.renderer.Tessellator;
  12. import net.minecraft.client.renderer.texture.TextureManager;
  13. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  14. import net.minecraft.particles.IParticleData;
  15. import net.minecraft.util.ResourceLocation;
  16. import net.minecraft.util.math.BlockPos;
  17. import net.minecraft.world.World;
  18. import net.minecraftforge.api.distmarker.Dist;
  19. import net.minecraftforge.api.distmarker.OnlyIn;
  20.  
  21. public class Footstep extends Particle{
  22.  
  23. private static final ResourceLocation FOOTPRINT_TEXTURE = new ResourceLocation("textures/particle/footprint.png");
  24. private int footstepAge;
  25. private final int footstepMaxAge;
  26. private final TextureManager currentFootSteps;
  27.  
  28. protected Footstep(TextureManager currentFootStepsIn, World worldIn, double posXIn, double posYIn, double posZIn) {
  29. super(worldIn, posXIn, posYIn, posZIn);
  30. this.currentFootSteps = currentFootStepsIn;
  31. this.motionX = 0.0D;
  32. this.motionY = 0.0D;
  33. this.motionZ = 0.0D;
  34. this.footstepMaxAge = 200;
  35. // TODO Auto-generated constructor stub
  36. }
  37.  
  38. @Override
  39. public void renderParticle(BufferBuilder buffer, ActiveRenderInfo entityIn, float partialTicks, float rotationX,
  40. float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
  41.  
  42. float f = ((float)this.footstepAge + partialTicks) / (float)this.footstepMaxAge;
  43. f = f * f;
  44. float f1 = 2.0F - f * 2.0F;
  45.  
  46. if (f1 > 1.0F)
  47. {
  48. f1 = 1.0F;
  49. }
  50.  
  51. f1 = f1 * 0.2F;
  52. GlStateManager.disableLighting();
  53. float f2 = 0.125F;
  54. float f3 = (float)(this.posX - interpPosX);
  55. float f4 = (float)(this.posY - interpPosY);
  56. float f5 = (float)(this.posZ - interpPosZ);
  57. float f6 = this.world.getBrightness(new BlockPos(this.posX, this.posY, this.posZ));
  58. this.currentFootSteps.bindTexture(FOOTPRINT_TEXTURE);
  59. com.mojang.blaze3d.platform.GlStateManager.enableBlend();
  60. GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
  61. buffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
  62. buffer.pos((double)(f3 - 0.125F), (double)f4, (double)(f5 + 0.125F)).tex(0.0D, 1.0D).color(f6, f6, f6, f1).endVertex();
  63. buffer.pos((double)(f3 + 0.125F), (double)f4, (double)(f5 + 0.125F)).tex(1.0D, 1.0D).color(f6, f6, f6, f1).endVertex();
  64. buffer.pos((double)(f3 + 0.125F), (double)f4, (double)(f5 - 0.125F)).tex(1.0D, 0.0D).color(f6, f6, f6, f1).endVertex();
  65. buffer.pos((double)(f3 - 0.125F), (double)f4, (double)(f5 - 0.125F)).tex(0.0D, 0.0D).color(f6, f6, f6, f1).endVertex();
  66. Tessellator.getInstance().draw();
  67. GlStateManager.disableBlend();
  68. GlStateManager.enableLighting();
  69.  
  70. }
  71.  
  72. public void onUpdate()
  73. {
  74. ++this.footstepAge;
  75.  
  76. if (this.footstepAge == this.footstepMaxAge)
  77. {
  78. this.setExpired();
  79. }
  80. }
  81.  
  82. /**
  83. * Retrieve what effect layer (what texture) the particle should be rendered with. 0 for the particle sprite sheet,
  84. * 1 for the main Texture atlas, and 3 for a custom texture
  85. */
  86. public int getFXLayer()
  87. {
  88. return 3;
  89. }
  90.  
  91.  
  92.  
  93. @Override
  94. public IParticleRenderType getRenderType() {
  95. // TODO Auto-generated method stub
  96. return null;
  97. }
  98.  
  99. @OnlyIn(Dist.CLIENT)
  100. public static class Factory implements IParticleFactory
  101. {
  102.  
  103. @Override
  104. public Particle makeParticle(IParticleData typeIn, World worldIn, double x, double y, double z, double xSpeed,
  105. double ySpeed, double zSpeed) {
  106.  
  107. return new Footstep(Minecraft.getInstance().textureManager, worldIn, x, y, z);
  108.  
  109.  
  110. }
  111.  
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement