Fix block color and group

This commit is contained in:
Norbi Peti 2021-05-18 00:44:09 +02:00
parent 58d703f502
commit 4f0645492c
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 30 additions and 6 deletions

View file

@ -195,7 +195,7 @@ namespace TechbloxModdingAPI
if (value.y < 4e-5) value.y = uscale;
if (value.z < 4e-5) value.z = uscale;
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
ScalingEngine.UpdateCollision(Id);
BlockEngine.UpdateDisplayedBlock(Id);
@ -225,7 +225,7 @@ namespace TechbloxModdingAPI
get => BlockEngine.GetBlockInfo<ScalingEntityStruct>(this).scale.x < 0;
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);
BlockEngine.UpdatePrefab(this, (ushort) Type, (byte) Material, value);
}
@ -256,7 +256,7 @@ namespace TechbloxModdingAPI
set
{
//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.hasNetworkChange = true;
color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette);
@ -311,7 +311,7 @@ namespace TechbloxModdingAPI
private BlockGroup blockGroup;
/// <summary>
/// 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,
/// 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

View file

@ -26,7 +26,7 @@ namespace TechbloxModdingAPI.Blocks
{
if (darkness > 9)
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!");
Index = (byte) (darkness * 10 + (byte) color);
}

View file

@ -2,6 +2,7 @@ using System;
using System.Reflection;
using DataLoader;
using Gamecraft.Blocks.BlockGroups;
using Gamecraft.Wires;
using HarmonyLib;
using RobocraftX.Blocks;
@ -40,6 +41,7 @@ namespace TechbloxModdingAPI.Blocks
public EntitiesDB entitiesDB { get; set; }
private static BlockEntityFactory _blockEntityFactory; //Injected from PlaceSingleBlockEngine
private static IEntityFactory _entityFactory;
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
@ -79,6 +81,25 @@ namespace TechbloxModdingAPI.Blocks
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)
{
EGID playerEGID = new EGID(playerId, group);
@ -98,9 +119,10 @@ namespace TechbloxModdingAPI.Blocks
[HarmonyPatch]
public class FactoryObtainerPatch
{
static void Postfix(BlockEntityFactory blockEntityFactory)
static void Postfix(BlockEntityFactory blockEntityFactory, IEntityFactory entityFactory)
{
_blockEntityFactory = blockEntityFactory;
_entityFactory = entityFactory;
Logging.MetaDebugLog("Block entity factory injected.");
}

View file

@ -181,6 +181,8 @@ 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();