EnumFacing .java

net.minecraft.util.EnumFacing (enum): members: DOWN, UP, NORTH, SOUTH, WEST, EAST, getFacingFromVector, getHorizontalIndex, getFacingFromAxis, Axis, Plane.

net.minecraft.utilenum479 linescommon12.7 KB

Implements

API Surface (36)

int getIndex()
int getHorizontalIndex()
EnumFacing.AxisDirection getAxisDirection()
EnumFacing getOpposite()
EnumFacing rotateAround(EnumFacing.Axis axis)
EnumFacing rotateY()
EnumFacing rotateYCCW()
int getFrontOffsetX()
int getFrontOffsetY()
int getFrontOffsetZ()
String getName2()
EnumFacing.Axis getAxis()
EnumFacing byName(String name)
EnumFacing getFront(int index)
EnumFacing getHorizontal(int p_176731_0_)
EnumFacing fromAngle(double angle)
EnumFacing random(Random rand)
EnumFacing getFacingFromVector(float p_176737_0_, float p_176737_1_, float p_176737_2_)
String toString()
String getName()
EnumFacing getFacingFromAxis(EnumFacing.AxisDirection p_181076_0_, EnumFacing.Axis p_181076_1_)
Vec3i getDirectionVec()
EnumFacing.Axis byName(String name)
String getName2()
boolean isVertical()
boolean isHorizontal()
String toString()
boolean apply(EnumFacing p_apply_1_)
EnumFacing.Plane getPlane()
String getName()
int getOffset()
String toString()
EnumFacing[] facings()
EnumFacing random(Random rand)
boolean apply(EnumFacing p_apply_1_)
Iterator<EnumFacing> iterator()

Fields & Constants (10)

VALUES
HORIZONTALS
NAME_LOOKUP
index
opposite
horizontalIndex
name
axis
axisDirection
directionVec

String literals (14)

"down"
"north"
"south"
"west"
"east"
"Unable to get CW facing for axis "
"Unable to get Y-rotated facing of "
"Unable to get X-rotated facing of "
"Unable to get Z-rotated facing of "
"Unable to get CCW facing of "
"No such direction: "
"Towards positive"
"Towards negative"
"Someone\'s been tampering with the universe!"

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

