extra validation for pitch and yaw of rotatable blocks

This commit is contained in:
Florian Nücke 2014-01-21 19:07:22 +01:00
parent 568bd7b873
commit 53e96153f0

View File

@ -165,9 +165,8 @@ trait Rotatable extends RotationAware with Persistable {
override def load(nbt: NBTTagCompound) = {
super.load(nbt)
_pitch = ForgeDirection.getOrientation(nbt.getInteger(Settings.namespace + "pitch"))
if (_pitch == ForgeDirection.UNKNOWN) _pitch = ForgeDirection.NORTH
_yaw = ForgeDirection.getOrientation(nbt.getInteger(Settings.namespace + "yaw"))
if (_yaw == ForgeDirection.UNKNOWN) _yaw = ForgeDirection.SOUTH
validatePitchAndYaw()
updateTranslation()
}
@ -182,6 +181,7 @@ trait Rotatable extends RotationAware with Persistable {
super.readFromNBTForClient(nbt)
_pitch = ForgeDirection.getOrientation(nbt.getInteger("pitch"))
_yaw = ForgeDirection.getOrientation(nbt.getInteger("yaw"))
validatePitchAndYaw()
updateTranslation()
}
@ -191,6 +191,15 @@ trait Rotatable extends RotationAware with Persistable {
nbt.setInteger("yaw", _yaw.ordinal)
}
private def validatePitchAndYaw() {
if (!Set(ForgeDirection.UP, ForgeDirection.DOWN, ForgeDirection.NORTH).contains(_pitch)) {
_pitch = ForgeDirection.NORTH
}
if (!Set(ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.EAST, ForgeDirection.WEST).contains(_yaw)) {
_yaw = ForgeDirection.SOUTH
}
}
// ----------------------------------------------------------------------- //
/** Updates cached translation array and sends notification to clients. */