diff --git a/GamecraftModdingAPI/BlockGroup.cs b/GamecraftModdingAPI/BlockGroup.cs
index eee660a..6c600b2 100644
--- a/GamecraftModdingAPI/BlockGroup.cs
+++ b/GamecraftModdingAPI/BlockGroup.cs
@@ -115,7 +115,7 @@ namespace GamecraftModdingAPI
///
/// Creates a new block group consisting of a single block.
/// You can add more blocks using the Add() method or by setting the BlockGroup property of the blocks.
- /// Note that only newly placed blocks should be added to groups.
+ /// Note that only newly placed blocks can be added to groups.
///
/// The block to add
/// A new block group containing the given block
@@ -155,7 +155,7 @@ namespace GamecraftModdingAPI
IEnumerator IEnumerable.GetEnumerator() => blocks.GetEnumerator();
///
- /// Adds a block to the group. You should only add newly placed blocks
+ /// Adds a block to the group. You can only add newly placed blocks
/// so that the game initializes the group membership properly.
///
///
@@ -170,7 +170,7 @@ namespace GamecraftModdingAPI
///
/// Removes all blocks from this group.
- /// You should not remove blocks that have been initialized, only those that you placed recently.
+ /// You cannot remove blocks that have been initialized, only those that you placed recently.
///
public void Clear()
{
@@ -183,7 +183,7 @@ namespace GamecraftModdingAPI
///
/// Removes a block from this group.
- /// You should not remove blocks that have been initialized, only those that you placed recently.
+ /// You cannot remove blocks that have been initialized, only those that you placed recently.
///
///
///
diff --git a/GamecraftModdingAPI/Blocks/BlueprintEngine.cs b/GamecraftModdingAPI/Blocks/BlueprintEngine.cs
index 619fda1..ff22a4c 100644
--- a/GamecraftModdingAPI/Blocks/BlueprintEngine.cs
+++ b/GamecraftModdingAPI/Blocks/BlueprintEngine.cs
@@ -209,6 +209,18 @@ namespace GamecraftModdingAPI.Blocks
return blocks;
}
+ public void GetBlueprintInfo(uint blueprintID, out float3 pos, out quaternion rot, out uint selectionSize)
+ {
+ var serializationData = clipboardManager.GetSerializationData(blueprintID);
+ var blueprintData = serializationData.blueprintData;
+ blueprintData.dataPos = 0U;
+ BoxSelectSerializationUtilities.ReadClipboardHeader(blueprintData, out selectionSize, out var posst,
+ out var rotst, out _);
+ blueprintData.dataPos = 0U; //Just to be sure, it gets reset when it's read anyway
+ pos = posst.position;
+ rot = rotst.rotation;
+ }
+
public void InitBlueprint(uint blueprintID)
{
clipboardManager.IncrementRefCount(blueprintID);
@@ -280,7 +292,7 @@ namespace GamecraftModdingAPI.Blocks
}
public static MethodBase TargetMethod()
- {
+ {RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine
return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine"))[0];
}
}
diff --git a/GamecraftModdingAPI/Blocks/MovementEngine.cs b/GamecraftModdingAPI/Blocks/MovementEngine.cs
index a4ac0fa..fb3aa55 100644
--- a/GamecraftModdingAPI/Blocks/MovementEngine.cs
+++ b/GamecraftModdingAPI/Blocks/MovementEngine.cs
@@ -41,9 +41,9 @@ namespace GamecraftModdingAPI.Blocks
{
if (data.Group == null) return float3.zero;
var init = new EntityComponentInitializer(blockID, data.Group);
- init.Init(new PositionEntityStruct {position = vector});
- init.Init(new GridRotationStruct {position = vector});
- init.Init(new LocalTransformEntityStruct {position = vector});
+ init.GetOrCreate().position = vector;
+ init.GetOrCreate().position = vector;
+ init.GetOrCreate().position = vector;
return vector;
}
ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity(blockID);
diff --git a/GamecraftModdingAPI/Blocks/RotationEngine.cs b/GamecraftModdingAPI/Blocks/RotationEngine.cs
index ca97874..fbf8c98 100644
--- a/GamecraftModdingAPI/Blocks/RotationEngine.cs
+++ b/GamecraftModdingAPI/Blocks/RotationEngine.cs
@@ -41,9 +41,9 @@ namespace GamecraftModdingAPI.Blocks
{
if (data.Group == null) return float3.zero;
var init = new EntityComponentInitializer(blockID, data.Group);
- init.Init(new RotationEntityStruct {rotation = new Quaternion {eulerAngles = vector}});
- init.Init(new GridRotationStruct {rotation = new Quaternion {eulerAngles = vector}});
- init.Init(new LocalTransformEntityStruct {rotation = new Quaternion {eulerAngles = vector}});
+ init.GetOrCreate().rotation = Quaternion.Euler(vector);
+ init.GetOrCreate().rotation = Quaternion.Euler(vector);
+ init.GetOrCreate().rotation = Quaternion.Euler(vector);
return vector;
}
ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity(blockID);
diff --git a/GamecraftModdingAPI/Blueprint.cs b/GamecraftModdingAPI/Blueprint.cs
index 765de3d..4d9dff0 100644
--- a/GamecraftModdingAPI/Blueprint.cs
+++ b/GamecraftModdingAPI/Blueprint.cs
@@ -15,15 +15,23 @@ namespace GamecraftModdingAPI
{
Id = id;
BlockGroup._engine.InitBlueprint(id);
+ Refresh();
}
-
- /*public static void SelectBlueprint(Blueprint blueprint)
- {
- BlueprintUtil.SelectBlueprint(null, new BlueprintInventoryItemEntityStruct
- {
- blueprintResourceId = blueprint.Id
- });
- }*/
+
+ ///
+ /// The center of the blueprint. Can only be set using the StoreBlocks() method.
+ ///
+ public float3 Position { get; private set; }
+
+ ///
+ /// The rotation of the blueprint. Can only be set using the StoreBlocks() method.
+ ///
+ public float3 Rotation { get; private set; }
+
+ ///
+ /// The amount of blocks in the blueprint. Gan only be set using the StoreBlocks() method.
+ ///
+ public uint BlockCount { get; private set; }
///
/// Creates a new, empty blueprint. It will be deleted on disposal unless the game holds a reference to it.
@@ -39,12 +47,13 @@ namespace GamecraftModdingAPI
/// Use the BlockGroup overload for automatically calculated position and rotation.
///
/// The array of blocks to use
- /// The anchor position of the blueprint
+ /// The anchor (center) position of the blueprint
/// The base rotation of the blueprint
public void StoreBlocks(Block[] blocks, float3 position, float3 rotation)
{
BlockGroup._engine.ReplaceBlueprint(Player.LocalPlayer.Id, Id, blocks, position,
quaternion.Euler(rotation));
+ Refresh();
}
///
@@ -55,6 +64,7 @@ namespace GamecraftModdingAPI
{
BlockGroup._engine.ReplaceBlueprint(Player.LocalPlayer.Id, Id, group, group.Position,
Quaternion.Euler(group.Rotation));
+ Refresh();
}
///
@@ -68,6 +78,17 @@ namespace GamecraftModdingAPI
return BlockGroup._engine.PlaceBlueprintBlocks(Id, Player.LocalPlayer.Id, position, rotation);
}
+ ///
+ /// Updates the properties based on the blueprint data. Only necessary if the blueprint is changed from the game.
+ ///
+ public void Refresh()
+ {
+ BlockGroup._engine.GetBlueprintInfo(Id, out var pos, out var rot, out uint count);
+ Position = pos;
+ Rotation = ((Quaternion) rot).eulerAngles;
+ BlockCount = count;
+ }
+
public void Dispose()
{
BlockGroup._engine.DisposeBlueprint(Id);
@@ -75,7 +96,7 @@ namespace GamecraftModdingAPI
public override string ToString()
{
- return $"{nameof(Id)}: {Id}";
+ return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Rotation)}: {Rotation}, {nameof(BlockCount)}: {BlockCount}";
}
}
}
\ No newline at end of file