Browse Source

Fix setting the material of a block

Also fixed ID of wood material
tags/v2.0.0
NorbiPeti 3 years ago
parent
commit
70b322583a
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
4 changed files with 24 additions and 16 deletions
  1. +6
    -5
      TechbloxModdingAPI/Block.cs
  2. +17
    -8
      TechbloxModdingAPI/Blocks/BlockEngine.cs
  3. +1
    -1
      TechbloxModdingAPI/Blocks/BlockMaterial.cs
  4. +0
    -2
      TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs

+ 6
- 5
TechbloxModdingAPI/Block.cs View File

@@ -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
}
}



+ 17
- 8
TechbloxModdingAPI/Blocks/BlockEngine.cs View File

@@ -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<RenderingDataStruct>(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<GFXPrefabEntityStructGPUI>(block).prefabID = pid;
entitiesDB.QueryEntityOrDefault<PhysicsPrefabEntityStruct>(block) = new PhysicsPrefabEntityStruct(pid);
}
internal void UpdatePrefab(Block block, byte material, bool flipped)
{
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)
{


+ 1
- 1
TechbloxModdingAPI/Blocks/BlockMaterial.cs View File

@@ -7,6 +7,6 @@ namespace TechbloxModdingAPI.Blocks
RigidSteel,
CarbonFiber,
Plastic,
Wood
Wood = 6
}
}

+ 0
- 2
TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs View File

@@ -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…
Cancel
Save