aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/objects/GT_CopiedBlockTexture.java
blob: ffbbe09ec6866e207607dd61412dcf9ad8ac7d0c (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
package gregtech.api.objects;

import gregtech.api.enums.Dyes;
import gregtech.api.interfaces.ITexture;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;

public class GT_CopiedBlockTexture implements ITexture {
	private final Block mBlock;
	private final byte mSide, mMeta;
	
	/**
	 *  DO NOT MANIPULATE THE VALUES INSIDE THIS ARRAY!!!
	 *  
	 *  Just set this variable to another different Array instead.
	 *  Otherwise some colored things will get Problems.
	 */
	public short[] mRGBa;
	
	private final boolean mAllowAlpha;
	
	public GT_CopiedBlockTexture(Block aBlock, int aSide, int aMeta, short[] aRGBa, boolean aAllowAlpha) {
		if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GT_CopiedBlockTexture");
		mBlock = aBlock;
		mRGBa = aRGBa;
		mSide = (byte)aSide;
		mMeta = (byte)aMeta;
		mAllowAlpha = aAllowAlpha;
	}
	
	public GT_CopiedBlockTexture(Block aBlock, int aSide, int aMeta, short[] aRGBa) {
		this(aBlock, aSide, aMeta, aRGBa, true);
	}
	
	public GT_CopiedBlockTexture(Block aBlock, int aSide, int aMeta) {
		this(aBlock, aSide, aMeta, Dyes._NULL.mRGBa);
	}
	
	private IIcon getIcon(int aSide) {
		if (mSide == 6) return mBlock.getIcon(aSide, mMeta);
		return mBlock.getIcon(mSide, mMeta);
	}
	
	@Override
	public void renderXPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
		IIcon aIcon = getIcon(5);
		Tessellator.instance.setColorRGBA((int)(mRGBa[0] * 0.6F), (int)(mRGBa[1] * 0.6F), (int)(mRGBa[2] * 0.6F), mAllowAlpha?255-mRGBa[3]:255);
//		aRenderer.flipTexture = !aRenderer.flipTexture;
    	aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, aIcon);
//		aRenderer.flipTexture = !aRenderer.flipTexture;
	}
	
	@Override
	public void renderXNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
		IIcon aIcon = getIcon(4);
		Tessellator.instance.setColorRGBA((int)(mRGBa[0] * 0.6F), (int)(mRGBa[1] * 0.6F), (int)(mRGBa[2] * 0.6F), mAllowAlpha?255-mRGBa[3]:255);
    	aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, aIcon);
	}
	
	@Override
	public void renderYPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
		IIcon aIcon = getIcon(1);
		Tessellator.instance.setColorRGBA((int)(mRGBa[0] * 1.0F), (int)(mRGBa[1] * 1.0F), (int)(mRGBa[2] * 1.0F), mAllowAlpha?255-mRGBa[3]:255);
    	aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, aIcon);
	}
	
	@Override
	public void renderYNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
		IIcon aIcon = getIcon(0);
		Tessellator.instance.setColorRGBA((int)(mRGBa[0] * 0.5F), (int)(mRGBa[1] * 0.5F), (int)(mRGBa[2] * 0.5F), mAllowAlpha?255-mRGBa[3]:255);
    	aRenderer.renderFaceYNeg(aBlock, aX, aY, aZ, aIcon);
	}
	
	@Override
	public void renderZPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
		IIcon aIcon = getIcon(3);
		Tessellator.instance.setColorRGBA((int)(mRGBa[0] * 0.8F), (int)(mRGBa[1] * 0.8F), (int)(mRGBa[2] * 0.8F), mAllowAlpha?255-mRGBa[3]:255);
    	aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, aIcon);
	}
	
	@Override
	public void renderZNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
		IIcon aIcon = getIcon(2);
		Tessellator.instance.setColorRGBA((int)(mRGBa[0] * 0.8F), (int)(mRGBa[1] * 0.8F), (int)(mRGBa[2] * 0.8F), mAllowAlpha?255-mRGBa[3]:255);
//		aRenderer.flipTexture = !aRenderer.flipTexture;
		aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, aIcon);
//		aRenderer.flipTexture = !aRenderer.flipTexture;
	}
	
	@Override
	public boolean isValidTexture() {
		return mBlock != null;
	}
}