Fix setting the material of a block
Also fixed ID of wood material
This commit is contained in:
parent
4f0645492c
commit
70b322583a
4 changed files with 24 additions and 16 deletions
|
@ -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<ScalingEntityStruct>(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<MaterialPropertiesData>((byte) value))
|
||||
throw new BlockException($"Block material {value} does not exist!");
|
||||
BlockEngine.GetBlockInfo<CubeMaterialStruct>(this).materialId = (byte) value;
|
||||
BlockEngine.UpdatePrefab(this, (ushort) Type, (byte) value, Flipped); //TODO: Test default
|
||||
BlockEngine.UpdatePrefab(this, (byte) value, Flipped); //TODO: Test default
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,11 +98,21 @@ namespace TechbloxModdingAPI.Blocks
|
|||
entitiesDB.QueryEntity<RenderingDataStruct>(id).matrix = float4x4.TRS(pos.position, rot.rotation, scale.scale);
|
||||
}
|
||||
|
||||
internal void UpdatePrefab(Block block, ushort type, byte material, bool flipped)
|
||||
internal void UpdatePrefab(Block block, byte material, bool flipped)
|
||||
{
|
||||
uint pid = PrefabsID.GetOrCreatePrefabID(type, material, 0, flipped);
|
||||
entitiesDB.QueryEntityOrDefault<GFXPrefabEntityStructGPUI>(block).prefabID = pid;
|
||||
entitiesDB.QueryEntityOrDefault<PhysicsPrefabEntityStruct>(block) = new PhysicsPrefabEntityStruct(pid);
|
||||
var prefabAssetIDOpt = entitiesDB.QueryEntityOptional<PrefabAssetIDComponent>(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<GFXPrefabEntityStructGPUI>(block).prefabID = prefabId;
|
||||
if (block.Exists)
|
||||
entitiesDB.PublishEntityChange<GFXPrefabEntityStructGPUI>(block.Id);
|
||||
//Phyiscs prefab: prefabAssetID, set on block creation from the CubeListData
|
||||
/*Console.WriteLine("Materials:\n" + FullGameFields._dataDb.GetValues<MaterialPropertiesData>()
|
||||
.Select(kv => $"{kv.Key}: {((MaterialPropertiesData) kv.Value).Name}")
|
||||
.Aggregate((a, b) => a + "\n" + b));*/
|
||||
}
|
||||
|
||||
public bool BlockExists(EGID blockID)
|
||||
|
|
|
@ -7,6 +7,6 @@ namespace TechbloxModdingAPI.Blocks
|
|||
RigidSteel,
|
||||
CarbonFiber,
|
||||
Plastic,
|
||||
Wood
|
||||
Wood = 6
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue