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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection.Emit;
|
|
||||||
|
|
||||||
|
using DataLoader;
|
||||||
using Gamecraft.Blocks.BlockGroups;
|
using Gamecraft.Blocks.BlockGroups;
|
||||||
using Svelto.ECS;
|
using Svelto.ECS;
|
||||||
using Svelto.ECS.EntityStructs;
|
using Svelto.ECS.EntityStructs;
|
||||||
|
@ -10,7 +9,7 @@ using RobocraftX.Common;
|
||||||
using RobocraftX.Blocks;
|
using RobocraftX.Blocks;
|
||||||
using Unity.Mathematics;
|
using Unity.Mathematics;
|
||||||
using Gamecraft.Blocks.GUI;
|
using Gamecraft.Blocks.GUI;
|
||||||
using RobocraftX.Rendering.GPUI;
|
|
||||||
using TechbloxModdingAPI.Blocks;
|
using TechbloxModdingAPI.Blocks;
|
||||||
using TechbloxModdingAPI.Utility;
|
using TechbloxModdingAPI.Utility;
|
||||||
|
|
||||||
|
@ -227,7 +226,7 @@ namespace TechbloxModdingAPI
|
||||||
{
|
{
|
||||||
ref var st = ref BlockEngine.GetBlockInfo<ScalingEntityStruct>(this);
|
ref var st = ref BlockEngine.GetBlockInfo<ScalingEntityStruct>(this);
|
||||||
st.scale.x = math.abs(st.scale.x) * (value ? -1 : 1);
|
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
|
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.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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
@ -11,11 +10,11 @@ using RobocraftX.Physics;
|
||||||
using RobocraftX.Rendering;
|
using RobocraftX.Rendering;
|
||||||
using RobocraftX.Rendering.GPUI;
|
using RobocraftX.Rendering.GPUI;
|
||||||
using Svelto.ECS.EntityStructs;
|
using Svelto.ECS.EntityStructs;
|
||||||
|
|
||||||
using Svelto.DataStructures;
|
using Svelto.DataStructures;
|
||||||
using Svelto.ECS;
|
using Svelto.ECS;
|
||||||
using Svelto.ECS.Hybrid;
|
using Svelto.ECS.Hybrid;
|
||||||
using Unity.Mathematics;
|
using Unity.Mathematics;
|
||||||
|
|
||||||
using TechbloxModdingAPI.Engines;
|
using TechbloxModdingAPI.Engines;
|
||||||
using TechbloxModdingAPI.Utility;
|
using TechbloxModdingAPI.Utility;
|
||||||
|
|
||||||
|
@ -99,12 +98,22 @@ namespace TechbloxModdingAPI.Blocks
|
||||||
entitiesDB.QueryEntity<RenderingDataStruct>(id).matrix = float4x4.TRS(pos.position, rot.rotation, scale.scale);
|
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);
|
var prefabAssetIDOpt = entitiesDB.QueryEntityOptional<PrefabAssetIDComponent>(block);
|
||||||
entitiesDB.QueryEntityOrDefault<GFXPrefabEntityStructGPUI>(block).prefabID = pid;
|
uint prefabAssetID = prefabAssetIDOpt
|
||||||
entitiesDB.QueryEntityOrDefault<PhysicsPrefabEntityStruct>(block) = new PhysicsPrefabEntityStruct(pid);
|
? 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)
|
public bool BlockExists(EGID blockID)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,6 @@ namespace TechbloxModdingAPI.Blocks
|
||||||
RigidSteel,
|
RigidSteel,
|
||||||
CarbonFiber,
|
CarbonFiber,
|
||||||
Plastic,
|
Plastic,
|
||||||
Wood
|
Wood = 6
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -181,8 +181,6 @@ namespace TechbloxModdingAPI.Tests
|
||||||
.Action((float x, float y, float z) =>
|
.Action((float x, float y, float z) =>
|
||||||
{
|
{
|
||||||
var block = Block.PlaceNew(BlockIDs.Cube, new float3(x, y, 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);
|
Logging.CommandLog("Block placed with type: " + block.Type);
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
Loading…
Reference in a new issue