From 53e96153f0da47ae28d6b352a94e793ba5654bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Tue, 21 Jan 2014 19:07:22 +0100 Subject: [PATCH] extra validation for pitch and yaw of rotatable blocks --- li/cil/oc/common/tileentity/Rotatable.scala | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/li/cil/oc/common/tileentity/Rotatable.scala b/li/cil/oc/common/tileentity/Rotatable.scala index 96763f190..848c64e44 100644 --- a/li/cil/oc/common/tileentity/Rotatable.scala +++ b/li/cil/oc/common/tileentity/Rotatable.scala @@ -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. */