SHARE
TWEET

RenderProjectile

ButterAleks May 27th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.ButterAleks.KirbyMod.entity.projectile.render;
  2.  
  3. import org.lwjgl.opengl.GL11;
  4.  
  5. import net.minecraft.client.model.ModelBase;
  6. import net.minecraft.client.renderer.BufferBuilder;
  7. import net.minecraft.client.renderer.GlStateManager;
  8. import net.minecraft.client.renderer.Tessellator;
  9. import net.minecraft.client.renderer.entity.Render;
  10. import net.minecraft.client.renderer.entity.RenderManager;
  11. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  12. import net.minecraft.entity.projectile.EntityArrow;
  13. import net.minecraft.util.math.MathHelper;
  14. import net.minecraftforge.fml.relauncher.Side;
  15. import net.minecraftforge.fml.relauncher.SideOnly;
  16.  
  17. @SideOnly(Side.CLIENT)
  18. public abstract class RenderProjectile<T extends EntityArrow> extends Render<T>
  19. {
  20.     protected ModelBase mainModel;
  21.    
  22.     public RenderProjectile(RenderManager renderManagerIn, ModelBase modelbaseIn)
  23.     {
  24.         super(renderManagerIn);
  25.         this.mainModel = modelbaseIn;
  26.     }
  27.  
  28.     /**
  29.      * Renders the desired {@code T} type Entity.
  30.      */
  31.     public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks)
  32.     {
  33.         this.bindEntityTexture(entity);
  34.         GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  35.         GlStateManager.pushMatrix();
  36.         GlStateManager.disableLighting();
  37.         GlStateManager.translate((float)x, (float)y, (float)z);
  38.         GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks - 90.0F, 0.0F, 1.0F, 0.0F);
  39.         GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, 0.0F, 0.0F, 1.0F);
  40.         Tessellator tessellator = Tessellator.getInstance();
  41.         BufferBuilder bufferbuilder = tessellator.getBuffer();
  42.         int i = 0;
  43.         float f = 0.0F;
  44.         float f1 = 0.5F;
  45.         float f2 = 0.0F;
  46.         float f3 = 0.15625F;
  47.         float f4 = 0.0F;
  48.         float f5 = 0.15625F;
  49.         float f6 = 0.15625F;
  50.         float f7 = 0.3125F;
  51.         float f8 = 0.05625F;
  52.         GlStateManager.enableRescaleNormal();
  53.         float f9 = (float)entity.arrowShake - partialTicks;
  54.  
  55.         if (f9 > 0.0F)
  56.         {
  57.             float f10 = -MathHelper.sin(f9 * 3.0F) * f9;
  58.             GlStateManager.rotate(f10, 0.0F, 0.0F, 1.0F);
  59.         }
  60.  
  61.         GlStateManager.rotate(45.0F, 1.0F, 0.0F, 0.0F);
  62.         GlStateManager.scale(0.05625F, 0.05625F, 0.05625F);
  63.         GlStateManager.translate(-4.0F, 0.0F, 0.0F);
  64.  
  65.         if (this.renderOutlines)
  66.         {
  67.             GlStateManager.enableColorMaterial();
  68.             GlStateManager.enableOutlineMode(this.getTeamColor(entity));
  69.         }
  70.  
  71.         if (this.renderOutlines)
  72.         {
  73.             GlStateManager.disableOutlineMode();
  74.             GlStateManager.disableColorMaterial();
  75.         }
  76.  
  77.         GlStateManager.disableRescaleNormal();
  78.         GlStateManager.enableLighting();
  79.         GlStateManager.popMatrix();
  80.         super.doRender(entity, x, y, z, entityYaw, partialTicks);
  81.     }
  82.    
  83.     @SideOnly(Side.CLIENT)
  84.     public static void drawCuboid(final float minU, final float maxU, final float minV, final float maxV, final double x_size, final double y_size, final double z_size, final double scale) {
  85.         drawCuboidAt(8, 8, 8, minU, maxU, minV, maxV, x_size, y_size, z_size, scale);
  86.     }
  87.     public static void drawCuboidAt(final double x, final double y, final double z, final float minU, final float maxU, final float minV, final float maxV, final double x_size, final double y_size, final double z_size, final double scale) {
  88.  
  89.         GlStateManager.pushMatrix();
  90.         GlStateManager.scale(scale, scale, scale);
  91.  
  92.         final Tessellator tessellator = Tessellator.getInstance();
  93.         final BufferBuilder bufferbuilder = tessellator.getBuffer();
  94.         bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
  95.  
  96.         // UP
  97.         bufferbuilder.pos(-x_size + x, y_size + y, -z_size + z).tex(maxU, maxV).endVertex();
  98.         bufferbuilder.pos(-x_size + x, y_size + y, z_size + z).tex(maxU, minV).endVertex();
  99.         bufferbuilder.pos(x_size + x, y_size + y, z_size + z).tex(minU, minV).endVertex();
  100.         bufferbuilder.pos(x_size + x, y_size + y, -z_size + z).tex(minU, maxV).endVertex();
  101.  
  102.         // DOWN
  103.         bufferbuilder.pos(-x_size + x, -y_size + y, z_size + z).tex(minU, minV).endVertex();
  104.         bufferbuilder.pos(-x_size + x, -y_size + y, -z_size + z).tex(minU, maxV).endVertex();
  105.         bufferbuilder.pos(x_size + x, -y_size + y, -z_size + z).tex(maxU, maxV).endVertex();
  106.         bufferbuilder.pos(x_size + x, -y_size + y, z_size + z).tex(maxU, minV).endVertex();
  107.  
  108.         // LEFT
  109.         bufferbuilder.pos(x_size + x, -y_size + y, z_size + z).tex(maxU, minV).endVertex();
  110.         bufferbuilder.pos(x_size + x, -y_size + y, -z_size + z).tex(maxU, maxV).endVertex();
  111.         bufferbuilder.pos(x_size + x, y_size + y, -z_size + z).tex(minU, maxV).endVertex();
  112.         bufferbuilder.pos(x_size + x, y_size + y, z_size + z).tex(minU, minV).endVertex();
  113.  
  114.         // RIGHT
  115.         bufferbuilder.pos(-x_size + x, -y_size + y, -z_size + z).tex(minU, maxV).endVertex();
  116.         bufferbuilder.pos(-x_size + x, -y_size + y, z_size + z).tex(minU, minV).endVertex();
  117.         bufferbuilder.pos(-x_size + x, y_size + y, z_size + z).tex(maxU, minV).endVertex();
  118.         bufferbuilder.pos(-x_size + x, y_size + y, -z_size + z).tex(maxU, maxV).endVertex();
  119.  
  120.         // BACK
  121.         bufferbuilder.pos(-x_size + x, -y_size + y, -z_size + z).tex(minU, maxV).endVertex();
  122.         bufferbuilder.pos(-x_size + x, y_size + y, -z_size + z).tex(minU, minV).endVertex();
  123.         bufferbuilder.pos(x_size + x, y_size + y, -z_size + z).tex(maxU, minV).endVertex();
  124.         bufferbuilder.pos(x_size + x, -y_size + y, -z_size + z).tex(maxU, maxV).endVertex();
  125.  
  126.         // FRONT
  127.         bufferbuilder.pos(x_size + x, -y_size + y, z_size + z).tex(maxU, minV).endVertex();
  128.         bufferbuilder.pos(x_size + x, y_size + y, z_size + z).tex(maxU, maxV).endVertex();
  129.         bufferbuilder.pos(-x_size + x, y_size + y, z_size + z).tex(minU, maxV).endVertex();
  130.         bufferbuilder.pos(-x_size + x, -y_size + y, z_size + z).tex(minU, minV).endVertex();
  131.  
  132.         tessellator.draw();
  133.  
  134.         GlStateManager.popMatrix();
  135.     }
  136. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top