Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.unh0lytigg.mobeds;
- import net.minecraft.block.Block;
- import net.minecraft.client.renderer.RenderBlocks;
- import net.minecraft.client.renderer.Tessellator;
- import net.minecraft.client.renderer.texture.TextureMap;
- import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
- import net.minecraft.init.Blocks;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.IIcon;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import org.lwjgl.opengl.GL11;
- import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
- public class RenderCustomBed extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler {
- @Override
- public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTicks) {
- if (tile instanceof TileCustomBed) {
- int metadata = tile.getBlockMetadata();
- GL11.glPushMatrix();
- GL11.glTranslated(x, y, z);
- if (!BlockCustomBed.isBlockHeadOfBed(metadata)) {
- renderBedFromFoot((TileCustomBed)tile, x, y, z, partialTicks);
- } else {
- renderBedFromHead((TileCustomBed)tile, x, y, z, partialTicks);
- }
- GL11.glPopMatrix();
- }
- }
- private void renderBedFromFoot(TileCustomBed bed, double x, double y, double z, float partialTicks) {
- renderUnderSide(bed.getWorldObj(), bed.xCoord, bed.yCoord, bed.zCoord);
- ResourceLocation r = getResource(bed);
- this.field_147501_a.field_147553_e.bindTexture(r);
- int b = bed.getBlockType().getMixedBrightnessForBlock(bed.getWorldObj(), bed.xCoord, bed.yCoord, bed.zCoord); // dynamic value
- int dir = BlockCustomBed.getDirection(bed.getBlockMetadata());
- for (int i = 0; i < dir; i++) {
- GL11.glRotated(-90, 0, 1, 0);
- GL11.glTranslated(0, 0, -1);
- }
- Tessellator t = Tessellator.instance;
- t.startDrawingQuads(); // end
- t.setBrightness(b);
- t.addVertexWithUV(0, 0.5625, 0, 0.18, 0.73529411764705882352941176470588);
- t.addVertexWithUV(1, 0.5625, 0, 0.18, 0.26470588235294117647058823529412);
- t.addVertexWithUV(1, 0, 0, 0, 0.26470588235294117647058823529412);
- t.addVertexWithUV(0, 0, 0, 0, 0.73529411764705882352941176470588);
- t.draw();
- t.startDrawingQuads(); // left (when facing end of bed)
- t.setBrightness(b);
- t.addVertexWithUV(1, 0.5625, 0, 0.18, 0.26470588235294117647058823529412);
- t.addVertexWithUV(1, 0.5625, 1, 0.5, 0.26470588235294117647058823529412);
- t.addVertexWithUV(1, 0, 1, 0.5, 0);
- t.addVertexWithUV(1, 0, 0, 0.18, 0);
- t.draw();
- t.startDrawingQuads(); // right (when facing end of bed)
- t.setBrightness(b);
- t.addVertexWithUV(0, 0, 0, 0.18, 1);
- t.addVertexWithUV(0, 0, 1, 0.5, 1);
- t.addVertexWithUV(0, 0.5625, 1, 0.5, 1.0-0.26470588235294117647058823529412);
- t.addVertexWithUV(0, 0.5625, 0, 0.18, 1.0-0.26470588235294117647058823529412);
- t.draw();
- t.startDrawingQuads(); // top
- t.setBrightness(b);
- t.addVertexWithUV(0, 0.5625, 1, 0.5, 1.0-0.26470588235294117647058823529412);
- t.addVertexWithUV(1, 0.5625, 1, 0.5, 0.26470588235294117647058823529412);
- t.addVertexWithUV(1, 0.5625, 0, 0.18, 0.26470588235294117647058823529412);
- t.addVertexWithUV(0, 0.5625, 0, 0.18, 1.0-0.26470588235294117647058823529412);
- t.draw();
- }
- private void renderBedFromHead(TileCustomBed bed, double x, double y, double z, float partialTicks) {
- renderUnderSide(bed.getWorldObj(), bed.xCoord, bed.yCoord, bed.zCoord);
- this.field_147501_a.field_147553_e.bindTexture(getResource(bed));
- int b = 0xFFFFFF; // hardcoded value
- int dir = BlockCustomBed.getDirection(bed.getBlockMetadata());
- for (int i = 0; i < dir; i++) {
- GL11.glRotated(-90, 0, 1, 0);
- GL11.glTranslated(0, 0, -1);
- }
- Tessellator t = Tessellator.instance;
- t.startDrawingQuads(); // end
- t.setBrightness(b);
- t.addVertexWithUV(1, 0.5625, 1, 1.0-0.18, 0.26470588235294117647058823529412);
- t.addVertexWithUV(0, 0.5625, 1, 1.0-0.18, 1-0.26470588235294117647058823529412);
- t.addVertexWithUV(0, 0, 1, 1, 1-0.26470588235294117647058823529412);
- t.addVertexWithUV(1, 0, 1, 1, 0.26470588235294117647058823529412);
- t.draw();
- t.startDrawingQuads(); // right (when facing end of bed)
- t.setBrightness(b);
- t.addVertexWithUV(1, 0.5625, 0, 0.5, 0.26470588235294117647058823529412);
- t.addVertexWithUV(1, 0.5625, 1, 1-0.18, 0.26470588235294117647058823529412);
- t.addVertexWithUV(1, 0, 1, 1-0.18, 0);
- t.addVertexWithUV(1, 0, 0, 0.5, 0);
- t.draw();
- t.startDrawingQuads(); // left (when facing end of bed)
- t.setBrightness(b);
- t.addVertexWithUV(0, 0, 0, 0.5, 1);
- t.addVertexWithUV(0, 0, 1, 1-0.18, 1);
- t.addVertexWithUV(0, 0.5625, 1, 1-0.18, 1.0-0.26470588235294117647058823529412);
- t.addVertexWithUV(0, 0.5625, 0, 0.5, 1.0-0.26470588235294117647058823529412);
- t.draw();
- t.startDrawingQuads(); // top
- t.setBrightness(b);
- t.addVertexWithUV(1, 0.5625, 0, 0.5, 0.26470588235294117647058823529412);
- t.addVertexWithUV(0, 0.5625, 0, 0.5, 1.0-0.26470588235294117647058823529412);
- t.addVertexWithUV(0, 0.5625, 1, 1-0.18, 1.0-0.26470588235294117647058823529412);
- t.addVertexWithUV(1, 0.5625, 1, 1-0.18, 0.26470588235294117647058823529412);
- t.draw();
- }
- private void renderUnderSide(World world, int x, int y, int z) {
- this.field_147501_a.field_147553_e.bindTexture(TextureMap.locationBlocksTexture);
- IIcon planks = Blocks.planks.getIcon(0, 0); // oak planks
- Tessellator t = Tessellator.instance;
- t.startDrawingQuads();
- t.setBrightness(world.getBlock(x, y, z).getMixedBrightnessForBlock(world, x, y, z));
- t.addVertexWithUV(0, 0.1875D, 0, planks.getInterpolatedU(0), planks.getInterpolatedV(0));
- t.addVertexWithUV(1, 0.1875D, 0, planks.getInterpolatedU(16), planks.getInterpolatedV(0));
- t.addVertexWithUV(1, 0.1875D, 1, planks.getInterpolatedU(16), planks.getInterpolatedV(16));
- t.addVertexWithUV(0, 0.1875D, 1, planks.getInterpolatedU(0), planks.getInterpolatedV(16));
- t.draw();
- }
- private static ResourceLocation getResource(TileCustomBed bed) {
- return new ResourceLocation("mobeds", "textures/beds/" + bed.getPillowColoring() + "-" + bed.getPulloverColoring() + "-" + bed.getBlanketColoring() + ".png");
- }
- @Override
- public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
- }
- @Override
- public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
- return true;
- }
- @Override
- public boolean shouldRender3DInInventory(int modelId) {
- return false;
- }
- @Override
- public int getRenderId() {
- return ProxyClient.BED_RENDER_ID;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement