public MyObjectBuilder_EntityBase[] BuildEntities()
{
var entity = new MyObjectBuilder_FloatingObject
{
EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY),
PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene,
Item = new MyObjectBuilder_InventoryItem { ItemId = 0 },
};
if (IsDecimal && DecimalUnits.HasValue)
entity.Item.Amount = DecimalUnits.Value.ToFixedPoint();
else if (IsInt && Units.HasValue)
entity.Item.Amount = Units.Value.ToFixedPoint();
else if (IsUnique)
entity.Item.Amount = GenerateFloatingObjectModel.UniqueUnits.ToFixedPoint();
else
entity.Item.Amount = 1;
IsValidItemToImport = true;
entity.Item.PhysicalContent = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_PhysicalObject>(StockItem.TypeId, StockItem.SubtypeId);
//switch (StockItem.TypeId)
//{
// case MyObjectBuilderTypeEnum.Component:
// case MyObjectBuilderTypeEnum.Ingot:
// case MyObjectBuilderTypeEnum.Ore:
// case MyObjectBuilderTypeEnum.AmmoMagazine:
// break;
// case MyObjectBuilderTypeEnum.PhysicalGunObject:
// // The GunEntity appears to make each 'GunObject' unique through the definition of an EntityId.
// // This means, you can't stack them.
// // Ownership does not appear to be required at this stage.
// ### Only required for pre-generating the Entity id for a gun that has been handled. ####
// // This is a hack approach, to find the Enum from a SubtypeName like "AngleGrinderItem".
// var enumName = StockItem.SubtypeId.Substring(0, StockItem.SubtypeId.Length - 4);
// MyObjectBuilderTypeEnum itemEnum;
// if (Enum.TryParse<MyObjectBuilderTypeEnum>(enumName, out itemEnum))
// {
// var gunEntity = MyObjectBuilder_Base.CreateNewObject(itemEnum) as MyObjectBuilder_EntityBase;
// gunEntity.EntityId = SpaceEngineersAPI.GenerateEntityId();
// gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
// ((MyObjectBuilder_PhysicalGunObject)entity.Item.PhysicalContent).GunEntity = gunEntity;
// }
// break;
// default:
// // As yet uncatered for items which may be new.
// IsValidItemToImport = false;
// break;
//}
// Figure out where the Character is facing, and plant the new construct 1m out in front, and 1m up from the feet, facing the Character.
var vectorFwd = _dataModel.CharacterPosition.Forward.ToVector3D();
var vectorUp = _dataModel.CharacterPosition.Up.ToVector3D();
vectorFwd.Normalize();
vectorUp.Normalize();
var vector = Vector3D.Multiply(vectorFwd, 1.0f) + Vector3D.Multiply(vectorUp, 1.0f);
entity.PositionAndOrientation = new MyPositionAndOrientation
{
Position = Point3D.Add(_dataModel.CharacterPosition.Position.ToPoint3D(), vector).ToVector3D(),
Forward = _dataModel.CharacterPosition.Forward,
Up = _dataModel.CharacterPosition.Up
};
var entities = new List<MyObjectBuilder_EntityBase>();
for (var i = 0; i < Multiplier; i++)
{
var newEntity = (MyObjectBuilder_FloatingObject)entity.Clone();
newEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
//if (StockItem.TypeId == SpaceEngineersConsts.PhysicalGunObject)
//{
// Only required for pre-generating the Entity id for a gun that has been handled.
// ((MyObjectBuilder_PhysicalGunObject)entity.Item.PhysicalContent).GunEntity.EntityId = SpaceEngineersAPI.GenerateEntityId();
//}
entities.Add(newEntity);
}
return entities.ToArray();
}