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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
package kr.syeyoung.dungeonsguide.utils;
import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import org.lwjgl.opengl.GL11;
import javax.vecmath.Vector3f;
import java.awt.*;
public class RenderUtils {
public static void renderDoor(DungeonDoor dungeonDoor, float partialTicks) {
Entity player = Minecraft.getMinecraft().thePlayer;
double playerX = player.prevPosX + (player.posX - player.prevPosX) * partialTicks;
double playerY = player.prevPosY + (player.posY - player.prevPosY) * partialTicks;
double playerZ = player.prevPosZ + (player.posZ - player.prevPosZ) * partialTicks;
//because of the way 3D rendering is done, all coordinates are relative to the camera. This "resets" the "0,0,0" position to the location that is (0,0,0) in the world.
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glPushMatrix();
GL11.glTranslated(-playerX, -playerY, -playerZ);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_CULL_FACE);
GlStateManager.enableAlpha();
if (dungeonDoor.isExist())
GL11.glColor4ub((byte)0,(byte)255,(byte)0, (byte)255);
else
GL11.glColor4ub((byte)255,(byte)0,(byte)0, (byte)255);
double x = dungeonDoor.getPosition().getX() + 0.5;
double y = dungeonDoor.getPosition().getY() -0.99;
double z = dungeonDoor.getPosition().getZ() + 0.5;
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(x - 2.5, y, z - 2.5);
GL11.glVertex3d(x - 2.5, y, z + 2.5);
GL11.glVertex3d(x + 2.5, y, z + 2.5);
GL11.glVertex3d(x + 2.5, y, z - 2.5);
GL11.glEnd();
if (dungeonDoor.isExist()) {
GL11.glBegin(GL11.GL_QUADS);
GL11.glColor4ub((byte)0,(byte)0,(byte)255, (byte)255);
if (dungeonDoor.isZDir()) {
GL11.glVertex3d(x - 0.5, y + 0.1, z - 2.5);
GL11.glVertex3d(x - 0.5, y+ 0.1, z + 2.5);
GL11.glVertex3d(x + 0.5, y+ 0.1, z + 2.5);
GL11.glVertex3d(x + 0.5, y+ 0.1, z - 2.5);
} else {
GL11.glVertex3d(x - 2.5, y+ 0.1, z - 0.5);
GL11.glVertex3d(x - 2.5, y+ 0.1, z + 0.5);
GL11.glVertex3d(x + 2.5, y+ 0.1, z + 0.5);
GL11.glVertex3d(x + 2.5, y+ 0.1, z - 0.5);
}
GL11.glEnd();
} else {
GL11.glLineWidth(5);
GL11.glBegin(GL11.GL_LINE_LOOP);
GL11.glVertex3d(x - 2.5, y, z - 2.5);
GL11.glVertex3d(x + 2.5, y + 5, z - 2.5);
GL11.glVertex3d(x + 2.5, y, z + 2.5);
GL11.glVertex3d(x - 2.5, y + 5, z + 2.5);
GL11.glEnd();
GL11.glBegin(GL11.GL_LINE_LOOP);
GL11.glVertex3d(x - 2.5, y +5, z - 2.5);
GL11.glVertex3d(x + 2.5, y, z - 2.5);
GL11.glVertex3d(x + 2.5, y + 5, z + 2.5);
GL11.glVertex3d(x - 2.5, y, z + 2.5);
GL11.glEnd();
GL11.glLineWidth(1);
}
// GlStateManager.disableAlpha();
GlStateManager.disableBlend();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
public static void highlightBlock(BlockPos blockpos, Color c, float partialTicks) {
Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity();
double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks);
double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks);
double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks);
GlStateManager.pushMatrix();
GlStateManager.pushAttrib();
GlStateManager.translate(-x_fix, -y_fix, -z_fix);
GlStateManager.disableLighting();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.disableTexture2D();
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(false);
GL11.glColor3ub((byte)c.getRed(), (byte)c.getGreen(), (byte)c.getBlue());
GL11.glTranslated(blockpos.getX(), blockpos.getY(), blockpos.getZ());
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(0, 0, 0);
GL11.glVertex3d(0, 0, 1);
GL11.glVertex3d(0, 1, 1);
GL11.glVertex3d(0, 1, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT
GL11.glVertex3d(1, 0, 1);
GL11.glVertex3d(1, 0, 0);
GL11.glVertex3d(1, 1, 0);
GL11.glVertex3d(1, 1, 1);
GL11.glVertex3d(0, 1, 1);
GL11.glVertex3d(0, 0, 1);
GL11.glVertex3d(1, 0, 1);
GL11.glVertex3d(1, 1, 1); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT
GL11.glVertex3d(0, 0, 0);
GL11.glVertex3d(0, 1, 0);
GL11.glVertex3d(1, 1, 0);
GL11.glVertex3d(1, 0, 0);
GL11.glVertex3d(0,1,0);
GL11.glVertex3d(0,1,1);
GL11.glVertex3d(1,1,1);
GL11.glVertex3d(1,1,0);
GL11.glVertex3d(0,0,1);
GL11.glVertex3d(0,0,0);
GL11.glVertex3d(1,0,0);
GL11.glVertex3d(1,0,1);
GL11.glEnd();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
GlStateManager.enableLighting();
GlStateManager.popMatrix();
GlStateManager.popAttrib();
//...
}
public static void drawTextAtWorld(String text, float x, float y, float z, int color, float scale, boolean increase, boolean renderBlackBox, float partialTicks) {
float lScale = scale;
RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
Vector3f renderPos = getRenderPos(x, y, z, partialTicks);
if (increase) {
double distance = Math.sqrt(renderPos.x * renderPos.x + renderPos.y * renderPos.y + renderPos.z * renderPos.z);
double multiplier = distance / 120f; //mobs only render ~120 blocks away
lScale *= 0.45f * multiplier;
}
GL11.glColor4f(1f, 1f, 1f, 0.5f);
GL11.glPushMatrix();
GL11.glTranslatef(renderPos.x, renderPos.y, renderPos.z);
GL11.glRotatef(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f);
GL11.glRotatef(renderManager.playerViewX, 1.0f, 0.0f, 0.0f);
GL11.glScalef(-lScale, -lScale, lScale);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDepthMask(false);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
int textWidth = fontRenderer.getStringWidth(text);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldRenderer = tessellator.getWorldRenderer();
if (renderBlackBox) {
double j = textWidth / 2;
GlStateManager.disableTexture2D();
worldRenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
worldRenderer.pos((double)(-j - 1), (double)(-1), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex();
worldRenderer.pos((double)(-j - 1), (double)8, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex();
worldRenderer.pos((double)(j + 1), (double)8, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex();
worldRenderer.pos((double)(j + 1), (double)(-1), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex();
tessellator.draw();
GlStateManager.enableTexture2D();
}
fontRenderer.drawString(text, -textWidth / 2, 0, color);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glPopMatrix();
}
private static Vector3f getRenderPos(float x, float y, float z, float partialTicks) {
EntityPlayerSP sp = Minecraft.getMinecraft().thePlayer;
return new Vector3f(
x - (float) (sp.lastTickPosX + (sp.posX - sp.lastTickPosX) * partialTicks),
y - (float) (sp.lastTickPosY + (sp.posY - sp.lastTickPosY) * partialTicks),
z - (float) (sp.lastTickPosZ + (sp.posZ - sp.lastTickPosZ) * partialTicks)
);
}
}
|