Guest User

render code

a guest
Sep 9th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.26 KB | None | 0 0
  1.     public void renderItemTexture(int x, int y, ItemStack stack, boolean shouldRenderTextOnLeft, boolean drawText)
  2.     {
  3.         IBakedModel ibakedmodel = mc.getRenderItem().getItemModelMesher().getItemModel(new ItemStack(stack.getItem(),
  4.         1, stack.getItemDamage()));
  5.         this.renderItemIntoGUI(stack, x, y, ibakedmodel);
  6.     }
  7.  
  8.     // Custom version of RenderItem#renderItemIntoGui so that it can call custom setupGuiTransformation
  9.     // Is used to render items onto the screen.
  10.     public void renderItemIntoGUI(ItemStack stack, int x, int y, IBakedModel model)
  11.     {
  12.         GlStateManager.pushMatrix();
  13.         this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
  14.         this.mc.getTextureManager().getTexture(TextureMap.locationBlocksTexture).setBlurMipmap(false, false);
  15.         GlStateManager.enableRescaleNormal();
  16.         GlStateManager.enableAlpha();
  17.         GlStateManager.alphaFunc(516, 0.1F);
  18.         GlStateManager.enableBlend();
  19.         GlStateManager.blendFunc(770, 771);
  20.         GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  21.         this.setupGuiTransform(stack, x + 8, y + 8, model.isGui3d());
  22.         if (x > mc.displayWidth) x = mc.displayWidth -  32;
  23.         if (y > mc.displayHeight) y = mc.displayHeight -  32;
  24.         model = ForgeHooksClient.handleCameraTransforms(model, ItemCameraTransforms.TransformType.GUI);
  25.         Minecraft.getMinecraft().getRenderItem().renderItem(stack, model);
  26.         GlStateManager.disableLighting();
  27.         GlStateManager.disableBlend();
  28.         GlStateManager.disableAlpha();
  29.         GlStateManager.disableRescaleNormal();
  30.         GlStateManager.popMatrix();
  31.         this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
  32.         this.mc.getTextureManager().getTexture(TextureMap.locationBlocksTexture).restoreLastBlurMipmap();
  33.     }
  34.  
  35.     // Custom version of RenderItem#setupGuiTransformation because using the vanilla one causes
  36.     // rotation, scale, translation errors.
  37.     private void setupGuiTransform(ItemStack stack, int xPosition, int yPosition, boolean isGui3d)
  38.     {
  39.         GlStateManager.translate((float) xPosition, (float) yPosition, this.zLevel - 7.8F);
  40.         GlStateManager.translate(8.0F, 8.0F, -20.0F);
  41.         GlStateManager.scale(1.0F, 1.0F, -1.0F);
  42.  
  43.         if (stack.getItem().getItemFromBlock(Block.getBlockFromItem(stack.getItem())) != null && isGui3d)
  44.         {
  45.             GlStateManager.scale(40.0F, 40.0F, 40.0F);
  46.             GlStateManager.rotate(210.0F, 1.0F, 0.0F, 0.0F);
  47.             RenderHelper.enableStandardItemLighting();
  48.             GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F);
  49.  
  50.             if (stack.getItem().hasEffect(stack))
  51.             {
  52.                 GlStateManager.scale(0.5F, 0.5F, 0.5F);
  53.                 GlStateManager.translate(0.562F, 0.69F, 0.0F);
  54.             }
  55.         }
  56.         else if (stack.getItem() != null && isGui3d)
  57.         {
  58.             GlStateManager.scale(20.0F, 20.0F, 20.0F);
  59.             GlStateManager.rotate(210.0F, 1.0F, 0.0F, 0.0F);
  60.             RenderHelper.enableStandardItemLighting();
  61.             GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F);
  62.             GlStateManager.translate(0.5F, 0.6F, 0.0F);
  63.         }
  64.         else if (stack.getItem().getItemFromBlock(Block.getBlockFromItem(stack.getItem())) != null && !isGui3d)
  65.         {
  66.             GlStateManager.scale(64.0F, 64.0F, 64.0F);
  67.             GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
  68.             GlStateManager.disableLighting();
  69.  
  70.             if (stack.getItem().hasEffect(stack))
  71.             {
  72.                 GlStateManager.scale(0.5F, 0.5F, 0.5F);
  73.                 GlStateManager.translate(-0.248F, 0.248F, 0.0F);
  74.             }
  75.         }
  76.         else
  77.         {
  78.             GlStateManager.scale(32.0F, 32.0F, 32.0F);
  79.             GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
  80.             GlStateManager.translate(-0.25F, 0.25F, 0.0F);
  81.             GlStateManager.disableLighting();
  82.         }
  83.     }
  84.  
  85.     public static void renderItemIcon(float x, float y, float z, Item item, float partialTickTime)
  86.     {
  87.         RenderManager rendermanager = mc.getRenderManager();
  88.         float playerX = (float) (mc.thePlayer.lastTickPosX + (mc.thePlayer.posX -
  89.         mc.thePlayer.lastTickPosX) * partialTickTime);
  90.         float playerY = (float) (mc.thePlayer.lastTickPosY + (mc.thePlayer.posY -
  91.         mc.thePlayer.lastTickPosY) * partialTickTime);
  92.         float playerZ = (float) (mc.thePlayer.lastTickPosZ + (mc.thePlayer.posZ -
  93.         mc.thePlayer.lastTickPosZ) * partialTickTime);
  94.         float dx = x - playerX;
  95.         float dy = y - playerY;
  96.         float dz = z - playerZ;
  97.         float scale = 0.025F;
  98.  
  99.         GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  100.         GlStateManager.pushMatrix();
  101.         GlStateManager.translate(dx, dy, dz);
  102.         GlStateManager.rotate(-rendermanager.playerViewY, 0.0F, 1.0F, 0.0F);
  103.         GlStateManager.rotate(mc.gameSettings.thirdPersonView != 2 ?
  104.         rendermanager.playerViewX : -rendermanager.playerViewX, 1.0F, 0.0F, 0.0F);
  105.         GlStateManager.scale(-scale, -scale, -scale);
  106.         GlStateManager.disableLighting();
  107.         GlStateManager.disableDepth();
  108.         GlStateManager.enableBlend();
  109.         GlStateManager.blendFunc(770, 771);
  110.         renderItemTexture(-8, -8, item, 16, 16);
  111.         GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  112.         GlStateManager.enableDepth();
  113.         GlStateManager.enableLighting();
  114.         GlStateManager.popMatrix();
  115.     }
  116.  
  117.     // Used to render Item Icons into the world.
  118.     public static void renderItemTexture(int x, int y, Item item, int width, int height)
  119.     {
  120.         IBakedModel ibakedmodel = mc.getRenderItem().getItemModelMesher().getItemModel(new ItemStack(item));
  121.         TextureAtlasSprite atlas = mc.getTextureMapBlocks().getAtlasSprite(ibakedmodel.getTexture().getIconName());
  122.         mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
  123.         drawTexturedModalRect(x, y, atlas, width, height, 0);
  124.     }
Advertisement
Add Comment
Please, Sign In to add comment