-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
111 lines (101 loc) · 3.66 KB
/
Block.java
File metadata and controls
111 lines (101 loc) · 3.66 KB
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
import java.util.Map;
public class Block {
private Vector3 position;
private boolean[] hiddenFaces;
private BlockType type;
private Map<String, Object> data;
public Block(Vector3 position, BlockType type) {
this.position = position;
this.hiddenFaces = new boolean[] {
false, false, false, false, false, false
};
this.type = type;
this.data = null;
}
public Face[] getFacesToRender(Vector3 cameraPosition) {
Face[] faces = new Face[3];
Vector3[] blockVertices = new Vector3[] {
new Vector3(position.getX(), position.getY(), position.getZ()),
new Vector3(position.getX(), position.getY(), position.getZ() + 1),
new Vector3(position.getX(),
position.getY() + (type.getSpecialBlockRendering() == SpecialBlockRendering.LIQUID ? 0.875 : 1),
position.getZ()),
new Vector3(position.getX(),
position.getY() + (type.getSpecialBlockRendering() == SpecialBlockRendering.LIQUID ? 0.875 : 1),
position.getZ() + 1),
new Vector3(position.getX() + 1, position.getY(), position.getZ()),
new Vector3(position.getX() + 1, position.getY(), position.getZ() + 1),
new Vector3(position.getX() + 1,
position.getY() + (type.getSpecialBlockRendering() == SpecialBlockRendering.LIQUID ? 0.875 : 1),
position.getZ()),
new Vector3(position.getX() + 1,
position.getY() + (type.getSpecialBlockRendering() == SpecialBlockRendering.LIQUID ? 0.875 : 1),
position.getZ() + 1)
};
int i = 0;
if (cameraPosition.getX() > position.getX() + 1 && !hiddenFaces[Orientation.NORTH.ordinal()]) {
faces[i++] = new Face(new Vector3[] {
blockVertices[4],
blockVertices[5],
blockVertices[6],
blockVertices[7]
}, type, Orientation.NORTH);
}
if (cameraPosition.getX() < position.getX() && !hiddenFaces[Orientation.SOUTH.ordinal()]) {
faces[i++] = new Face(new Vector3[] {
blockVertices[1],
blockVertices[0],
blockVertices[3],
blockVertices[2]
}, type, Orientation.SOUTH);
}
if (cameraPosition.getY() > position.getY() + 1 && !hiddenFaces[Orientation.UP.ordinal()]) {
faces[i++] = new Face(new Vector3[] {
blockVertices[3],
blockVertices[2],
blockVertices[7],
blockVertices[6]
}, type, Orientation.UP);
}
if (cameraPosition.getY() < position.getY() && !hiddenFaces[Orientation.DOWN.ordinal()]) {
faces[i++] = new Face(new Vector3[] {
blockVertices[1],
blockVertices[0],
blockVertices[5],
blockVertices[4]
}, type, Orientation.DOWN);
}
if (cameraPosition.getZ() > position.getZ() + 1 && !hiddenFaces[Orientation.WEST.ordinal()]) {
faces[i++] = new Face(new Vector3[] {
blockVertices[5],
blockVertices[1],
blockVertices[7],
blockVertices[3]
}, type, Orientation.WEST);
}
if (cameraPosition.getZ() < position.getZ() && !hiddenFaces[Orientation.EAST.ordinal()]) {
faces[i++] = new Face(new Vector3[] {
blockVertices[0],
blockVertices[4],
blockVertices[2],
blockVertices[6]
}, type, Orientation.EAST);
}
return faces;
}
public void hideFace(Orientation orientation) {
hiddenFaces[orientation.ordinal()] = true;
}
public boolean isTransparent() {
return type.isTransparent();
}
public double getSpeedModifier() {
return type.getSpeedModifier();
}
public Vector3 getPosition() {
return position;
}
public int getBlockTypeId() {
return BlockType.getBlockTypeId(type);
}
}