summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/tileentity/renders/TileEntityJewelrsCraftingTableRender.java
blob: fbe3db6f0a909f965388e0af15711aa24c260a1b (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package darkknight.jewelrycraft.tileentity.renders;

import org.lwjgl.opengl.GL11;

import darkknight.jewelrycraft.model.ModelJewlersCraftingBench;
import darkknight.jewelrycraft.tileentity.TileEntityJewelrsCraftingTable;
import darkknight.jewelrycraft.util.Variables;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class TileEntityJewelrsCraftingTableRender
		extends TileEntitySpecialRenderer {
	ModelJewlersCraftingBench	modelTable	= new ModelJewlersCraftingBench();
	String				texture		= "textures/tileentities/JewelrsCraftingBench.png";

	/**
	 * @param te
	 * @param x
	 * @param y
	 * @param z
	 * @param scale
	 */
	@Override
	public void renderTileEntityAt(TileEntity te, double x, double y,
			double z, float scale) {
		GL11.glPushMatrix();
		GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F,
				(float) z + 0.5F);
		ResourceLocation blockTexture = new ResourceLocation(
				Variables.MODID, texture);
		Minecraft.getMinecraft().renderEngine
				.bindTexture(blockTexture);
		TileEntityJewelrsCraftingTable jt = (TileEntityJewelrsCraftingTable) te;
		GL11.glPushMatrix();
		GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
		try {
			int block = te.getBlockMetadata();
			if (block == 1)
				GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
			else if (block == 2) {
				GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
				GL11.glRotatef(180F, 1.0F, 0.0F, 0.0F);
			} else if (block == 3) {
				GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
				GL11.glRotatef(180F, 1.0F, 0.0F, 1.0F);
			}
		} catch (Exception e) {
		}
		modelTable.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F,
				0.0F, 0.0625F);
		if (jt != null) {
			if (jt.hasJewelry && jt.jewelry
					.getIconIndex() != null
					&& jt.jewelry.getIconIndex()
							.getIconName() != "") {
				GL11.glPushMatrix();
				GL11.glDisable(GL11.GL_LIGHTING);
				EntityItem entityitem = new EntityItem(
						te.getWorldObj(), 0.0D,
						0.0D, 0.0D, jt.jewelry);
				entityitem.getEntityItem().stackSize = 1;
				entityitem.hoverStart = 0.0F;
				GL11.glRotatef(180F, 1F, 0F, 0F);
				GL11.glScalef(0.5F, 0.5F, 0.5F);
				GL11.glTranslatef(0.55F, -1.5F, -0.45F);
				GL11.glRotatef(jt.angle, 0F, 1F, 0F);
				if (RenderManager.instance.options.fancyGraphics)
					RenderManager.instance
							.renderEntityWithPosYaw(
									entityitem,
									0.0D,
									0.0D,
									0.0D,
									0.0F,
									0.0F);
				else {
					GL11.glRotatef(180F, 0F, 1F, 0F);
					RenderManager.instance.options.fancyGraphics = true;
					RenderManager.instance
							.renderEntityWithPosYaw(
									entityitem,
									0.0D,
									0.0D,
									0.0D,
									0.0F,
									0.0F);
					RenderManager.instance.options.fancyGraphics = false;
				}
				GL11.glEnable(GL11.GL_LIGHTING);
				GL11.glPopMatrix();
			}
			if (jt.hasEndItem && jt.endItem.getIconIndex()
					.getIconName() != "") {
				GL11.glPushMatrix();
				GL11.glDisable(GL11.GL_LIGHTING);
				EntityItem entityitem = new EntityItem(
						te.getWorldObj(), 0.0D,
						0.0D, 0.0D, jt.endItem);
				entityitem.getEntityItem().stackSize = 1;
				entityitem.hoverStart = 0.0F;
				GL11.glRotatef(180F, 1F, 0F, 0F);
				GL11.glScalef(0.5F, 0.5F, 0.5F);
				GL11.glTranslatef(0.0F, -1.6F, 0.6F);
				GL11.glRotatef(jt.angle, 0F, 1F, 0F);
				if (RenderManager.instance.options.fancyGraphics)
					RenderManager.instance
							.renderEntityWithPosYaw(
									entityitem,
									0.0D,
									0.0D,
									0.0D,
									0.0F,
									0.0F);
				else {
					GL11.glRotatef(180F, 0F, 1F, 0F);
					RenderManager.instance.options.fancyGraphics = true;
					RenderManager.instance
							.renderEntityWithPosYaw(
									entityitem,
									0.0D,
									0.0D,
									0.0D,
									0.0F,
									0.0F);
					RenderManager.instance.options.fancyGraphics = false;
				}
				GL11.glEnable(GL11.GL_LIGHTING);
				GL11.glPopMatrix();
			}
			if (jt.hasGem && jt.gem.getIconIndex()
					.getIconName() != "") {
				GL11.glPushMatrix();
				GL11.glDisable(GL11.GL_LIGHTING);
				EntityItem entityitem = new EntityItem(
						te.getWorldObj(), 0.0D,
						0.0D, 0.0D, jt.gem);
				entityitem.getEntityItem().stackSize = 1;
				entityitem.hoverStart = 0.0F;
				GL11.glRotatef(180F, 1F, 0F, 0F);
				GL11.glScalef(0.5F, 0.5F, 0.5F);
				GL11.glTranslatef(-0.55F, -1.5F, -0.45F);
				GL11.glRotatef(jt.angle, 0F, 1F, 0F);
				if (RenderManager.instance.options.fancyGraphics)
					RenderManager.instance
							.renderEntityWithPosYaw(
									entityitem,
									0.0D,
									0.0D,
									0.0D,
									0.0F,
									0.0F);
				else {
					GL11.glRotatef(180F, 0F, 1F, 0F);
					RenderManager.instance.options.fancyGraphics = true;
					RenderManager.instance
							.renderEntityWithPosYaw(
									entityitem,
									0.0D,
									0.0D,
									0.0D,
									0.0F,
									0.0F);
					RenderManager.instance.options.fancyGraphics = false;
				}
				GL11.glEnable(GL11.GL_LIGHTING);
				GL11.glPopMatrix();
			}
		}
		GL11.glPopMatrix();
		GL11.glPopMatrix();
	}

	/**
	 * @param world
	 * @param i
	 * @param j
	 * @param k
	 * @param block
	 */
	public void adjustLightFixture(World world, int i, int j, int k,
			Block block) {
		Tessellator tess = Tessellator.instance;
		float brightness = block.getLightOpacity(world, i, j, k);
		int skyLight = world.getLightBrightnessForSkyBlocks(i, j,
				k, 0);
		int modulousModifier = skyLight % 65536;
		int divModifier = skyLight / 65536;
		tess.setColorOpaque_F(brightness, brightness, brightness);
		OpenGlHelper.setLightmapTextureCoords(
				OpenGlHelper.lightmapTexUnit,
				modulousModifier, divModifier);
	}
}