forked from MinecraftModDevelopmentMods/CommunityMod
/
AnimationHelper.java
118 lines (90 loc) · 4.74 KB
/
AnimationHelper.java
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
package com.mcmoddev.communitymod.davidm.extrarandomness.core.helper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
public class AnimationHelper {
private static final ResourceLocation BEAM_TEXTURE = new ResourceLocation("textures/entity/beacon_beam.png");
public static void drawPlane(ResourceLocation texture, Vec3d pos_1, Vec3d pos_2, Vec3d pos_3, Vec3d pos_4) {
drawPlane(texture, pos_1, pos_2, pos_3, pos_4, new double[][] {{0, 0}, {0, 1}, {1, 1}, {1, 0}});
}
public static void drawPlane(ResourceLocation texture, Vec3d pos_1, Vec3d pos_2, Vec3d pos_3, Vec3d pos_4, double[][] vertPos) {
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(7, DefaultVertexFormats.POSITION_TEX);
buffer.pos(pos_1.x, pos_1.y, pos_1.z).tex(vertPos[0][0], vertPos[0][1]).endVertex();
buffer.pos(pos_2.x, pos_2.y, pos_2.z).tex(vertPos[1][0], vertPos[1][1]).endVertex();
buffer.pos(pos_3.x, pos_3.y, pos_3.z).tex(vertPos[2][0], vertPos[2][1]).endVertex();
buffer.pos(pos_4.x, pos_4.y, pos_4.z).tex(vertPos[3][0], vertPos[3][1]).endVertex();
tessellator.draw();
}
public static void drawDoublePlane(ResourceLocation texture, double x, double y, double z, double time, double radius, EnumFacing facing) {
drawPlane(texture, x, y, z, time, radius, facing);
drawPlane(texture, x, y, z, time, radius, facing.getOpposite());
}
public static void drawPlane(ResourceLocation texture, double x, double y, double z, double time, double radius, EnumFacing facing) {
drawPlane(texture, x, y, z, time, radius, facing, new double[][] {{0, 0}, {0, 1}, {1, 1}, {1, 0}});
}
public static void drawPlane(ResourceLocation texture, double x, double y, double z, double time, double radius, EnumFacing facing, double[][] vertPos) {
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(7, DefaultVertexFormats.POSITION_TEX);
double slant = Math.sqrt(radius * radius * 2);
for (int i = 0; i < 4; i++) {
double offset = Math.toRadians(i * 90 + time);
double newX = slant * Math.sin(offset);
double newY = 0;
double newZ = slant * Math.cos(offset);
double temp;
switch (facing) {
case UP: break;
case DOWN: temp = newX; newX = newZ; newZ = temp; break;
case WEST: temp = newX; newX = newY; newY = newZ; newZ = temp; break;
case SOUTH: temp = newY; newY = newZ; newZ = temp; break;
case NORTH: temp = newZ; newZ = newY; newY = newX; newX = temp; break;
case EAST: temp = newX; newX = newY; newY = temp;
}
buffer.pos(x + newX, y + newY, z + newZ).tex(vertPos[i][0], vertPos[i][1]).endVertex();
}
tessellator.draw();
}
public static void drawBeam(double x, double y, double z, double length, double radius, double time, EnumFacing facing) {
drawBeam(x, y, z, length, radius, time, time, facing);
}
public static void drawBeam(double x, double y, double z, double length, double radius, double time, double rotationTime, EnumFacing facing) {
GlStateManager.pushMatrix();
Vec3d[] points = new Vec3d[4];
double temp;
switch(facing) {
case DOWN: GlStateManager.rotate(180, 0, 0, 1); y = -y; x = -x; break;
case WEST: GlStateManager.rotate(90, 0, 0, 1); temp = y; y = -x; x = temp; break;
case SOUTH: GlStateManager.rotate(90, 1, 0, 0); temp = y; y = z; z = -temp; break;
case NORTH: GlStateManager.rotate(270, 1, 0, 0); temp = y; y = -z; z = temp; break;
case EAST: GlStateManager.rotate(270, 0, 0, 1); temp = y; y = x; x = -temp; break;
default: break;
}
for (int i = 0; i < 4; i++) {
double rotation = rotationTime * 0.085 + i * Math.PI / 2;
double new_x = x + radius * Math.sin(rotation);
double new_z = z + radius * Math.cos(rotation);
points[i] = new Vec3d(new_x, y, new_z);
}
double startVert = -time / 15;
double widthScale = radius * 3;
double[][] vertPos = new double[][] {{0, startVert}, {1, startVert}, {1, startVert + length / widthScale}, {0, startVert + length / widthScale}};
for (int i = 0; i < 4; i++) {
Vec3d point_1 = points[i];
Vec3d point_2 = points[(i + 1) % 4];
Vec3d point_3 = point_2.add(0, length, 0);
Vec3d point_4 = point_1.add(0, length, 0);
drawPlane(BEAM_TEXTURE, point_1, point_2, point_3, point_4, vertPos);
}
GlStateManager.popMatrix();
}
}