EnumFacing.java479 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
import com.google.common.base.Predicate;
4
import com.google.common.collect.Iterators;
5
import com.google.common.collect.Maps;
6
import java.util.Iterator;
7
import java.util.Map;
8
import java.util.Random;
9
10
public enum EnumFacing implements IStringSerializable
11
{
12
    DOWN(0, 1, -1, "down", EnumFacing.AxisDirection.NEGATIVE, EnumFacing.Axis.Y, new Vec3i(0, -1, 0)),
13
    UP(1, 0, -1, "up", EnumFacing.AxisDirection.POSITIVE, EnumFacing.Axis.Y, new Vec3i(0, 1, 0)),
14
    NORTH(2, 3, 2, "north", EnumFacing.AxisDirection.NEGATIVE, EnumFacing.Axis.Z, new Vec3i(0, 0, -1)),
15
    SOUTH(3, 2, 0, "south", EnumFacing.AxisDirection.POSITIVE, EnumFacing.Axis.Z, new Vec3i(0, 0, 1)),
16
    WEST(4, 5, 1, "west", EnumFacing.AxisDirection.NEGATIVE, EnumFacing.Axis.X, new Vec3i(-1, 0, 0)),
17
    EAST(5, 4, 3, "east", EnumFacing.AxisDirection.POSITIVE, EnumFacing.Axis.X, new Vec3i(1, 0, 0));
18
19
    /** Ordering index for D-U-N-S-W-E */
20
    private final int index;
21
22
    /** Index of the opposite Facing in the VALUES array */
23
    private final int opposite;
24
25
    /** Ordering index for the HORIZONTALS field (S-W-N-E) */
26
    private final int horizontalIndex;
27
    private final String name;
28
    private final EnumFacing.Axis axis;
29
    private final EnumFacing.AxisDirection axisDirection;
30
31
    /** Normalized Vector that points in the direction of this Facing */
32
    private final Vec3i directionVec;
33
34
    /** All facings in D-U-N-S-W-E order */
35
    private static final EnumFacing[] VALUES = new EnumFacing[6];
36
37
    /** All Facings with horizontal axis in order S-W-N-E */
38
    private static final EnumFacing[] HORIZONTALS = new EnumFacing[4];
39
    private static final Map<String, EnumFacing> NAME_LOOKUP = Maps.<String, EnumFacing>newHashMap();
40
41
    private EnumFacing(int indexIn, int oppositeIn, int horizontalIndexIn, String nameIn, EnumFacing.AxisDirection axisDirectionIn, EnumFacing.Axis axisIn, Vec3i directionVecIn)
42
    {
43
        this.index = indexIn;
44
        this.horizontalIndex = horizontalIndexIn;
45
        this.opposite = oppositeIn;
46
        this.name = nameIn;
47
        this.axis = axisIn;
48
        this.axisDirection = axisDirectionIn;
49
        this.directionVec = directionVecIn;
50
    }
51
52
    /**
53
     * Get the Index of this Facing (0-5). The order is D-U-N-S-W-E
54
     */
55
    public int getIndex()
56
    {
57
        return this.index;
58
    }
59
60
    /**
61
     * Get the index of this horizontal facing (0-3). The order is S-W-N-E
62
     */
63
    public int getHorizontalIndex()
64
    {
65
        return this.horizontalIndex;
66
    }
67
68
    /**
69
     * Get the AxisDirection of this Facing.
70
     */
71
    public EnumFacing.AxisDirection getAxisDirection()
72
    {
73
        return this.axisDirection;
74
    }
75
76
    /**
77
     * Get the opposite Facing (e.g. DOWN => UP)
78
     */
79
    public EnumFacing getOpposite()
80
    {
81
        return getFront(this.opposite);
82
    }
83
84
    /**
85
     * Rotate this Facing around the given axis clockwise. If this facing cannot be rotated around the given axis,
86
     * returns this facing without rotating.
87
     */
88
    public EnumFacing rotateAround(EnumFacing.Axis axis)
89
    {
90
        switch (axis)
91
        {
92
            case X:
93
                if (this != WEST && this != EAST)
94
                {
95
                    return this.rotateX();
96
                }
97
98
                return this;
99
100
            case Y:
101
                if (this != UP && this != DOWN)
102
                {
103
                    return this.rotateY();
104
                }
105
106
                return this;
107
108
            case Z:
109
                if (this != NORTH && this != SOUTH)
110
                {
111
                    return this.rotateZ();
112
                }
113
114
                return this;
115
116
            default:
117
                throw new IllegalStateException("Unable to get CW facing for axis " + axis);
118
        }
119
    }
120
121
    /**
122
     * Rotate this Facing around the Y axis clockwise (NORTH => EAST => SOUTH => WEST => NORTH)
123
     */
124
    public EnumFacing rotateY()
125
    {
126
        switch (this)
127
        {
128
            case NORTH:
129
                return EAST;
130
131
            case EAST:
132
                return SOUTH;
133
134
            case SOUTH:
135
                return WEST;
136
137
            case WEST:
138
                return NORTH;
139
140
            default:
141
                throw new IllegalStateException("Unable to get Y-rotated facing of " + this);
142
        }
143
    }
144
145
    /**
146
     * Rotate this Facing around the X axis (NORTH => DOWN => SOUTH => UP => NORTH)
147
     */
148
    private EnumFacing rotateX()
149
    {
150
        switch (this)
151
        {
152
            case NORTH:
153
                return DOWN;
154
155
            case EAST:
156
            case WEST:
157
            default:
158
                throw new IllegalStateException("Unable to get X-rotated facing of " + this);
159
160
            case SOUTH:
161
                return UP;
162
163
            case UP:
164
                return NORTH;
165
166
            case DOWN:
167
                return SOUTH;
168
        }
169
    }
170
171
    /**
172
     * Rotate this Facing around the Z axis (EAST => DOWN => WEST => UP => EAST)
173
     */
174
    private EnumFacing rotateZ()
175
    {
176
        switch (this)
177
        {
178
            case EAST:
179
                return DOWN;
180
181
            case SOUTH:
182
            default:
183
                throw new IllegalStateException("Unable to get Z-rotated facing of " + this);
184
185
            case WEST:
186
                return UP;
187
188
            case UP:
189
                return EAST;
190
191
            case DOWN:
192
                return WEST;
193
        }
194
    }
195
196
    /**
197
     * Rotate this Facing around the Y axis counter-clockwise (NORTH => WEST => SOUTH => EAST => NORTH)
198
     */
199
    public EnumFacing rotateYCCW()
200
    {
201
        switch (this)
202
        {
203
            case NORTH:
204
                return WEST;
205
206
            case EAST:
207
                return NORTH;
208
209
            case SOUTH:
210
                return EAST;
211
212
            case WEST:
213
                return SOUTH;
214
215
            default:
216
                throw new IllegalStateException("Unable to get CCW facing of " + this);
217
        }
218
    }
219
220
    /**
221
     * Returns a offset that addresses the block in front of this facing.
222
     */
223
    public int getFrontOffsetX()
224
    {
225
        return this.axis == EnumFacing.Axis.X ? this.axisDirection.getOffset() : 0;
226
    }
227
228
    public int getFrontOffsetY()
229
    {
230
        return this.axis == EnumFacing.Axis.Y ? this.axisDirection.getOffset() : 0;
231
    }
232
233
    /**
234
     * Returns a offset that addresses the block in front of this facing.
235
     */
236
    public int getFrontOffsetZ()
237
    {
238
        return this.axis == EnumFacing.Axis.Z ? this.axisDirection.getOffset() : 0;
239
    }
240
241
    /**
242
     * Same as getName, but does not override the method from Enum.
243
     */
244
    public String getName2()
245
    {
246
        return this.name;
247
    }
248
249
    public EnumFacing.Axis getAxis()
250
    {
251
        return this.axis;
252
    }
253
254
    /**
255
     * Get the facing specified by the given name
256
     */
257
    public static EnumFacing byName(String name)
258
    {
259
        return name == null ? null : (EnumFacing)NAME_LOOKUP.get(name.toLowerCase());
260
    }
261
262
    /**
263
     * Get a Facing by it's index (0-5). The order is D-U-N-S-W-E. Named getFront for legacy reasons.
264
     */
265
    public static EnumFacing getFront(int index)
266
    {
267
        return VALUES[MathHelper.abs_int(index % VALUES.length)];
268
    }
269
270
    /**
271
     * Get a Facing by it's horizontal index (0-3). The order is S-W-N-E.
272
     */
273
    public static EnumFacing getHorizontal(int p_176731_0_)
274
    {
275
        return HORIZONTALS[MathHelper.abs_int(p_176731_0_ % HORIZONTALS.length)];
276
    }
277
278
    /**
279
     * Get the Facing corresponding to the given angle (0-360). An angle of 0 is SOUTH, an angle of 90 would be WEST.
280
     */
281
    public static EnumFacing fromAngle(double angle)
282
    {
283
        return getHorizontal(MathHelper.floor_double(angle / 90.0D + 0.5D) & 3);
284
    }
285
286
    /**
287
     * Choose a random Facing using the given Random
288
     */
289
    public static EnumFacing random(Random rand)
290
    {
291
        return values()[rand.nextInt(values().length)];
292
    }
293
294
    public static EnumFacing getFacingFromVector(float p_176737_0_, float p_176737_1_, float p_176737_2_)
295
    {
296
        EnumFacing enumfacing = NORTH;
297
        float f = Float.MIN_VALUE;
298
299
        for (EnumFacing enumfacing1 : values())
300
        {
301
            float f1 = p_176737_0_ * (float)enumfacing1.directionVec.getX() + p_176737_1_ * (float)enumfacing1.directionVec.getY() + p_176737_2_ * (float)enumfacing1.directionVec.getZ();
302
303
            if (f1 > f)
304
            {
305
                f = f1;
306
                enumfacing = enumfacing1;
307
            }
308
        }
309
310
        return enumfacing;
311
    }
312
313
    public String toString()
314
    {
315
        return this.name;
316
    }
317
318
    public String getName()
319
    {
320
        return this.name;
321
    }
322
323
    public static EnumFacing getFacingFromAxis(EnumFacing.AxisDirection p_181076_0_, EnumFacing.Axis p_181076_1_)
324
    {
325
        for (EnumFacing enumfacing : values())
326
        {
327
            if (enumfacing.getAxisDirection() == p_181076_0_ && enumfacing.getAxis() == p_181076_1_)
328
            {
329
                return enumfacing;
330
            }
331
        }
332
333
        throw new IllegalArgumentException("No such direction: " + p_181076_0_ + " " + p_181076_1_);
334
    }
335
336
    /**
337
     * Get a normalized Vector that points in the direction of this Facing.
338
     */
339
    public Vec3i getDirectionVec()
340
    {
341
        return this.directionVec;
342
    }
343
344
    static {
345
        for (EnumFacing enumfacing : values())
346
        {
347
            VALUES[enumfacing.index] = enumfacing;
348
349
            if (enumfacing.getAxis().isHorizontal())
350
            {
351
                HORIZONTALS[enumfacing.horizontalIndex] = enumfacing;
352
            }
353
354
            NAME_LOOKUP.put(enumfacing.getName2().toLowerCase(), enumfacing);
355
        }
356
    }
357
358
    public static enum Axis implements Predicate<EnumFacing>, IStringSerializable {
359
        X("x", EnumFacing.Plane.HORIZONTAL),
360
        Y("y", EnumFacing.Plane.VERTICAL),
361
        Z("z", EnumFacing.Plane.HORIZONTAL);
362
363
        private static final Map<String, EnumFacing.Axis> NAME_LOOKUP = Maps.<String, EnumFacing.Axis>newHashMap();
364
        private final String name;
365
        private final EnumFacing.Plane plane;
366
367
        private Axis(String name, EnumFacing.Plane plane)
368
        {
369
            this.name = name;
370
            this.plane = plane;
371
        }
372
373
        public static EnumFacing.Axis byName(String name)
374
        {
375
            return name == null ? null : (EnumFacing.Axis)NAME_LOOKUP.get(name.toLowerCase());
376
        }
377
378
        public String getName2()
379
        {
380
            return this.name;
381
        }
382
383
        public boolean isVertical()
384
        {
385
            return this.plane == EnumFacing.Plane.VERTICAL;
386
        }
387
388
        public boolean isHorizontal()
389
        {
390
            return this.plane == EnumFacing.Plane.HORIZONTAL;
391
        }
392
393
        public String toString()
394
        {
395
            return this.name;
396
        }
397
398
        public boolean apply(EnumFacing p_apply_1_)
399
        {
400
            return p_apply_1_ != null && p_apply_1_.getAxis() == this;
401
        }
402
403
        public EnumFacing.Plane getPlane()
404
        {
405
            return this.plane;
406
        }
407
408
        public String getName()
409
        {
410
            return this.name;
411
        }
412
413
        static {
414
            for (EnumFacing.Axis enumfacing$axis : values())
415
            {
416
                NAME_LOOKUP.put(enumfacing$axis.getName2().toLowerCase(), enumfacing$axis);
417
            }
418
        }
419
    }
420
421
    public static enum AxisDirection {
422
        POSITIVE(1, "Towards positive"),
423
        NEGATIVE(-1, "Towards negative");
424
425
        private final int offset;
426
        private final String description;
427
428
        private AxisDirection(int offset, String description)
429
        {
430
            this.offset = offset;
431
            this.description = description;
432
        }
433
434
        public int getOffset()
435
        {
436
            return this.offset;
437
        }
438
439
        public String toString()
440
        {
441
            return this.description;
442
        }
443
    }
444
445
    public static enum Plane implements Predicate<EnumFacing>, Iterable<EnumFacing> {
446
        HORIZONTAL,
447
        VERTICAL;
448
449
        public EnumFacing[] facings()
450
        {
451
            switch (this)
452
            {
453
                case HORIZONTAL:
454
                    return new EnumFacing[] {EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST};
455
                case VERTICAL:
456
                    return new EnumFacing[] {EnumFacing.UP, EnumFacing.DOWN};
457
                default:
458
                    throw new Error("Someone\'s been tampering with the universe!");
459
            }
460
        }
461
462
        public EnumFacing random(Random rand)
463
        {
464
            EnumFacing[] aenumfacing = this.facings();
465
            return aenumfacing[rand.nextInt(aenumfacing.length)];
466
        }
467
468
        public boolean apply(EnumFacing p_apply_1_)
469
        {
470
            return p_apply_1_ != null && p_apply_1_.getAxis().getPlane() == this;
471
        }
472
473
        public Iterator<EnumFacing> iterator()
474
        {
475
            return Iterators.<EnumFacing>forArray(this.facings());
476
        }
477
    }
478
}
479

Deobfuscated MCP 1.8.9 source of EnumFacing from Marcelektro/MavenMCP-1.8.9 (net/minecraft/util/EnumFacing.java), stored verbatim.