context: using VRage.Game;
  using VRage.Game.ModAPI;
  
  namespace SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid
  {
  	using System;
  	using System.Collections.Generic;
  	using System.ComponentModel;
  	using System.IO;
  	using System.Runtime.Serialization;
  	using Sandbox;
  	using Sandbox.Common.ObjectBuilders;
  	using Sandbox.Definitions;
  	using Sandbox.ModAPI;
  	using SEModAPI.API.TypeConverters;
  	using SEModAPI.API.Utility;
  	using SEModAPIInternal.API.Common;
  	using SEModAPIInternal.API.Utility;
  	using SEModAPIInternal.Support;
  	using VRage;
  	using VRage.ObjectBuilders;
  	using VRageMath;
  
  	[DataContract( Name = "CubeBlockEntityProxy" )]
  	[KnownType( "KnownTypes" )]
  	public class CubeBlockEntity : BaseObject
  	{
  		#region "Attributes"
  
  		private CubeGridEntity m_parent;
  		private static Type m_internalType;
  		private float m_buildPercent;
  		private float m_integrityPercent;
  		private long m_owner;
  		private MyOwnershipShareModeEnum m_shareMode;
  
  		public static string CubeBlockNamespace = "Sandbox.Game.Entities.Cube";
  		public static string SlimBlockClass = "MySlimBlock";
  
  		public static string CubeBlockGetObjectBuilderMethod = "GetObjectBuilder";
  		public static string CubeBlockGetActualBlockMethod = "get_FatBlock";
  
  		public static string CubeBlockDamageBlockMethod = "DoDamage";
  
  		public static string CubeBlockGetBuildValueMethod = "get_BuildIntegrity";
  		public static string CubeBlockGetBuildPercentMethod = "get_BuildLevelRatio";
  
  		//public static string CubeBlockGetIntegrityValueMethod = "get_Integrity";
  		public static string CubeBlockGetIntegrityValueMethod = "get_Integrity";
  
  		public static string CubeBlockGetMaxIntegrityValueMethod = "get_MaxIntegrity";
  		public static string CubeBlockUpdateWeldProgressMethod = "ApplyAccumulatedDamage";
  
  		public static string CubeBlockGetBoneDamageMethod = "get_MaxDeformation";
  		public static string CubeBlockFixBonesMethod = "FixBones";
  
  		public static string CubeBlockParentCubeGridField = "m_cubeGrid";
  		public static string CubeBlockColorMaskHSVField = "ColorMaskHSV";
  		public static string CubeBlockConstructionManagerField = "m_componentStack";
  		public static string CubeBlockCubeBlockDefinitionField = "BlockDefinition";
  
  		/////////////////////////////////////////////////////
  
  		public static string ActualCubeBlockNamespace = "";
  		public static string ActualCubeBlockClass = "Sandbox.Game.Entities.MyCubeBlock";
  
  		public static string ActualCubeBlockGetObjectBuilderMethod = "GetObjectBuilderCubeBlock";
  		public static string ActualCubeBlockGetFactionsObjectMethod = "get_IDModule";
  		public static string ActualCubeBlockSetFactionsDataMethod = "ChangeOwner";
  		public static string ActualCubeBlockGetMatrixMethod = "get_WorldMatrix";
  
  		public static string ActualCubeBlockGetOwnerMethod = "get_OwnerId";
  
  		/////////////////////////////////////////////////////
  
  		public static string FactionsDataNamespace = "Sandbox.Game.Entities";
  		public static string FactionsDataClass = "MyIDModule";
  
  		public static string FactionsDataOwnerField = "m_owner";
  		public static string FactionsDataShareModeField = "ShareMode";
  
  		/////////////////////////////////////////////////////
  
  		public static string ConstructionManagerNamespace = "Sandbox.Game.Entities";
  		public static string ConstructionManagerClass = "MyComponentStack";
  
  		public static string ConstructionManagerSetIntegrityBuildValuesMethod = "SetIntegrity";
  		public static string ConstructionManagerGetBuildValueMethod = "get_BuildIntegrity";
  		public static string ConstructionManagerGetIntegrityValueMethod = "get_Integrity";
  		public static string ConstructionManagerGetMaxIntegrityMethod = "get_MaxIntegrity";
  		public static string ConstructionManagerGetBuildPercentMethod = "get_BuildRatio";
  		public static string ConstructionManagerGetIntegrityPercentMethod = "get_IntegrityRatio";
  
  		public static string ConstructionManagerIntegrityValueField = "m_integrity";
  		public static string ConstructionManagerBuildValueField = "m_buildIntegrity";
  
  		#endregion "Attributes"
  
  		#region "Constructors and Initializers"
  
  		public CubeBlockEntity( CubeGridEntity parent, MyObjectBuilder_CubeBlock definition )
  			: base( definition )
  		{
  			m_parent = parent;
  
  			m_buildPercent = definition.BuildPercent;
  			m_integrityPercent = definition.IntegrityPercent;
  			m_owner = definition.Owner;
  			m_shareMode = definition.ShareMode;
  		}
  
  		public CubeBlockEntity( CubeGridEntity parent, MyObjectBuilder_CubeBlock definition, Object backingObject )
  			: base( definition, backingObject )
  		{
  			m_parent = parent;
  
  			EntityEventManager.EntityEvent newEvent = new EntityEventManager.EntityEvent( );
  			newEvent.type = EntityEventManager.EntityEventType.OnCubeBlockCreated;
  			newEvent.timestamp = DateTime.Now;
  			newEvent.entity = this;
  			if ( m_parent.IsLoading )
  			{
  				newEvent.priority = 10;
  			}
  			else if ( EntityId != 0 )
  			{
  				newEvent.priority = 1;
  			}
  			else
  			{
  				newEvent.priority = 2;
  			}
  			EntityEventManager.Instance.AddEvent( newEvent );
  
  			if ( EntityId != 0 )
  			{
  				GameEntityManager.AddEntity( EntityId, this );
  			}
  
  			m_buildPercent = definition.BuildPercent;
  			m_integrityPercent = definition.IntegrityPercent;
  			m_owner = definition.Owner;
  			m_shareMode = definition.ShareMode;
  		}
  
  		#endregion "Constructors and Initializers"
  
  		#region "Properties"
  
  		[IgnoreDataMember]
  		[Category( "Cube Block" )]
  		[Browsable( false )]
  		[ReadOnly( true )]
  		internal static Type InternalType
  		{
  			get
  			{
  				if ( m_internalType == null )
  					m_internalType = SandboxGameAssemblyWrapper.Instance.GetAssemblyType( CubeBlockNamespace, SlimBlockClass );
  				return m_internalType;
  			}
  		}
  
  		[IgnoreDataMember]
  		[Category( "Cube Block" )]
  		[Browsable( false )]
  		[ReadOnly( true )]
  		internal new MyObjectBuilder_CubeBlock ObjectBuilder
  		{
  			get
  			{
  				MyObjectBuilder_CubeBlock objectBuilder = (MyObjectBuilder_CubeBlock)base.ObjectBuilder;
  				if ( objectBuilder == null )
  				{
  					objectBuilder = new MyObjectBuilder_CubeBlock( );
  					ObjectBuilder = objectBuilder;
  				}
  
  				return objectBuilder;
  			}
  			set
  			{
  				base.ObjectBuilder = value;
  			}
  		}
  
  		[DataMember( Order = 1 )]
  		[Category( "Cube Block" )]
  		[ReadOnly( true )]
  		public override string Name
  		{
  			get
  			{
  				String name = Id.SubtypeName;
  				if ( name == null || name == "" )
  					name = Id.TypeId.ToString( );
  				if ( name == null || name == "" )
  					name = EntityId.ToString( );
  				if ( name == null || name == "" )
  					name = "Cube Block";
  				return name;
  			}
  		}
  
  		[DataMember( Order = 1 )]
  		[Category( "Cube Block" )]
  		[Browsable( true )]
  		[ReadOnly( true )]
  		[Description( "The unique entity ID representing a functional entity in-game" )]
  		public long EntityId
  		{
  			get { return ObjectBuilder.EntityId; }
  			set
  			{
  				if ( ObjectBuilder.EntityId == value ) return;
  				ObjectBuilder.EntityId = value;
  
  				Changed = true;
  			}
  		}
  
  		[DataMember( Order = 2 )]
  		[Category( "Cube Block" )]
  		[Browsable( false )]
  		[ReadOnly( true )]
  		[TypeConverter( typeof( Vector3ITypeConverter ) )]
  		[Obsolete]
  		public SerializableVector3I Min
  		{
  			get { return ObjectBuilder.Min; }
  			set
  			{
  				if ( ObjectBuilder.Min.Equals( value ) ) return;
  				ObjectBuilder.Min = value;
  				Changed = true;
  			}
  		}
  
  		[DataMember( Order = 2 )]
  		[Category( "Cube Block" )]
  		[ReadOnly( true )]
  		[TypeConverter( typeof( Vector3ITypeConverter ) )]
  		public Vector3I Position
  		{
  			get { return ObjectBuilder.Min; }
  			set
  			{
  				if ( value.Equals( (Vector3I)ObjectBuilder.Min ) ) return;
  				ObjectBuilder.Min = value;
  				Changed = true;
  			}
  		}
  
  		[DataMember( Order = 2 )]
  		[Category( "Cube Block" )]
  		[ReadOnly( true )]
  		[TypeConverter( typeof( Vector3ITypeConverter ) )]
  		public Vector3I Size
  		{
  			get
  			{
  				MyCubeBlockDefinition def = MyDefinitionManager.Static.GetCubeBlockDefinition( ObjectBuilder );
  				return def.Size;
  			}
  			private set
  			{
  				//Do nothing!
  			}
  		}
  
  		[DataMember( Order = 2 )]
  		[Category( "Cube Block" )]
  		[Browsable( false )]
  		[ReadOnly( true )]
  		public MyBlockOrientation BlockOrientation
  		{
  			get { return ObjectBuilder.BlockOrientation; }
  			set
  			{
  				if ( ObjectBuilder.BlockOrientation.Equals( value ) ) return;
  				ObjectBuilder.BlockOrientation = value;
  				Changed = true;
  			}
  		}
  
  		[IgnoreDataMember]
  		[Category( "Cube Block" )]
  		[Browsable( false )]
  		[ReadOnly( true )]
  		[TypeConverter( typeof( Vector3TypeConverter ) )]
  		public Vector3Wrapper Up
  		{
  			get
  			{
  				if ( BackingObject == null || ActualObject == null )
  					return Vector3.Zero;
  
  				return GetBlockEntityMatrix( ).Up;
  			}
  			private set
  			{
  				//Do nothing!
  			}
  		}
  
  		[IgnoreDataMember]
  
gt: 		[Category( "Cube Block" )]