diff --git a/TechbloxModdingAPI/Block.cs b/TechbloxModdingAPI/Block.cs index 12abed7..ca66f3a 100644 --- a/TechbloxModdingAPI/Block.cs +++ b/TechbloxModdingAPI/Block.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Reflection.Emit; +using DataLoader; using Gamecraft.Blocks.BlockGroups; using Svelto.ECS; using Svelto.ECS.EntityStructs; @@ -10,7 +9,7 @@ using RobocraftX.Common; using RobocraftX.Blocks; using Unity.Mathematics; using Gamecraft.Blocks.GUI; -using RobocraftX.Rendering.GPUI; + using TechbloxModdingAPI.Blocks; using TechbloxModdingAPI.Utility; @@ -227,7 +226,7 @@ namespace TechbloxModdingAPI { ref var st = ref BlockEngine.GetBlockInfo(this); st.scale.x = math.abs(st.scale.x) * (value ? -1 : 1); - BlockEngine.UpdatePrefab(this, (ushort) Type, (byte) Material, value); + BlockEngine.UpdatePrefab(this, (byte) Material, value); } } @@ -289,8 +288,10 @@ namespace TechbloxModdingAPI } set { + if (!FullGameFields._dataDb.ContainsKey((byte) value)) + throw new BlockException($"Block material {value} does not exist!"); BlockEngine.GetBlockInfo(this).materialId = (byte) value; - BlockEngine.UpdatePrefab(this, (ushort) Type, (byte) value, Flipped); //TODO: Test default + BlockEngine.UpdatePrefab(this, (byte) value, Flipped); //TODO: Test default } } diff --git a/TechbloxModdingAPI/Blocks/BlockEngine.cs b/TechbloxModdingAPI/Blocks/BlockEngine.cs index c23ee8d..b06194f 100644 --- a/TechbloxModdingAPI/Blocks/BlockEngine.cs +++ b/TechbloxModdingAPI/Blocks/BlockEngine.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; @@ -11,11 +10,11 @@ using RobocraftX.Physics; using RobocraftX.Rendering; using RobocraftX.Rendering.GPUI; using Svelto.ECS.EntityStructs; - using Svelto.DataStructures; using Svelto.ECS; using Svelto.ECS.Hybrid; using Unity.Mathematics; + using TechbloxModdingAPI.Engines; using TechbloxModdingAPI.Utility; @@ -99,12 +98,22 @@ namespace TechbloxModdingAPI.Blocks entitiesDB.QueryEntity(id).matrix = float4x4.TRS(pos.position, rot.rotation, scale.scale); } - internal void UpdatePrefab(Block block, ushort type, byte material, bool flipped) - { - uint pid = PrefabsID.GetOrCreatePrefabID(type, material, 0, flipped); - entitiesDB.QueryEntityOrDefault(block).prefabID = pid; - entitiesDB.QueryEntityOrDefault(block) = new PhysicsPrefabEntityStruct(pid); - } + internal void UpdatePrefab(Block block, byte material, bool flipped) + { + var prefabAssetIDOpt = entitiesDB.QueryEntityOptional(block); + uint prefabAssetID = prefabAssetIDOpt + ? prefabAssetIDOpt.Get().prefabAssetID + : throw new BlockException("Prefab asset ID not found!"); //Set by the game + uint prefabId = + PrefabsID.GetOrCreatePrefabID((ushort) prefabAssetID, material, 1, flipped); + entitiesDB.QueryEntityOrDefault(block).prefabID = prefabId; + if (block.Exists) + entitiesDB.PublishEntityChange(block.Id); + //Phyiscs prefab: prefabAssetID, set on block creation from the CubeListData + /*Console.WriteLine("Materials:\n" + FullGameFields._dataDb.GetValues() + .Select(kv => $"{kv.Key}: {((MaterialPropertiesData) kv.Value).Name}") + .Aggregate((a, b) => a + "\n" + b));*/ + } public bool BlockExists(EGID blockID) { diff --git a/TechbloxModdingAPI/Blocks/BlockMaterial.cs b/TechbloxModdingAPI/Blocks/BlockMaterial.cs index 723bd63..6d00823 100644 --- a/TechbloxModdingAPI/Blocks/BlockMaterial.cs +++ b/TechbloxModdingAPI/Blocks/BlockMaterial.cs @@ -7,6 +7,6 @@ namespace TechbloxModdingAPI.Blocks RigidSteel, CarbonFiber, Plastic, - Wood + Wood = 6 } } \ No newline at end of file diff --git a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs index a4665f2..d9cfedb 100644 --- a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs +++ b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs @@ -181,8 +181,6 @@ namespace TechbloxModdingAPI.Tests .Action((float x, float y, float z) => { var block = Block.PlaceNew(BlockIDs.Cube, new float3(x, y, z)); - block.Scale *= 2; - new Block(BlockIDs.Cube, new float3(x + 1, y, z)).Scale *= 2; Logging.CommandLog("Block placed with type: " + block.Type); }) .Build();