diff --git a/TechbloxModdingAPI/Block.cs b/TechbloxModdingAPI/Block.cs index 391ee62..5917668 100644 --- a/TechbloxModdingAPI/Block.cs +++ b/TechbloxModdingAPI/Block.cs @@ -289,6 +289,7 @@ namespace TechbloxModdingAPI color.indexInPalette = value.Index; color.hasNetworkChange = true; color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette); //Setting to 255 results in black + BlockEngine.UpdateBlockColor(Id); } } diff --git a/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs b/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs index 1cfe0eb..7b83b1e 100644 --- a/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs +++ b/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs @@ -157,6 +157,11 @@ namespace TechbloxModdingAPI.Blocks.Engines //Phyiscs prefab: prefabAssetID, set on block creation from the CubeListData } + public void UpdateBlockColor(EGID id) + { + entitiesDB.PublishEntityChange(id); + } + public bool BlockExists(EGID blockID) { return entitiesDB.Exists(blockID); diff --git a/TechbloxModdingAPI/Player.cs b/TechbloxModdingAPI/Player.cs index 635bb74..68f5e49 100644 --- a/TechbloxModdingAPI/Player.cs +++ b/TechbloxModdingAPI/Player.cs @@ -1,5 +1,6 @@ using System; using Gamecraft.Wires; +using RobocraftX.Blocks.Ghost; using RobocraftX.Character; using RobocraftX.Character.Movement; using Unity.Mathematics; @@ -527,6 +528,15 @@ namespace TechbloxModdingAPI return playerEngine.GetSelectedBlocks(Id); } + /// + /// Returns the ghost block that shows the block to be placed in build mode. + /// + /// A block instance or null if not found + public Block GetGhostBlock() + { + return playerEngine.GetGhostBlock(Id); + } + public bool Equals(Player other) { if (ReferenceEquals(null, other)) return false; diff --git a/TechbloxModdingAPI/Players/PlayerEngine.cs b/TechbloxModdingAPI/Players/PlayerEngine.cs index d5feaf5..441d3ac 100644 --- a/TechbloxModdingAPI/Players/PlayerEngine.cs +++ b/TechbloxModdingAPI/Players/PlayerEngine.cs @@ -9,6 +9,7 @@ using RobocraftX.CR.MachineEditing.BoxSelect; using RobocraftX.Physics; using RobocraftX.Blocks.Ghost; using Gamecraft.GUI.HUDFeedbackBlocks; +using RobocraftX.Common; using RobocraftX.Multiplayer; using RobocraftX.SimulationModeState; using Svelto.ECS; @@ -270,5 +271,11 @@ namespace TechbloxModdingAPI.Players .QueryUniqueEntity(MultiplayerExclusiveGroups.MultiplayerStateGroup) .networkStats.PingMs; } + + public Block GetGhostBlock(uint playerId) + { + var egid = new EGID(playerId, GHOST_BLOCKS_ENABLED.Group); + return entitiesDB.Exists(egid) ? Block.New(egid) : null; + } } } diff --git a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs index 9c80ecd..7b225d0 100644 --- a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs +++ b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs @@ -343,6 +343,28 @@ namespace TechbloxModdingAPI.Tests Logging.CommandLog(asset); } }).Build(); + + bool shouldTestGhostBlock = false; + CommandBuilder.Builder("testGhostBlock") + .Action(() => + { + if (shouldTestGhostBlock) + { + shouldTestGhostBlock = false; + Logging.CommandLog("Test disabled"); + } + + shouldTestGhostBlock = true; + Scheduler.Schedule(new Repeatable(() => + { + var ghostBlock = Player.LocalPlayer.GetGhostBlock(); + if (ghostBlock == null) return; + ghostBlock.Position = Player.LocalPlayer.Position + 2; + ghostBlock.Color = new BlockColor(BlockColors.Lime); + }, () => shouldTestGhostBlock)); + Logging.CommandLog("Test enabled"); + }).Build(); + Client.EnterMenu += (sender, args) => Scheduler.Schedule(new Once(() => Client.Instance.CloseBetaPopup())); Game.Enter += (sender, args) =>