| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import com.mojang.math.OctahedralGroup;
|
| 4 | import com.mojang.serialization.Codec;
|
| 5 | import net.minecraft.core.Direction;
|
| 6 | import net.minecraft.network.chat.Component;
|
| 7 | import net.minecraft.util.ExtraCodecs;
|
| 8 | import net.minecraft.util.StringRepresentable;
|
| 9 |
|
| 10 | public enum Mirror implements StringRepresentable {
|
| 11 | NONE("none", OctahedralGroup.IDENTITY),
|
| 12 | LEFT_RIGHT("left_right", OctahedralGroup.INVERT_Z),
|
| 13 | FRONT_BACK("front_back", OctahedralGroup.INVERT_X);
|
| 14 |
|
| 15 | public static final Codec<Mirror> CODEC = StringRepresentable.fromEnum(Mirror::values);
|
| 16 | @Deprecated
|
| 17 | public static final Codec<Mirror> LEGACY_CODEC = ExtraCodecs.legacyEnum(Mirror::valueOf);
|
| 18 | private final String id;
|
| 19 | private final Component symbol;
|
| 20 | private final OctahedralGroup rotation;
|
| 21 |
|
| 22 | Mirror(final String id, final OctahedralGroup rotation) {
|
| 23 | this.id = id;
|
| 24 | this.symbol = Component.translatable("mirror." + id);
|
| 25 | this.rotation = rotation;
|
| 26 | }
|
| 27 |
|
| 28 | public int mirror(final int rotation, final int steps) {
|
| 29 | int halfSteps = steps / 2;
|
| 30 | int correctedRotation = rotation > halfSteps ? rotation - steps : rotation;
|
| 31 |
|
| 32 | return switch (this) {
|
| 33 | case LEFT_RIGHT -> (halfSteps - correctedRotation + steps) % steps;
|
| 34 | case FRONT_BACK -> (steps - correctedRotation) % steps;
|
| 35 | default -> rotation;
|
| 36 | };
|
| 37 | }
|
| 38 |
|
| 39 | public Rotation getRotation(final Direction value) {
|
| 40 | Direction.Axis axis = value.getAxis();
|
| 41 | return (this != LEFT_RIGHT || axis != Direction.Axis.Z) && (this != FRONT_BACK || axis != Direction.Axis.X) ? Rotation.NONE : Rotation.CLOCKWISE_180;
|
| 42 | }
|
| 43 |
|
| 44 | public Direction mirror(final Direction direction) {
|
| 45 | if (this == FRONT_BACK && direction.getAxis() == Direction.Axis.X) {
|
| 46 | return direction.getOpposite();
|
| 47 | } else {
|
| 48 | return this == LEFT_RIGHT && direction.getAxis() == Direction.Axis.Z ? direction.getOpposite() : direction;
|
| 49 | }
|
| 50 | }
|
| 51 |
|
| 52 | public OctahedralGroup rotation() {
|
| 53 | return this.rotation;
|
| 54 | }
|
| 55 |
|
| 56 | public Component symbol() {
|
| 57 | return this.symbol;
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | public String getSerializedName() {
|
| 62 | return this.id;
|
| 63 | }
|
| 64 | }
|
| 65 |
|