Advertisement
Plasma_Blazer

[1.8] TESR Entity Item Rendering

Feb 20th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.63 KB | None | 0 0
  1. package com.plasmablazer.electroniceng.client.renderer.tileentity;
  2.  
  3. import com.plasmablazer.electroniceng.block.BlockDeconstructionTable;
  4. import com.plasmablazer.electroniceng.init.ModItems;
  5. import com.plasmablazer.electroniceng.tileentity.TileDeconstructionTable;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.client.Minecraft;
  8. import net.minecraft.client.renderer.GlStateManager;
  9. import net.minecraft.client.renderer.Tessellator;
  10. import net.minecraft.client.renderer.WorldRenderer;
  11. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  12. import net.minecraft.entity.item.EntityItem;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.tileentity.TileEntity;
  15. import org.lwjgl.opengl.GL11;
  16.  
  17. /**
  18.  * Electronic Engineering (Minecraft Mod)
  19.  * Copyright (C) 2014 Jack Bentley
  20.  * <p/>
  21.  * This program is free software: you can redistribute it and/or modify
  22.  * it under the terms of the GNU General Public License as published by
  23.  * the Free Software Foundation, either version 3 of the License, or
  24.  * (at your option) any later version.
  25.  * <p/>
  26.  * This program is distributed in the hope that it will be useful,
  27.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29.  * GNU General Public License for more details.
  30.  * <p/>
  31.  * You should have received a copy of the GNU General Public License
  32.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  33.  */
  34. public class RendererDeconstructionTable extends TileEntitySpecialRenderer
  35. {
  36.     TileDeconstructionTable tile;
  37.  
  38.     ItemStack stackWrench = new ItemStack(ModItems.basicWrench);
  39.     EntityItem entityWrench = new EntityItem(Minecraft.getMinecraft().theWorld, 0D, 0D, 0D);
  40.  
  41.     EntityItem entityInput = new EntityItem(Minecraft.getMinecraft().theWorld, 0D, 0D, 0D);
  42.  
  43.     public RendererDeconstructionTable()
  44.     {
  45.  
  46.     }
  47.  
  48.     @Override
  49.     public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick, int destroyStage)
  50.     {
  51.         Block block = tileEntity.getBlockType();
  52.         if(!(block instanceof BlockDeconstructionTable))
  53.             return;
  54.  
  55.         tile = (TileDeconstructionTable) tileEntity;
  56.         int metadata = block.getMetaFromState(tileEntity.getWorld().getBlockState(tileEntity.getPos()));
  57.  
  58.         renderWrench(x, y, z, metadata);
  59.         renderInput(x, y, z, metadata);
  60.  
  61.     }
  62.  
  63.     private void renderWrench(double x, double y, double z, int metadata)
  64.     {
  65.         entityWrench.setEntityItemStack(stackWrench);
  66.  
  67.         GL11.glPushMatrix();
  68.  
  69.         this.entityWrench.hoverStart = 0.0F;
  70.  
  71.         GL11.glDisable(GL11.GL_LIGHTING);
  72.         WorldRenderer renderer = Tessellator.getInstance().getWorldRenderer();
  73.         //renderer.setBrightness(15728880);
  74.  
  75.         float xOffset = 0.0F;
  76.         float zOffset = 0.0F;
  77.  
  78.         switch (metadata)
  79.         {
  80.             case 0:
  81.                 xOffset += 0.5F;
  82.                 zOffset -= 0.1875F;
  83.                 break;
  84.             case 1:
  85.                 xOffset += 1.1875F;
  86.                 zOffset += 0.5F;
  87.                 break;
  88.             case 2:
  89.                 xOffset += 0.5F;
  90.                 zOffset += 1.1875F;
  91.                 break;
  92.             case 3:
  93.                 xOffset -= 0.175F;
  94.                 zOffset += 0.4875;
  95.                 break;
  96.         }
  97.  
  98.         GL11.glTranslatef((float) x + xOffset, (float) y + 1F, (float) z + zOffset);
  99.         GL11.glRotatef(metadata * -90F, 0, 1, 0);
  100.         GL11.glRotatef(180, 0, 1, 1);
  101.         GL11.glScalef(2.0F, 2.0F, 2.0F);
  102.         Minecraft.getMinecraft().getRenderManager().renderEntityWithPosYaw(entityWrench, 0.0D, 0.0D, 0.0D, 2F, 0.0F);
  103.  
  104.         GL11.glEnable(GL11.GL_LIGHTING);
  105.  
  106.         GL11.glPopMatrix();
  107.     }
  108.  
  109.     private void renderInput(double x, double y, double z, int metadata)
  110.     {
  111.         if (tile.getStackInSlot(tile.SLOT_INPUT) != null)
  112.         {
  113.             entityInput.setEntityItemStack(tile.getStackInSlot(tile.SLOT_INPUT));
  114.  
  115.             GL11.glPushMatrix();
  116.  
  117.             this.entityInput.hoverStart = 0.0F;
  118.  
  119.             GL11.glDisable(GL11.GL_LIGHTING);
  120.             WorldRenderer renderer = Tessellator.getInstance().getWorldRenderer();
  121.             //renderer.setBrightness(15728880);
  122.  
  123.             GL11.glTranslatef((float) x + 0.5F, (float) y + 0.8125F, (float) z + 0.5F);
  124.             GL11.glRotatef(metadata * - 90F, 0, 1, 0);
  125.             Minecraft.getMinecraft().getRenderManager().renderEntityWithPosYaw(entityInput, 0.0D, 0.0D, 0.0D, 2F, 0.0F);
  126.  
  127.             GL11.glEnable(GL11.GL_LIGHTING);
  128.  
  129.             GL11.glPopMatrix();
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement