Fix block color and group
This commit is contained in:
parent
58d703f502
commit
4f0645492c
4 changed files with 30 additions and 6 deletions
|
@ -195,7 +195,7 @@ namespace TechbloxModdingAPI
|
||||||
if (value.y < 4e-5) value.y = uscale;
|
if (value.y < 4e-5) value.y = uscale;
|
||||||
if (value.z < 4e-5) value.z = uscale;
|
if (value.z < 4e-5) value.z = uscale;
|
||||||
BlockEngine.GetBlockInfo<ScalingEntityStruct>(this).scale = value;
|
BlockEngine.GetBlockInfo<ScalingEntityStruct>(this).scale = value;
|
||||||
BlockEngine.GetBlockInfo<GridScaleStruct>(this).gridScale = value - (int3) value + 1;
|
//BlockEngine.GetBlockInfo<GridScaleStruct>(this).gridScale = value - (int3) value + 1;
|
||||||
if (!Exists) return; //UpdateCollision needs the block to exist
|
if (!Exists) return; //UpdateCollision needs the block to exist
|
||||||
ScalingEngine.UpdateCollision(Id);
|
ScalingEngine.UpdateCollision(Id);
|
||||||
BlockEngine.UpdateDisplayedBlock(Id);
|
BlockEngine.UpdateDisplayedBlock(Id);
|
||||||
|
@ -225,7 +225,7 @@ namespace TechbloxModdingAPI
|
||||||
get => BlockEngine.GetBlockInfo<ScalingEntityStruct>(this).scale.x < 0;
|
get => BlockEngine.GetBlockInfo<ScalingEntityStruct>(this).scale.x < 0;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
var st = 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, (ushort) Type, (byte) Material, value);
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ namespace TechbloxModdingAPI
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
//TODO: Check if setting to 255 works
|
//TODO: Check if setting to 255 works
|
||||||
var color = BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(this);
|
ref var color = ref BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(this);
|
||||||
color.indexInPalette = value.Index;
|
color.indexInPalette = value.Index;
|
||||||
color.hasNetworkChange = true;
|
color.hasNetworkChange = true;
|
||||||
color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette);
|
color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette);
|
||||||
|
@ -311,7 +311,7 @@ namespace TechbloxModdingAPI
|
||||||
private BlockGroup blockGroup;
|
private BlockGroup blockGroup;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the block group this block is a part of. Block groups can also be placed using blueprints.
|
/// Returns the block group this block is a part of. Block groups can also be placed using blueprints.
|
||||||
/// Returns null if not part of a group.<br />
|
/// Returns null if not part of a group, although all blocks should have their own by default.<br />
|
||||||
/// Setting the group after the block has been initialized will not update everything properly,
|
/// Setting the group after the block has been initialized will not update everything properly,
|
||||||
/// so you can only set this property on blocks newly placed by your code.<br />
|
/// so you can only set this property on blocks newly placed by your code.<br />
|
||||||
/// To set it for existing blocks, you can use the Copy() method and set the property on the resulting block
|
/// To set it for existing blocks, you can use the Copy() method and set the property on the resulting block
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace TechbloxModdingAPI.Blocks
|
||||||
{
|
{
|
||||||
if (darkness > 9)
|
if (darkness > 9)
|
||||||
throw new ArgumentOutOfRangeException(nameof(darkness), "Darkness must be 0-9 where 0 is default.");
|
throw new ArgumentOutOfRangeException(nameof(darkness), "Darkness must be 0-9 where 0 is default.");
|
||||||
if (color > BlockColors.Red) //Last valid color
|
if (color > BlockColors.Red && color != BlockColors.Default) //Last valid color
|
||||||
throw new ArgumentOutOfRangeException(nameof(color), "Invalid color!");
|
throw new ArgumentOutOfRangeException(nameof(color), "Invalid color!");
|
||||||
Index = (byte) (darkness * 10 + (byte) color);
|
Index = (byte) (darkness * 10 + (byte) color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using DataLoader;
|
using DataLoader;
|
||||||
|
using Gamecraft.Blocks.BlockGroups;
|
||||||
using Gamecraft.Wires;
|
using Gamecraft.Wires;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using RobocraftX.Blocks;
|
using RobocraftX.Blocks;
|
||||||
|
@ -40,6 +41,7 @@ namespace TechbloxModdingAPI.Blocks
|
||||||
|
|
||||||
public EntitiesDB entitiesDB { get; set; }
|
public EntitiesDB entitiesDB { get; set; }
|
||||||
private static BlockEntityFactory _blockEntityFactory; //Injected from PlaceSingleBlockEngine
|
private static BlockEntityFactory _blockEntityFactory; //Injected from PlaceSingleBlockEngine
|
||||||
|
private static IEntityFactory _entityFactory;
|
||||||
|
|
||||||
public EntityInitializer PlaceBlock(BlockIDs block, float3 position, Player player, bool autoWire)
|
public EntityInitializer PlaceBlock(BlockIDs block, float3 position, Player player, bool autoWire)
|
||||||
{ //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
|
{ //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
|
||||||
|
@ -79,6 +81,25 @@ namespace TechbloxModdingAPI.Blocks
|
||||||
triggerAutoWiring = autoWire && structInitializer.Has<BlockPortsStruct>()
|
triggerAutoWiring = autoWire && structInitializer.Has<BlockPortsStruct>()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*structInitializer.Init(new OverrideStaticComponent()
|
||||||
|
{ //TODO
|
||||||
|
staticIfUnconnected = true
|
||||||
|
});*/
|
||||||
|
|
||||||
|
int nextFilterId = BlockGroupUtility.NextFilterId;
|
||||||
|
structInitializer.Init(new BlockGroupEntityComponent
|
||||||
|
{
|
||||||
|
currentBlockGroup = nextFilterId
|
||||||
|
});
|
||||||
|
_entityFactory.BuildEntity<BlockGroupEntityDescriptor>((uint) nextFilterId,
|
||||||
|
BlockGroupExclusiveGroups.BlockGroupEntityGroup)
|
||||||
|
.Init(new BlockGroupTransformEntityComponent
|
||||||
|
{
|
||||||
|
blockGroupGridRotation = quaternion.identity,
|
||||||
|
blockGroupGridPosition = position
|
||||||
|
});
|
||||||
|
|
||||||
foreach (var group in CharacterExclusiveGroups.AllCharacters)
|
foreach (var group in CharacterExclusiveGroups.AllCharacters)
|
||||||
{
|
{
|
||||||
EGID playerEGID = new EGID(playerId, group);
|
EGID playerEGID = new EGID(playerId, group);
|
||||||
|
@ -98,9 +119,10 @@ namespace TechbloxModdingAPI.Blocks
|
||||||
[HarmonyPatch]
|
[HarmonyPatch]
|
||||||
public class FactoryObtainerPatch
|
public class FactoryObtainerPatch
|
||||||
{
|
{
|
||||||
static void Postfix(BlockEntityFactory blockEntityFactory)
|
static void Postfix(BlockEntityFactory blockEntityFactory, IEntityFactory entityFactory)
|
||||||
{
|
{
|
||||||
_blockEntityFactory = blockEntityFactory;
|
_blockEntityFactory = blockEntityFactory;
|
||||||
|
_entityFactory = entityFactory;
|
||||||
Logging.MetaDebugLog("Block entity factory injected.");
|
Logging.MetaDebugLog("Block entity factory injected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,8 @@ 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