aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/goodgenerator/client/render/BlockRenderHandler.java
blob: 9fa68f9e53190b7cfeeaefc7512844825a558be1 (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
package goodgenerator.client.render;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import goodgenerator.blocks.regularBlock.ITextureBlock;
import gregtech.GT_Mod;
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 static gregtech.common.render.GT_Renderer_Block.*;
import static net.minecraftforge.common.util.ForgeDirection.*;
import static net.minecraftforge.common.util.ForgeDirection.EAST;

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, (byte) DOWN.ordinal()), true);
            renderPositiveYFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, (byte) UP.ordinal()), true);
            renderNegativeZFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, (byte) NORTH.ordinal()), true);
            renderPositiveZFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, (byte) SOUTH.ordinal()), true);
            renderNegativeXFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, (byte) WEST.ordinal()), true);
            renderPositiveXFacing(null, aRenderer, aBlock, 0, 0, 0, tc.getTexture(aBlock, (byte) EAST.ordinal()), 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, (byte) DOWN.ordinal(), aWorld, aX, aY, aZ), true);
            renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, tc.getTexture(aBlock, (byte) UP.ordinal(), aWorld, aX, aY, aZ), true);
            renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, tc.getTexture(aBlock, (byte) NORTH.ordinal(), aWorld, aX, aY, aZ), true);
            renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, tc.getTexture(aBlock, (byte) SOUTH.ordinal(), aWorld, aX, aY, aZ), true);
            renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, tc.getTexture(aBlock, (byte) WEST.ordinal(), aWorld, aX, aY, aZ), true);
            renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, tc.getTexture(aBlock, (byte) EAST.ordinal(), aWorld, aX, aY, aZ), true);
        }
        return false;
    }

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

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