25
25
package org .spongepowered .common .util ;
26
26
27
27
28
- import net .minecraft .world .level .block .state .properties .DirectionProperty ;
28
+ import net .minecraft .world .level .block .state .properties .EnumProperty ;
29
29
import org .spongepowered .api .util .Direction ;
30
30
31
31
import java .util .Objects ;
@@ -34,45 +34,31 @@ public final class DirectionUtil {
34
34
35
35
public static net .minecraft .core .Direction getFor (final Direction direction ) {
36
36
Objects .requireNonNull (direction );
37
- switch (direction ) {
38
- case UP :
39
- return net .minecraft .core .Direction .UP ;
40
- case DOWN :
41
- return net .minecraft .core .Direction .DOWN ;
42
- case WEST :
43
- return net .minecraft .core .Direction .WEST ;
44
- case SOUTH :
45
- return net .minecraft .core .Direction .SOUTH ;
46
- case EAST :
47
- return net .minecraft .core .Direction .EAST ;
48
- case NORTH :
49
- return net .minecraft .core .Direction .NORTH ;
50
- default :
51
- return null ;
52
- }
37
+ return switch (direction ) {
38
+ case UP -> net .minecraft .core .Direction .UP ;
39
+ case DOWN -> net .minecraft .core .Direction .DOWN ;
40
+ case WEST -> net .minecraft .core .Direction .WEST ;
41
+ case SOUTH -> net .minecraft .core .Direction .SOUTH ;
42
+ case EAST -> net .minecraft .core .Direction .EAST ;
43
+ case NORTH -> net .minecraft .core .Direction .NORTH ;
44
+ default -> null ;
45
+ };
53
46
}
54
47
55
48
public static Direction getFor (final net .minecraft .core .Direction facing ) {
56
49
Objects .requireNonNull (facing );
57
- switch (facing ) {
58
- case UP :
59
- return Direction .UP ;
60
- case DOWN :
61
- return Direction .DOWN ;
62
- case WEST :
63
- return Direction .WEST ;
64
- case SOUTH :
65
- return Direction .SOUTH ;
66
- case EAST :
67
- return Direction .EAST ;
68
- case NORTH :
69
- return Direction .NORTH ;
70
- default :
71
- throw new IllegalStateException ();
72
- }
50
+ return switch (facing ) {
51
+ case UP -> Direction .UP ;
52
+ case DOWN -> Direction .DOWN ;
53
+ case WEST -> Direction .WEST ;
54
+ case SOUTH -> Direction .SOUTH ;
55
+ case EAST -> Direction .EAST ;
56
+ case NORTH -> Direction .NORTH ;
57
+ default -> throw new IllegalStateException ();
58
+ };
73
59
}
74
60
75
- public static net .minecraft .world .level .block .state .BlockState set (final net .minecraft .world .level .block .state .BlockState holder , final Direction value , final DirectionProperty property ) {
61
+ public static net .minecraft .world .level .block .state .BlockState set (final net .minecraft .world .level .block .state .BlockState holder , final Direction value , final EnumProperty < net . minecraft . core . Direction > property ) {
76
62
final net .minecraft .core .Direction direction = DirectionUtil .getFor (value );
77
63
if (direction == null || !property .getPossibleValues ().contains (direction )) {
78
64
return holder ;
@@ -81,168 +67,101 @@ public static net.minecraft.world.level.block.state.BlockState set(final net.min
81
67
}
82
68
83
69
public static Direction fromRotation (int i ) {
84
- switch (i ) {
85
- case 0 :
86
- return Direction .SOUTH ;
87
- case 1 :
88
- return Direction .SOUTH_SOUTHWEST ;
89
- case 2 :
90
- return Direction .SOUTHWEST ;
91
- case 3 :
92
- return Direction .WEST_SOUTHWEST ;
93
- case 4 :
94
- return Direction .WEST ;
95
- case 5 :
96
- return Direction .WEST_NORTHWEST ;
97
- case 6 :
98
- return Direction .NORTHWEST ;
99
- case 7 :
100
- return Direction .NORTH_NORTHWEST ;
101
- case 8 :
102
- return Direction .NORTH ;
103
- case 9 :
104
- return Direction .NORTH_NORTHEAST ;
105
- case 10 :
106
- return Direction .NORTHEAST ;
107
- case 11 :
108
- return Direction .EAST_NORTHEAST ;
109
- case 12 :
110
- return Direction .EAST ;
111
- case 13 :
112
- return Direction .EAST_SOUTHEAST ;
113
- case 14 :
114
- return Direction .SOUTHEAST ;
115
- case 15 :
116
- return Direction .SOUTH_SOUTHEAST ;
117
- default :
118
- return Direction .NORTH ;
119
- }
70
+ return switch (i ) {
71
+ case 0 -> Direction .SOUTH ;
72
+ case 1 -> Direction .SOUTH_SOUTHWEST ;
73
+ case 2 -> Direction .SOUTHWEST ;
74
+ case 3 -> Direction .WEST_SOUTHWEST ;
75
+ case 4 -> Direction .WEST ;
76
+ case 5 -> Direction .WEST_NORTHWEST ;
77
+ case 6 -> Direction .NORTHWEST ;
78
+ case 7 -> Direction .NORTH_NORTHWEST ;
79
+ case 8 -> Direction .NORTH ;
80
+ case 9 -> Direction .NORTH_NORTHEAST ;
81
+ case 10 -> Direction .NORTHEAST ;
82
+ case 11 -> Direction .EAST_NORTHEAST ;
83
+ case 12 -> Direction .EAST ;
84
+ case 13 -> Direction .EAST_SOUTHEAST ;
85
+ case 14 -> Direction .SOUTHEAST ;
86
+ case 15 -> Direction .SOUTH_SOUTHEAST ;
87
+ default -> Direction .NORTH ;
88
+ };
120
89
}
121
90
public static int toRotation (final Direction direction ) {
122
- switch (direction ) {
123
- case SOUTH :
124
- return 0 ;
125
- case SOUTH_SOUTHWEST :
126
- return 1 ;
127
- case SOUTHWEST :
128
- return 2 ;
129
- case WEST_SOUTHWEST :
130
- return 3 ;
131
- case WEST :
132
- return 4 ;
133
- case WEST_NORTHWEST :
134
- return 5 ;
135
- case NORTHWEST :
136
- return 6 ;
137
- case NORTH_NORTHWEST :
138
- return 7 ;
139
- case NORTH :
140
- return 8 ;
141
- case NORTH_NORTHEAST :
142
- return 9 ;
143
- case NORTHEAST :
144
- return 10 ;
145
- case EAST_NORTHEAST :
146
- return 11 ;
147
- case EAST :
148
- return 12 ;
149
- case EAST_SOUTHEAST :
150
- return 13 ;
151
- case SOUTHEAST :
152
- return 14 ;
153
- case SOUTH_SOUTHEAST :
154
- return 15 ;
155
- default :
156
- return 0 ;
157
- }
91
+ return switch (direction ) {
92
+ case SOUTH -> 0 ;
93
+ case SOUTH_SOUTHWEST -> 1 ;
94
+ case SOUTHWEST -> 2 ;
95
+ case WEST_SOUTHWEST -> 3 ;
96
+ case WEST -> 4 ;
97
+ case WEST_NORTHWEST -> 5 ;
98
+ case NORTHWEST -> 6 ;
99
+ case NORTH_NORTHWEST -> 7 ;
100
+ case NORTH -> 8 ;
101
+ case NORTH_NORTHEAST -> 9 ;
102
+ case NORTHEAST -> 10 ;
103
+ case EAST_NORTHEAST -> 11 ;
104
+ case EAST -> 12 ;
105
+ case EAST_SOUTHEAST -> 13 ;
106
+ case SOUTHEAST -> 14 ;
107
+ case SOUTH_SOUTHEAST -> 15 ;
108
+ default -> 0 ;
109
+ };
158
110
}
159
111
160
112
public static Direction fromHorizontalHanging (int i ) {
161
- switch (i ) {
162
- case 0 :
163
- return Direction .SOUTH ;
164
- case 1 :
165
- return Direction .WEST ;
166
- case 2 :
167
- return Direction .NORTH ;
168
- case 3 :
169
- return Direction .EAST ;
170
- default :
171
- return Direction .NORTH ;
172
- }
113
+ return switch (i ) {
114
+ case 0 -> Direction .SOUTH ;
115
+ case 1 -> Direction .WEST ;
116
+ case 2 -> Direction .NORTH ;
117
+ case 3 -> Direction .EAST ;
118
+ default -> Direction .NORTH ;
119
+ };
173
120
}
174
121
175
122
public static int toHorizontalHanging (Direction direction ) {
176
- switch (direction ) {
177
- case SOUTH :
178
- return 0 ;
179
- case WEST :
180
- return 1 ;
181
- case NORTH :
182
- return 2 ;
183
- case EAST :
184
- return 3 ;
185
- default :
186
- return 0 ;
187
- }
123
+ return switch (direction ) {
124
+ case SOUTH -> 0 ;
125
+ case WEST -> 1 ;
126
+ case NORTH -> 2 ;
127
+ case EAST -> 3 ;
128
+ default -> 0 ;
129
+ };
188
130
}
189
131
190
132
191
133
public static Direction fromHanging (int i ) {
192
- switch (i ) {
193
- case 0 :
194
- return Direction .DOWN ;
195
- case 1 :
196
- return Direction .UP ;
197
- case 2 :
198
- return Direction .NORTH ;
199
- case 3 :
200
- return Direction .SOUTH ;
201
- case 4 :
202
- return Direction .WEST ;
203
- case 5 :
204
- return Direction .EAST ;
205
- default :
206
- return Direction .DOWN ;
207
- }
134
+ return switch (i ) {
135
+ case 0 -> Direction .DOWN ;
136
+ case 1 -> Direction .UP ;
137
+ case 2 -> Direction .NORTH ;
138
+ case 3 -> Direction .SOUTH ;
139
+ case 4 -> Direction .WEST ;
140
+ case 5 -> Direction .EAST ;
141
+ default -> Direction .DOWN ;
142
+ };
208
143
}
209
144
210
145
public static int toHanging (Direction direction ) {
211
- switch (direction ) {
212
- case DOWN :
213
- return 0 ;
214
- case UP :
215
- return 1 ;
216
- case NORTH :
217
- return 2 ;
218
- case SOUTH :
219
- return 3 ;
220
- case WEST :
221
- return 4 ;
222
- case EAST :
223
- return 5 ;
224
- default :
225
- return 0 ;
226
- }
146
+ return switch (direction ) {
147
+ case DOWN -> 0 ;
148
+ case UP -> 1 ;
149
+ case NORTH -> 2 ;
150
+ case SOUTH -> 3 ;
151
+ case WEST -> 4 ;
152
+ case EAST -> 5 ;
153
+ default -> 0 ;
154
+ };
227
155
}
228
156
229
157
public static int directionToIndex (final Direction direction ) {
230
- switch (direction ) {
231
- case NORTH :
232
- case NORTHEAST :
233
- case NORTHWEST :
234
- return 0 ;
235
- case SOUTH :
236
- case SOUTHEAST :
237
- case SOUTHWEST :
238
- return 1 ;
239
- case EAST :
240
- return 2 ;
241
- case WEST :
242
- return 3 ;
243
- default :
244
- throw new IllegalArgumentException ("Unexpected direction" );
245
- }
158
+ return switch (direction ) {
159
+ case NORTH , NORTHEAST , NORTHWEST -> 0 ;
160
+ case SOUTH , SOUTHEAST , SOUTHWEST -> 1 ;
161
+ case EAST -> 2 ;
162
+ case WEST -> 3 ;
163
+ default -> throw new IllegalArgumentException ("Unexpected direction" );
164
+ };
246
165
}
247
166
248
167
private DirectionUtil () {
0 commit comments