diff --git a/GamecraftModdingAPI/Block.cs b/GamecraftModdingAPI/Block.cs
index 607213d..daeeba3 100644
--- a/GamecraftModdingAPI/Block.cs
+++ b/GamecraftModdingAPI/Block.cs
@@ -40,18 +40,18 @@ namespace GamecraftModdingAPI
///
/// The block's type
/// The block's color
- /// The block color's darkness (0-9) - 0 is default color
+ /// The block's material
/// The block's position - default block size is 0.2
/// The block's rotation in degrees
/// The block's uniform scale - default scale is 1 (with 0.2 width)
/// The block's non-uniform scale - 0 means is used
/// The player who placed the block
/// The placed block or null if failed
- public static Block PlaceNew(BlockIDs block, float3 position,
- float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
+ public static Block PlaceNew(BlockIDs block, float3 position, float3 rotation = default,
+ BlockColors color = BlockColors.Default, BlockMaterial material = BlockMaterial.Default,
int uscale = 1, float3 scale = default, Player player = null)
{
- return PlaceNew(block, position, rotation, color, darkness, uscale, scale, player);
+ return PlaceNew(block, position, rotation, color, material, uscale, scale, player);
}
///
@@ -61,7 +61,7 @@ namespace GamecraftModdingAPI
///
/// The block's type
/// The block's color
- /// The block color's darkness (0-9) - 0 is default color
+ /// The block's materialr
/// The block's position - default block size is 0.2
/// The block's rotation in degrees
/// The block's uniform scale - default scale is 1 (with 0.2 width)
@@ -69,12 +69,12 @@ namespace GamecraftModdingAPI
/// The player who placed the block
/// The placed block or null if failed
public static T PlaceNew(BlockIDs block, float3 position,
- float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
+ float3 rotation = default, BlockColor? color = null, BlockMaterial material = BlockMaterial.Default,
int uscale = 1, float3 scale = default, Player player = null) where T : Block
{
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
- var egid = PlacementEngine.PlaceBlock(block, color, darkness,
+ var egid = PlacementEngine.PlaceBlock(block, color ?? BlockColors.Default, material,
position, uscale, scale, player, rotation, out var initializer);
var bl = New(egid.entityID, egid.groupID);
bl.InitData.Group = BlockEngine.InitGroup(initializer);
@@ -319,9 +319,7 @@ namespace GamecraftModdingAPI
{
BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, BlockColor val) =>
{
- color.indexInPalette = (byte) (val.Color + val.Darkness * 10);
- //color.overridePaletteColour = false;
- //color.needsUpdate = true;
+ color.indexInPalette = val.Index;
color.hasNetworkChange = true;
color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette);
}, value);
@@ -339,13 +337,18 @@ namespace GamecraftModdingAPI
BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, float4 val) =>
{
color.paletteColour = val;
- //color.overridePaletteColour = true;
- //color.needsUpdate = true;
color.hasNetworkChange = true;
}, value);
}
}
+ public BlockMaterial Material
+ {
+ get => BlockEngine.GetBlockInfo(this, (CubeMaterialStruct cmst) => (BlockMaterial) cmst.materialId);
+ set => BlockEngine.SetBlockInfo(this,
+ (ref CubeMaterialStruct cmst, BlockMaterial val) => cmst.materialId = (byte) val, value);
+ }
+
///
/// The text displayed on the block if applicable, or null.
/// Setting it is temporary to the session, it won't be saved.
@@ -433,7 +436,7 @@ namespace GamecraftModdingAPI
///
public T Copy() where T : Block
{
- var block = PlaceNew(Type, Position, Rotation, Color.Color, Color.Darkness, UniformScale, Scale);
+ var block = PlaceNew(Type, Position, Rotation, Color, Material, UniformScale, Scale);
block.copiedFrom = Id;
return block;
}
diff --git a/GamecraftModdingAPI/Blocks/BlockColor.cs b/GamecraftModdingAPI/Blocks/BlockColor.cs
index bf22090..bb5fa4a 100644
--- a/GamecraftModdingAPI/Blocks/BlockColor.cs
+++ b/GamecraftModdingAPI/Blocks/BlockColor.cs
@@ -5,35 +5,35 @@ namespace GamecraftModdingAPI.Blocks
{
public struct BlockColor
{
- public BlockColors Color;
- public byte Darkness;
+ public BlockColors Color => Index == byte.MaxValue
+ ? BlockColors.Default
+ : (BlockColors) (Index % 10);
- public byte Index => Color == BlockColors.Default
- ? byte.MaxValue
- : (byte) (Darkness * 10 + Color);
+ public byte Darkness => (byte) (Index == byte.MaxValue
+ ? 0
+ : Index / 10);
+
+ public byte Index { get; }
public BlockColor(byte index)
{
- if (index == byte.MaxValue)
- {
- Color = BlockColors.Default;
- Darkness = 0;
- }
- else
- {
- if (index > 99)
- throw new ArgumentOutOfRangeException(nameof(index), "Invalid color index. Must be 0-90 or 255.");
- Color = (BlockColors) (index % 10);
- Darkness = (byte) (index / 10);
- }
+ if (index > 99 && index != byte.MaxValue)
+ throw new ArgumentOutOfRangeException(nameof(index), "Invalid color index. Must be 0-90 or 255.");
+ Index = index;
}
- public BlockColor(BlockColors color, byte darkness)
+ public BlockColor(BlockColors color, byte darkness = 0)
{
if (darkness > 9)
throw new ArgumentOutOfRangeException(nameof(darkness), "Darkness must be 0-9 where 0 is default.");
- Color = color;
- Darkness = darkness;
+ if (color > BlockColors.Red) //Last valid color
+ throw new ArgumentOutOfRangeException(nameof(color), "Invalid color!");
+ Index = (byte) (darkness * 10 + (byte) color);
+ }
+
+ public static implicit operator BlockColor(BlockColors color)
+ {
+ return new BlockColor(color);
}
public float4 RGBA => Block.BlockEngine.ConvertBlockColor(Index);
@@ -47,7 +47,7 @@ namespace GamecraftModdingAPI.Blocks
///
/// Preset block colours
///
- public enum BlockColors
+ public enum BlockColors : byte
{
Default = byte.MaxValue,
White = 0,
diff --git a/GamecraftModdingAPI/Blocks/BlockMaterial.cs b/GamecraftModdingAPI/Blocks/BlockMaterial.cs
new file mode 100644
index 0000000..74d45bb
--- /dev/null
+++ b/GamecraftModdingAPI/Blocks/BlockMaterial.cs
@@ -0,0 +1,12 @@
+namespace GamecraftModdingAPI.Blocks
+{
+ public enum BlockMaterial : byte
+ {
+ Default = byte.MaxValue,
+ SteelBodywork = 0,
+ RigidSteel,
+ CarbonFiber,
+ Plastic,
+ Wood
+ }
+}
\ No newline at end of file
diff --git a/GamecraftModdingAPI/Blocks/PlacementEngine.cs b/GamecraftModdingAPI/Blocks/PlacementEngine.cs
index 506456b..908eadf 100644
--- a/GamecraftModdingAPI/Blocks/PlacementEngine.cs
+++ b/GamecraftModdingAPI/Blocks/PlacementEngine.cs
@@ -40,17 +40,17 @@ namespace GamecraftModdingAPI.Blocks
public EntitiesDB entitiesDB { get; set; }
private static BlockEntityFactory _blockEntityFactory; //Injected from PlaceSingleBlockEngine
- public EGID PlaceBlock(BlockIDs block, BlockColors color, byte darkness, float3 position, int uscale,
+ public EGID PlaceBlock(BlockIDs block, BlockColor color, BlockMaterial materialId, float3 position, int uscale,
float3 scale, Player player, float3 rotation, out EntityInitializer initializer)
{ //It appears that only the non-uniform scale has any visible effect, but if that's not given here it will be set to the uniform one
- if (darkness > 9)
+ if (color.Darkness > 9)
throw new Exception("That is too dark. Make sure to use 0-9 as darkness. (0 is default.)");
- initializer = BuildBlock((ushort) block, (byte) (color + darkness * 10), position, uscale, scale, rotation,
+ initializer = BuildBlock((ushort) block, color.Index, (byte) materialId, position, uscale, scale, rotation,
(player ?? new Player(PlayerType.Local)).Id);
return initializer.EGID;
}
- private EntityInitializer BuildBlock(ushort block, byte color, float3 position, int uscale, float3 scale, float3 rot, uint playerId)
+ private EntityInitializer BuildBlock(ushort block, byte color, byte materialId, float3 position, int uscale, float3 scale, float3 rot, uint playerId)
{
if (_blockEntityFactory == null)
throw new BlockException("The factory is null.");
@@ -81,11 +81,11 @@ namespace GamecraftModdingAPI.Blocks
indexInPalette = color,
hasNetworkChange = true
});
- structInitializer.Init(new CubeMaterialStruct
- {
- materialId = 0, //TODO
- cosmeticallyPaintedOnly = true //TODO
- });
+ if (materialId != byte.MaxValue)
+ structInitializer.Init(new CubeMaterialStruct
+ {
+ materialId = materialId
+ });
uint prefabId = PrefabsID.GetOrCreatePrefabID(block, 0, 0, false); //TODO
structInitializer.Init(new GFXPrefabEntityStructGPUI(prefabId));
structInitializer.Init(new PhysicsPrefabEntityStruct(prefabId));
diff --git a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
index 410c0a5..92b1d7a 100644
--- a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
+++ b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs
@@ -224,8 +224,8 @@ namespace GamecraftModdingAPI.Tests
float.Parse(s[1]), float.Parse(s[2]), float.Parse(s[3]));
return;
}
- new Player(PlayerType.Local).GetBlockLookedAt().Color =
- new BlockColor { Color = color };
+
+ new Player(PlayerType.Local).GetBlockLookedAt().Color = color;
Logging.CommandLog("Colored block to " + color);
}).Build();
diff --git a/GamecraftModdingAPI/Utility/DebugInterfaceEngine.cs b/GamecraftModdingAPI/Utility/DebugInterfaceEngine.cs
index 0e4d023..9c14075 100644
--- a/GamecraftModdingAPI/Utility/DebugInterfaceEngine.cs
+++ b/GamecraftModdingAPI/Utility/DebugInterfaceEngine.cs
@@ -31,8 +31,8 @@ namespace GamecraftModdingAPI.Utility
public void SetInfo(string id, Func contentGetter) => _extraInfo[id] = contentGetter;
public bool RemoveInfo(string id) => _extraInfo.Remove(id);
- public string Name { get; } = "GamecraftModdingAPIDebugInterfaceGameEngine";
- public bool isRemovable { get; } = true;
+ public string Name => "GamecraftModdingAPIDebugInterfaceGameEngine";
+ public bool isRemovable => true;
[HarmonyPatch]
private class Patch