aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/tectech/thing/block/RenderGodforgeGlass.java
blob: 12c0327f654d421f915af33ddf1d63447bb4f473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package tectech.thing.block;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class RenderGodforgeGlass implements ISimpleBlockRenderingHandler {

    @Override
    public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
        GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
        Tessellator tessellator = Tessellator.instance;
        GL11.glPushMatrix();
        // Get icons from custom register (useful for renderers and fluids)
        IIcon side = BlockGodforgeGlass.Icon;
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, -1.0F, 0.0F);
        renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, side);
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 0.0F, -1.0F);
        renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, side);
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 0.0F, 1.0F);
        renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, side);
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(-1.0F, 0.0F, 0.0F);
        renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, side);
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(1.0F, 0.0F, 0.0F);
        renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, side);
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 1.0F, 0.0F);
        renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, side);
        tessellator.draw();
        GL11.glTranslatef(0.5F, 0.5F, 0.5F);
        GL11.glPopMatrix();
    }

    @Override
    public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
        RenderBlocks renderer) {

        renderer.renderStandardBlock(block, x, y, z);
        Tessellator tes = Tessellator.instance;
        tes.setNormal(0F, 1F, 0F);
        tes.setBrightness(15728880);
        tes.setColorOpaque_F(0F, 1F, 1F);
        IIcon side = BlockGodforgeGlass.Icon;

        // South
        if (world.getBlock(x, y, z + 1)
            .getClass() != BlockGodforgeGlass.class) {
            tes.addVertexWithUV(x, y, z + 0.999, side.getMinU(), side.getMaxV()); // 0.999 instead of 1 for fighting
            // (textures overlapping)
            tes.addVertexWithUV(x, y + 1, z + 0.999, side.getMinU(), side.getMinV());
            tes.addVertexWithUV(x + 1, y + 1, z + 0.999, side.getMaxU(), side.getMinV());
            tes.addVertexWithUV(x + 1, y, z + 0.999, side.getMaxU(), side.getMaxV());
        }
        // East
        if (world.getBlock(x + 1, y, z)
            .getClass() != BlockGodforgeGlass.class) {
            tes.addVertexWithUV(x + 0.999, y, z + 1, side.getMinU(), side.getMaxV());
            tes.addVertexWithUV(x + 0.999, y + 1, z + 1, side.getMinU(), side.getMinV());
            tes.addVertexWithUV(x + 0.999, y + 1, z, side.getMaxU(), side.getMinV());
            tes.addVertexWithUV(x + 0.999, y, z, side.getMaxU(), side.getMaxV());
        }
        // North
        if (world.getBlock(x, y, z - 1)
            .getClass() != BlockGodforgeGlass.class) {
            tes.addVertexWithUV(x + 1, y, z + 0.001, side.getMinU(), side.getMaxV());
            tes.addVertexWithUV(x + 1, y + 1, z + 0.001, side.getMinU(), side.getMinV());
            tes.addVertexWithUV(x, y + 1, z + 0.001, side.getMaxU(), side.getMinV());
            tes.addVertexWithUV(x, y, z + 0.001, side.getMaxU(), side.getMaxV());
        }
        // West
        if (world.getBlock(x - 1, y, z)
            .getClass() != BlockGodforgeGlass.class) {
            tes.addVertexWithUV(x + 0.001, y, z, side.getMinU(), side.getMaxV());
            tes.addVertexWithUV(x + 0.001, y + 1, z, side.getMinU(), side.getMinV());
            tes.addVertexWithUV(x + 0.001, y + 1, z + 1, side.getMaxU(), side.getMinV());
            tes.addVertexWithUV(x + 0.001, y, z + 1, side.getMaxU(), side.getMaxV());
        }
        // Top
        if (world.getBlock(x, y + 1, z)
            .getClass() != BlockGodforgeGlass.class) {
            tes.addVertexWithUV(x, y + 0.999, z + 1, side.getMinU(), side.getMaxV());
            tes.addVertexWithUV(x, y + 0.999, z, side.getMinU(), side.getMinV());
            tes.addVertexWithUV(x + 1, y + 0.999, z, side.getMaxU(), side.getMinV());
            tes.addVertexWithUV(x + 1, y + 0.999, z + 1, side.getMaxU(), side.getMaxV());
        }
        // Bottom
        if (world.getBlock(x, y - 1, z)
            .getClass() != BlockGodforgeGlass.class) {
            tes.addVertexWithUV(x, y + 0.001, z, side.getMinU(), side.getMaxV());
            tes.addVertexWithUV(x, y + 0.001, z + 1, side.getMinU(), side.getMinV());
            tes.addVertexWithUV(x + 1, y + 0.001, z + 1, side.getMaxU(), side.getMinV());
            tes.addVertexWithUV(x + 1, y + 0.001, z, side.getMaxU(), side.getMaxV());
        }
        return true;
    }

    @Override
    public boolean shouldRender3DInInventory(int modelId) {
        return true;
    }

    @Override
    public int getRenderId() {
        return BlockGodforgeGlass.renderID;
    }
}