Browse Source

Add method to get ghost block

tags/v2.2.0
NorbiPeti 2 years ago
parent
commit
0ec47cd38b
5 changed files with 45 additions and 0 deletions
  1. +1
    -0
      TechbloxModdingAPI/Block.cs
  2. +5
    -0
      TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs
  3. +10
    -0
      TechbloxModdingAPI/Player.cs
  4. +7
    -0
      TechbloxModdingAPI/Players/PlayerEngine.cs
  5. +22
    -0
      TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs

+ 1
- 0
TechbloxModdingAPI/Block.cs View File

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



+ 5
- 0
TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs View File

@@ -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<ColourParameterEntityStruct>(id);
}

public bool BlockExists(EGID blockID)
{
return entitiesDB.Exists<BlockTagEntityStruct>(blockID);


+ 10
- 0
TechbloxModdingAPI/Player.cs View File

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

/// <summary>
/// Returns the ghost block that shows the block to be placed in build mode.
/// </summary>
/// <returns>A block instance or null if not found</returns>
public Block GetGhostBlock()
{
return playerEngine.GetGhostBlock(Id);
}

public bool Equals(Player other)
{
if (ReferenceEquals(null, other)) return false;


+ 7
- 0
TechbloxModdingAPI/Players/PlayerEngine.cs View File

@@ -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<NetworkStatsEntityStruct>(MultiplayerExclusiveGroups.MultiplayerStateGroup)
.networkStats.PingMs;
}

public Block GetGhostBlock(uint playerId)
{
var egid = new EGID(playerId, GHOST_BLOCKS_ENABLED.Group);
return entitiesDB.Exists<DBEntityStruct>(egid) ? Block.New(egid) : null;
}
}
}

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

@@ -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) =>


Loading…
Cancel
Save