Advertisement
Unh0ly_Tigg

RenderCustomBed.java

Aug 16th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.59 KB | None | 0 0
  1. package org.unh0lytigg.mobeds;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.client.renderer.RenderBlocks;
  5. import net.minecraft.client.renderer.Tessellator;
  6. import net.minecraft.client.renderer.texture.TextureMap;
  7. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraft.tileentity.TileEntity;
  10. import net.minecraft.util.IIcon;
  11. import net.minecraft.util.ResourceLocation;
  12. import net.minecraft.world.IBlockAccess;
  13. import net.minecraft.world.World;
  14.  
  15. import org.lwjgl.opengl.GL11;
  16.  
  17. import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
  18.  
  19. public class RenderCustomBed extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler {
  20.  
  21.     @Override
  22.     public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTicks) {
  23.         if (tile instanceof TileCustomBed) {
  24.             int metadata = tile.getBlockMetadata();
  25.             GL11.glPushMatrix();
  26.             GL11.glTranslated(x, y, z);
  27.             if (!BlockCustomBed.isBlockHeadOfBed(metadata)) {
  28.                 renderBedFromFoot((TileCustomBed)tile, x, y, z, partialTicks);
  29.             } else {
  30.                 renderBedFromHead((TileCustomBed)tile, x, y, z, partialTicks);
  31.             }
  32.             GL11.glPopMatrix();
  33.         }
  34.     }
  35.    
  36.     private void renderBedFromFoot(TileCustomBed bed, double x, double y, double z, float partialTicks) {
  37.         renderUnderSide(bed.getWorldObj(), bed.xCoord, bed.yCoord, bed.zCoord);
  38.         ResourceLocation r = getResource(bed);
  39.         this.field_147501_a.field_147553_e.bindTexture(r);
  40.         int b = bed.getBlockType().getMixedBrightnessForBlock(bed.getWorldObj(), bed.xCoord, bed.yCoord, bed.zCoord); // dynamic value
  41.         int dir = BlockCustomBed.getDirection(bed.getBlockMetadata());
  42.         for (int i = 0; i < dir; i++) {
  43.             GL11.glRotated(-90, 0, 1, 0);
  44.             GL11.glTranslated(0, 0, -1);
  45.         }
  46.         Tessellator t = Tessellator.instance;
  47.         t.startDrawingQuads(); // end
  48.         t.setBrightness(b);
  49.         t.addVertexWithUV(0, 0.5625, 0, 0.18, 0.73529411764705882352941176470588);
  50.         t.addVertexWithUV(1, 0.5625, 0, 0.18, 0.26470588235294117647058823529412);
  51.         t.addVertexWithUV(1, 0, 0, 0, 0.26470588235294117647058823529412);
  52.         t.addVertexWithUV(0, 0, 0, 0, 0.73529411764705882352941176470588);
  53.         t.draw();
  54.         t.startDrawingQuads(); // left (when facing end of bed)
  55.         t.setBrightness(b);
  56.         t.addVertexWithUV(1, 0.5625, 0, 0.18, 0.26470588235294117647058823529412);
  57.         t.addVertexWithUV(1, 0.5625, 1, 0.5, 0.26470588235294117647058823529412);
  58.         t.addVertexWithUV(1, 0, 1, 0.5, 0);
  59.         t.addVertexWithUV(1, 0, 0, 0.18, 0);
  60.         t.draw();
  61.         t.startDrawingQuads(); // right (when facing end of bed)
  62.         t.setBrightness(b);
  63.         t.addVertexWithUV(0, 0, 0, 0.18, 1);
  64.         t.addVertexWithUV(0, 0, 1, 0.5, 1);
  65.         t.addVertexWithUV(0, 0.5625, 1, 0.5, 1.0-0.26470588235294117647058823529412);
  66.         t.addVertexWithUV(0, 0.5625, 0, 0.18, 1.0-0.26470588235294117647058823529412);
  67.         t.draw();
  68.         t.startDrawingQuads(); // top
  69.         t.setBrightness(b);
  70.         t.addVertexWithUV(0, 0.5625, 1, 0.5, 1.0-0.26470588235294117647058823529412);
  71.         t.addVertexWithUV(1, 0.5625, 1, 0.5, 0.26470588235294117647058823529412);
  72.         t.addVertexWithUV(1, 0.5625, 0, 0.18, 0.26470588235294117647058823529412);
  73.         t.addVertexWithUV(0, 0.5625, 0, 0.18, 1.0-0.26470588235294117647058823529412);
  74.         t.draw();
  75.     }
  76.  
  77.     private void renderBedFromHead(TileCustomBed bed, double x, double y, double z, float partialTicks) {
  78.         renderUnderSide(bed.getWorldObj(), bed.xCoord, bed.yCoord, bed.zCoord);
  79.         this.field_147501_a.field_147553_e.bindTexture(getResource(bed));
  80.         int b = 0xFFFFFF; // hardcoded value
  81.         int dir = BlockCustomBed.getDirection(bed.getBlockMetadata());
  82.         for (int i = 0; i < dir; i++) {
  83.             GL11.glRotated(-90, 0, 1, 0);
  84.             GL11.glTranslated(0, 0, -1);
  85.         }
  86.         Tessellator t = Tessellator.instance;
  87.         t.startDrawingQuads(); // end
  88.         t.setBrightness(b);
  89.         t.addVertexWithUV(1, 0.5625, 1, 1.0-0.18, 0.26470588235294117647058823529412);
  90.         t.addVertexWithUV(0, 0.5625, 1, 1.0-0.18, 1-0.26470588235294117647058823529412);
  91.         t.addVertexWithUV(0, 0, 1,      1, 1-0.26470588235294117647058823529412);
  92.         t.addVertexWithUV(1, 0, 1,      1, 0.26470588235294117647058823529412);
  93.         t.draw();
  94.         t.startDrawingQuads(); // right (when facing end of bed)
  95.         t.setBrightness(b);
  96.         t.addVertexWithUV(1, 0.5625, 0, 0.5, 0.26470588235294117647058823529412);
  97.         t.addVertexWithUV(1, 0.5625, 1, 1-0.18, 0.26470588235294117647058823529412);
  98.         t.addVertexWithUV(1, 0, 1,      1-0.18, 0);
  99.         t.addVertexWithUV(1, 0, 0,      0.5, 0);
  100.         t.draw();
  101.         t.startDrawingQuads(); // left (when facing end of bed)
  102.         t.setBrightness(b);
  103.         t.addVertexWithUV(0, 0, 0,      0.5, 1);
  104.         t.addVertexWithUV(0, 0, 1,      1-0.18, 1);
  105.         t.addVertexWithUV(0, 0.5625, 1, 1-0.18, 1.0-0.26470588235294117647058823529412);
  106.         t.addVertexWithUV(0, 0.5625, 0, 0.5, 1.0-0.26470588235294117647058823529412);
  107.         t.draw();
  108.         t.startDrawingQuads(); // top
  109.         t.setBrightness(b);
  110.         t.addVertexWithUV(1, 0.5625, 0, 0.5,    0.26470588235294117647058823529412);
  111.         t.addVertexWithUV(0, 0.5625, 0, 0.5,    1.0-0.26470588235294117647058823529412);
  112.         t.addVertexWithUV(0, 0.5625, 1, 1-0.18, 1.0-0.26470588235294117647058823529412);
  113.         t.addVertexWithUV(1, 0.5625, 1, 1-0.18, 0.26470588235294117647058823529412);
  114.         t.draw();
  115.     }
  116.    
  117.     private void renderUnderSide(World world, int x, int y, int z) {
  118.         this.field_147501_a.field_147553_e.bindTexture(TextureMap.locationBlocksTexture);
  119.         IIcon planks = Blocks.planks.getIcon(0, 0); // oak planks
  120.         Tessellator t = Tessellator.instance;
  121.         t.startDrawingQuads();
  122.         t.setBrightness(world.getBlock(x, y, z).getMixedBrightnessForBlock(world, x, y, z));
  123.         t.addVertexWithUV(0, 0.1875D, 0, planks.getInterpolatedU(0), planks.getInterpolatedV(0));
  124.         t.addVertexWithUV(1, 0.1875D, 0, planks.getInterpolatedU(16), planks.getInterpolatedV(0));
  125.         t.addVertexWithUV(1, 0.1875D, 1, planks.getInterpolatedU(16), planks.getInterpolatedV(16));
  126.         t.addVertexWithUV(0, 0.1875D, 1, planks.getInterpolatedU(0), planks.getInterpolatedV(16));
  127.         t.draw();
  128.     }
  129.    
  130.     private static ResourceLocation getResource(TileCustomBed bed) {
  131.         return new ResourceLocation("mobeds", "textures/beds/" + bed.getPillowColoring() + "-" + bed.getPulloverColoring() + "-" + bed.getBlanketColoring() + ".png");
  132.     }
  133.  
  134.     @Override
  135.     public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
  136.        
  137.     }
  138.  
  139.     @Override
  140.     public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
  141.         return true;
  142.     }
  143.  
  144.     @Override
  145.     public boolean shouldRender3DInInventory(int modelId) {
  146.         return false;
  147.     }
  148.  
  149.     @Override
  150.     public int getRenderId() {
  151.         return ProxyClient.BED_RENDER_ID;
  152.     }
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement