EnumFacing variable type

Status
Resolved
Issue description

Related issues: "Suggestion: Procedure / Condition (Block Face)", "Get/set block rotation procedure"

The EnumFacing variable type is used to store info such as a block orientation or the side of a block. This type of variable can have 6 possible values: UP, DOWN, NORTH, SOUTH, EAST, WEST. Adding support for this variable type would allow for more complex machines, such as orientable block generators, or blocks that perform different effects based on which side is clicked, without any code editing.

Some procedure triggers that can pass the "block side" dependency are "On block right-clicked" and "Item right clicked on block". Additionally, orientable blocks can pass their block state: the "FACING" property can be then converted to an EnumFacing variable.

Some procedure blocks that can be added with this variable are:

// EnumFacing related procedures from EnumFacing.java

/*
 * "[facing] = [DUNSWE]"
 * Replace FACING with DOWN, UP, NORTH etc.
 */
facing == EnumFacing.FACING;

// "Set [facing] to DUNSWE"
EnumFacing facing = EnumFacing.FACING;

// "Get facing index of [facing]" (converts DUNSWE to 0-5)
int n = enumFacing.getIndex();

// "Get horizontal index of [facing]" (converts SWNE to 0-3 and UD to -1)
int n = enumFacing.getHorizontalIndex();

// "Get opposite facing of [facing]" (e.g. opposite of UP is DOWN)
EnumFacing opposite = enumFacing.getOpposite();

// "Rotate [facing] along [X/Y/Z] axis"
EnumFacing rotate = enumFacing.rotateAround(EnumFacing.Axis axis);

// "Convert [facing] to string"
String name = enumFacing.getName2();

// "Convert [string] to facing"
EnumFacing facing = EnumFacing.byName(String name);

// "Convert [int] to facing" (converts int modulo 6 to DUNSWE)
EnumFacing facing = EnumFacing.getFront(int index);

// "Convert [int] to horizontal facing" (converts int modulo 4 to SWNE)
EnumFacing facing = EnumFacing.getHorizontal(int horizontalIndex);

// "Convert [double] to facing" (converts 0-360 angles to SWNE, 0 -> S, 90 -> W etc.)
EnumFacing facing = EnumFacing.fromAngle(double angle);

// "Convert [facing] to angle" (Converts SWNE to 0-360 angles)
float angle = enumFacing.getHorizontalAngle();


// Other EnumFacing procedure blocks

/* 
 * "Get [block] orientation"
 * Would require a blockState dependency, or a "Get block state at XYZ" procedure block
 * Could be added to the code of orientable blocks before they call the procedure
 * The orientation could be passed as an EnumFacing dependency, similar to block side
 */ 
EnumFacing facing = state.getValue(FACING);

/* 
 * "Offset blockpos by [int] amount along [facing] direction"
 * Would require to convert XYZ to BlockPos, then get the XYZ of the new BlockPos
 */
BlockPos pos = blockPos.offset(EnumFacing facing, int n);

// "Get horizontal facing of provided entity" (returns SWNE)
EnumFacing facing = entity.getHorizontalFacing();

 

Issue comments

Thank you for the code examples. Enums are basically int so for now I will keep these as number variable type in MCreator, but will consider extending this later down the road.

I want to make a infected oak log block that can infect other oak log blocks but when I do it it places the same rotation every time, I tried to make a variable that can store the rotation of the block before infection but turns out there isn't a variable type called rotation. Can you please add something like this?