Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.46 KB | None | 0 0
  1. public class RenderPress extends TileEntitySpecialRenderer<TileEntityMachinePress> {
  2.  
  3.     private static final float[] IDENTITY_MATRIX =
  4.             new float[] {
  5.                 1.0f, 0.0f, 0.0f, 0.0f,
  6.                 0.0f, 1.0f, 0.0f, 0.0f,
  7.                 0.0f, 0.0f, 1.0f, 0.0f,
  8.                 0.0f, 0.0f, 0.0f, 1.0f };
  9.    
  10.     private static final FloatBuffer matrix = BufferUtils.createFloatBuffer(16);
  11.     public static float fov;
  12.     boolean bool = false;
  13.     int renderCount = 0;
  14.  
  15.     public RenderPress() {
  16.         super();
  17.     }
  18.  
  19.     @Override
  20.     public void render(TileEntityMachinePress te, double x, double y, double z, float partialTicks, int destroyStage,
  21.             float alpha) {
  22.  
  23.        
  24.         FloatBuffer oldMatrix = GLAllocation.createDirectFloatBuffer(16);
  25.         GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, oldMatrix);
  26.         float[] duck = RenderHelper.getScreenAreaFromQuad(new Vec3d(x, y, z), new Vec3d(x, y, z + 1),
  27.                 new Vec3d(x, y + 1, z + 1), new Vec3d(x, y + 1, z));
  28.         if (duck != null) {
  29.            
  30.            
  31.             GL11.glMatrixMode(GL11.GL_PROJECTION);
  32.             GL11.glLoadIdentity();
  33.             float rightFactor = Minecraft.getMinecraft().displayWidth/duck[2];
  34.             float leftFactor = Minecraft.getMinecraft().displayWidth/duck[0];
  35.             float topFactor = Minecraft.getMinecraft().displayHeight/duck[3];
  36.             float bottomFactor = Minecraft.getMinecraft().displayHeight/duck[1];
  37.             this.setupProjMatrix(rightFactor, leftFactor, topFactor, bottomFactor, 0.05F, (Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16) * MathHelper.SQRT_2);
  38.  
  39.             IntBuffer vp = GLAllocation.createDirectIntBuffer(16);
  40.            
  41.             GL11.glViewport((int) (Minecraft.getMinecraft().displayWidth/leftFactor), (int) (Minecraft.getMinecraft().displayHeight/bottomFactor), (int) (Minecraft.getMinecraft().displayWidth/rightFactor-Minecraft.getMinecraft().displayWidth/leftFactor), (int) (Minecraft.getMinecraft().displayHeight/topFactor-Minecraft.getMinecraft().displayHeight/bottomFactor));
  42.             GL11.glGetInteger(GL11.GL_VIEWPORT, vp);
  43.  
  44.            
  45.             GL11.glMatrixMode(GL11.GL_MODELVIEW);
  46.         }
  47.  
  48.         GL11.glPushMatrix();
  49.  
  50.         GL11.glTranslated(x + 0.5D, y, z + 0.5D);
  51.         GL11.glEnable(GL11.GL_LIGHTING);
  52.         GL11.glRotatef(180, 0F, 1F, 0F);
  53.         this.bindTexture(ResourceManager.press_body_tex);
  54.         ResourceManager.press_body.renderAll();
  55.  
  56.         GL11.glPopMatrix();
  57.         renderTileEntityAt2(te, x, y, z, partialTicks);
  58.         GL11.glMatrixMode(GL11.GL_PROJECTION);
  59.         GL11.glLoadIdentity();
  60.         GL11.glLoadMatrix(oldMatrix);
  61.         GL11.glMatrixMode(GL11.GL_MODELVIEW);
  62.         GL11.glViewport(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
  63.     }
  64.  
  65.     public void renderTileEntityAt2(TileEntity tileEntity, double x, double y, double z, float f) {
  66.         GL11.glPushMatrix();
  67.         GL11.glTranslated(x + 0.5D, y + 1 - 0.125D, z + 0.5D);
  68.         GL11.glEnable(GL11.GL_LIGHTING);
  69.         GL11.glRotatef(180, 0F, 1F, 0F);
  70.         GL11.glScalef(0.95F, 1, 0.95F);
  71.  
  72.         TileEntityMachinePress press = (TileEntityMachinePress) tileEntity;
  73.         float f1 = press.progress * (1 - 0.125F) / TileEntityMachinePress.maxProgress;
  74.         GL11.glTranslated(0, -f1, 0);
  75.  
  76.         this.bindTexture(ResourceManager.press_head_tex);
  77.  
  78.         ResourceManager.press_head.renderAll();
  79.  
  80.         GL11.glPopMatrix();
  81.  
  82.         renderTileEntityAt3(tileEntity, x, y, z, f);
  83.     }
  84.  
  85.     public void renderTileEntityAt3(TileEntity tileEntity, double x, double y, double z, float f) {
  86.         GL11.glPushMatrix();
  87.         GL11.glTranslated(x + 0.5D, y + 1, z - 0.5);
  88.         GL11.glEnable(GL11.GL_LIGHTING);
  89.         GL11.glRotatef(180, 0F, 1F, 0F);
  90.         GL11.glRotatef(-90, 1F, 0F, 0F);
  91.  
  92.         TileEntityMachinePress press = (TileEntityMachinePress) tileEntity;
  93.         ItemStack stack = new ItemStack(Item.getItemById(press.item), 1, press.meta);
  94.  
  95.         if (!(stack.getItem() instanceof ItemBlock) && !stack.isEmpty()) {
  96.             IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(stack,
  97.                     tileEntity.getWorld(), null);
  98.             model = ForgeHooksClient.handleCameraTransforms(model, TransformType.FIXED, false);
  99.             Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
  100.             GL11.glTranslatef(0.0F, 1.0F, 0.0F);
  101.             GL11.glRotatef(180, 0F, 1F, 0F);
  102.             GL11.glScalef(0.5F, 0.5F, 0.5F);
  103.             Minecraft.getMinecraft().getRenderItem().renderItem(stack, model);
  104.         }
  105.  
  106.         GL11.glPopMatrix();
  107.     }
  108.    
  109.     /**
  110.      *
  111.      * @param r -
  112.      * @param l
  113.      * @param t
  114.      * @param b
  115.      * @param zNear
  116.      * @param zFar
  117.      */
  118.     public void setupProjMatrix(float r, float l, float t, float b, float zNear, float zFar){
  119.        
  120.         float r2, l2, t2, b2, r3, l3, t3, b3;
  121.         float sine, cotangent, deltaZ;
  122.         float radians = Minecraft.getMinecraft().gameSettings.fovSetting*fov / 2 * (float)Math.PI / 180;
  123.  
  124.         deltaZ = zFar - zNear;
  125.         sine = (float) Math.sin(radians);
  126.  
  127.         if ((deltaZ == 0) || (sine == 0) || (1 == 0)) {
  128.             return;
  129.         }
  130.  
  131.         cotangent = (float) Math.cos(radians) / sine;
  132.  
  133.         float aspect = (float)Minecraft.getMinecraft().displayWidth/(float)Minecraft.getMinecraft().displayHeight;
  134.         float duck = cotangent/aspect;
  135.         //System.out.println(cotangent/aspect + " " + cotangent + " " + cotangent/(cotangent/aspect) + " " + Minecraft.getMinecraft().displayWidth/(float)Minecraft.getMinecraft().displayHeight);
  136.        
  137.        
  138.        
  139.        
  140.         r2 = (float) (((2.0F*zNear)/duck)/2);
  141.         l2 =  -r2;
  142.         t2 = (float) (((2.0F*zNear)/cotangent)/2);
  143.         b2 = -t2;
  144.        
  145.         r3 = (r2+r2)/r-r2;
  146.         l3 = -((l2+l2)/l-l2);
  147.         t3 = (t2+t2)/t-t2;
  148.         b3 = -((b2+b2)/b-b2);
  149.         this.setupProjMatrixDirect(r3, l3, t3, b3, zNear, zFar);
  150.     }
  151.    
  152.     public void setupProjMatrixDirect(float r, float l, float t, float b, float zNear, float zFar){
  153.  
  154.        
  155.        
  156.        
  157.         __gluMakeIdentityf(matrix);
  158. //2*zNear / (r-l))
  159.         //2*zNear / (t-b)
  160.         matrix.put(0 * 4 + 0, 2*zNear / (r-l));
  161.         matrix.put(1 * 4 + 1, 2*zNear / (t-b));
  162.         matrix.put(2*4 + 0, (r+l)/(r-l));
  163.         matrix.put(2*4 + 1, (t+b)/(t-b));
  164.         matrix.put(2 * 4 + 2, - (zFar + zNear) / (zFar-zNear));
  165.         matrix.put(2 * 4 + 3, -1);
  166.         matrix.put(3 * 4 + 2, -2 * zNear * zFar / (zFar-zNear));
  167.         matrix.put(3 * 4 + 3, 0);
  168.  
  169.         //glMultMatrix(matrix);
  170.         GL11.glLoadMatrix(matrix);
  171.     }
  172.  
  173.     private static void __gluMakeIdentityf(FloatBuffer m) {
  174.         int oldPos = m.position();
  175.         m.put(IDENTITY_MATRIX);
  176.         m.position(oldPos);
  177.     }
  178.    
  179.     public float normalize(float value, float min, float max, float mult) {
  180.         float normalized = (value - min) / (max - min);
  181.         return normalized*mult;
  182.     }
  183.     public float normalize(float value, float min, float max){
  184.         return this.normalize(value, min, max, 1.0f);
  185.     }
  186.    
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement