Record Class Orientation
- Record Components:
raw- the client angle0..16383, orUNKNOWN_RAW
raw() is the client's own angle, 0..16383 per full turn. It is the
entity's rendered facing, which the client interpolates while the entity turns,
so for a few ticks after a turn starts it reads an in-between angle rather than the
direction being turned towards. It is UNKNOWN_RAW when the producer could not
read one.
For anything but an exact comparison, use degrees() (a compass bearing,
clockwise from north) or compass() (the nearest of eight points). Both are empty
when the facing is unknown. They never quietly answer "north" or "0 degrees" for a value
that was not read.
Compare facings with isSameFacingAs(Orientation), not equals. The client's
conversion truncates, so a facing the server set to angle j can read back as
j - 1. Record equals is exact value identity and will call those two
different; isSameFacingAs(Orientation) allows the READBACK_TOLERANCE of one unit.
compass() is unaffected, because one unit is far inside a 45-degree sector.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intClient angle units in one full turn.static final intThe raw angle that faces north (+tileY).static final intHow far, in raw units, a facing read back from the client may sit from the angle that set it: the client's conversion truncates, so anglejcan read back asj - 1.static final intraw()when the facing is not known.static final intWhat the producer publishes on the wire for "not known": an all-onesu16. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncompass()The nearest of the eight compass points; empty when unknown.degrees()Compass bearing in[0, 360), clockwise from north; empty when unknown.final booleanIndicates whether some other object is "equal to" this one.static OrientationfromWire(int wireValue, IntConsumer outOfContract) Decodes the producer's zero-extendedu16, degrading rather than throwing.final inthashCode()Returns a hash code value for this object.booleanisKnown()booleanisSameFacingAs(Orientation other) True when both facings are known and lie withinREADBACK_TOLERANCEof each other around the circle, so0and16383count as one unit apart.intraw()Returns the value of therawrecord component.final StringtoString()Returns a string representation of this record class.static Orientationunknown()An orientation that was not read.
-
Field Details
-
FULL_TURN
public static final int FULL_TURNClient angle units in one full turn.- See Also:
-
NORTH_RAW
public static final int NORTH_RAWThe raw angle that faces north (+tileY). The raw angle grows clockwise seen from above:0south,4096west,8192north,12288east.This zero offset is inferred statically and not yet confirmed against a live client. If that check disagrees, this constant is the one line to change, and
OrientationTest's cardinal pins say what the answers must become.- See Also:
-
UNKNOWN_RAW
-
WIRE_UNKNOWN
public static final int WIRE_UNKNOWNWhat the producer publishes on the wire for "not known": an all-onesu16.- See Also:
-
READBACK_TOLERANCE
public static final int READBACK_TOLERANCEHow far, in raw units, a facing read back from the client may sit from the angle that set it: the client's conversion truncates, so anglejcan read back asj - 1.- See Also:
-
-
Constructor Details
-
Orientation
public Orientation(int raw) Creates an instance of aOrientationrecord class.- Parameters:
raw- the value for therawrecord component
-
-
Method Details
-
fromWire
Decodes the producer's zero-extendedu16, degrading rather than throwing.WIRE_UNKNOWNis an unknown orientation and0..16383is the angle itself. Anything else (16384..65534) breaks the producer's contract; it is also decoded as unknown, never wrapped into a plausible wrong angle, and reported tooutOfContract. This method never throws: it runs inside a snapshot decode, and one bad row must not take down every running script. Constructing anOrientationdirectly with an out-of-range value still throws, because that is a caller's mistake rather than the wire's.- Parameters:
wireValue- the zero-extendedu16read from shared memoryoutOfContract- told the offending value when it is neither an angle nor the sentinel; the decode layer rate-limits what it logs
-
unknown
An orientation that was not read. -
isKnown
public boolean isKnown() -
isSameFacingAs
True when both facings are known and lie withinREADBACK_TOLERANCEof each other around the circle, so0and16383count as one unit apart. Use this rather thanequals, which is exact and so fooled by the client's truncation. An unknown facing matches nothing, including another unknown one. -
degrees
Compass bearing in[0, 360), clockwise from north; empty when unknown. -
compass
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
raw
-