aboutsummaryrefslogtreecommitdiff
path: root/goodgen/src/main/java/goodgenerator/client/render/BlockRenderHandler.java
blob: 01893339f540488cdd8ef2bb2b99d47326fdf03c (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
123
124
125
126
127
128
129
130
131
132
133
134
135
package goodgenerator.client.render;

import static gregtech.common.render.GT_Renderer_Block.*;
import static net.minecraftforge.common.util.ForgeDirection.*;
import static net.minecraftforge.common.util.ForgeDirection.EAST;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import goodgenerator.blocks.regularBlock.ITextureBlock;
import gregtech.GT_Mod;

public class BlockRenderHandler implements ISimpleBlockRenderingHandler {

    public static final float blockMin = 0.0F;
    public static final float blockMax = 1.0F;
    public static BlockRenderHandler INSTANCE;
    public final int mRenderID;

    public BlockRenderHandler() {
        this.mRenderID = RenderingRegistry.getNextAvailableRenderId();
        INSTANCE = this;
        RenderingRegistry.registerBlockHandler(this);
    }

    @Override
    public void renderInventoryBlock(Block aBlock, int metadata, int modelId, RenderBlocks aRenderer) {
        aRenderer.enableAO = false;
        aRenderer.useInventoryTint = true;

        GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
        GL11.glTranslatef(-0.5F, -0.5F, -0.5F);

        if (aBlock instanceof ITextureBlock) {
            ITextureBlock tc = (ITextureBlock) aBlock;
            aBlock.setBlockBoundsForItemRender();
            aRenderer.setRenderBoundsFromBlock(aBlock);
            renderNegativeYFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, metadata, DOWN), true);
            renderPositiveYFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, metadata, UP), true);
            renderNegativeZFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, metadata, NORTH), true);
            renderPositiveZFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, metadata, SOUTH), true);
            renderNegativeXFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, metadata, WEST), true);
            renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, metadata, EAST), true);
        }

        aBlock.setBlockBounds(blockMin, blockMin, blockMin, blockMax, blockMax, blockMax);
        aRenderer.setRenderBoundsFromBlock(aBlock);

        GL11.glTranslatef(0.5F, 0.5F, 0.5F);
        aRenderer.useInventoryTint = false;
    }

    @Override
    public boolean renderWorldBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, int aModelID,
        RenderBlocks aRenderer) {
        aRenderer.enableAO = Minecraft.isAmbientOcclusionEnabled() && GT_Mod.gregtechproxy.mRenderTileAmbientOcclusion;
        aRenderer.useInventoryTint = false;
        if (aBlock instanceof ITextureBlock) {
            aBlock.setBlockBounds(blockMin, blockMin, blockMin, blockMax, blockMax, blockMax);
            aRenderer.setRenderBoundsFromBlock(aBlock);
            ITextureBlock tc = (ITextureBlock) aBlock;
            renderNegativeYFacing(
                aWorld,
                aRenderer,
                aBlock,
                aX,
                aY,
                aZ,
                tc.getTexture(aBlock, DOWN, aWorld, aX, aY, aZ),
                true);
            renderPositiveYFacing(
                aWorld,
                aRenderer,
                aBlock,
                aX,
                aY,
                aZ,
                tc.getTexture(aBlock, UP, aWorld, aX, aY, aZ),
                true);
            renderNegativeZFacing(
                aWorld,
                aRenderer,
                aBlock,
                aX,
                aY,
                aZ,
                tc.getTexture(aBlock, NORTH, aWorld, aX, aY, aZ),
                true);
            renderPositiveZFacing(
                aWorld,
                aRenderer,
                aBlock,
                aX,
                aY,
                aZ,
                tc.getTexture(aBlock, SOUTH, aWorld, aX, aY, aZ),
                true);
            renderNegativeXFacing(
                aWorld,
                aRenderer,
                aBlock,
                aX,
                aY,
                aZ,
                tc.getTexture(aBlock, WEST, aWorld, aX, aY, aZ),
                true);
            renderPositiveXFacing(
                aWorld,
                aRenderer,
                aBlock,
                aX,
                aY,
                aZ,
                tc.getTexture(aBlock, EAST, aWorld, aX, aY, aZ),
                true);
        }
        return false;
    }

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

    @Override
    public int getRenderId() {
        return this.mRenderID;
    }
}