Compare commits

..

No commits in common. "master" and "v1.1.0" have entirely different histories.

9 changed files with 872 additions and 1736 deletions

View file

@ -1,7 +1,7 @@
using System.Linq; using System.Linq;
using TechbloxModdingAPI; using GamecraftModdingAPI;
using TechbloxModdingAPI.Blocks; using GamecraftModdingAPI.Blocks;
using TechbloxModdingAPI.Utility; using GamecraftModdingAPI.Utility;
namespace BuildingTools namespace BuildingTools
{ {
@ -21,9 +21,17 @@ namespace BuildingTools
return false; return false;
} }
public Block[] SelectBlocks(byte id)
{
var blocks = ObjectIdentifier.GetBySimID(id).SelectMany(block => block.GetConnectedCubes()).ToArray();
return blocks;
}
public Block[] SelectBlocks(char id) public Block[] SelectBlocks(char id)
{ {
return ObjectID.GetByID(id).SelectMany(oid => oid.GetConnectedCubes()).ToArray(); var blocks = ObjectIdentifier.GetByID(id).SelectMany(oid => oid.GetConnectedCubes())
.ToArray();
return blocks;
} }
} }
} }

View file

@ -1,21 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using DataLoader; using DataLoader;
using HarmonyLib; using GamecraftModdingAPI;
using TechbloxModdingAPI; using GamecraftModdingAPI.Blocks;
using TechbloxModdingAPI.Blocks; using GamecraftModdingAPI.Commands;
using TechbloxModdingAPI.Commands; using GamecraftModdingAPI.Utility;
using TechbloxModdingAPI.Utility;
using IllusionPlugin; using IllusionPlugin;
using RobocraftX.Schedulers;
using Svelto.Tasks;
using Svelto.Tasks.Enumerators;
using Svelto.Tasks.Lean;
using TechbloxModdingAPI.App;
using Unity.Mathematics; using Unity.Mathematics;
using Main = TechbloxModdingAPI.Main; using Main = GamecraftModdingAPI.Main;
namespace BuildingTools namespace BuildingTools
{ {
@ -24,8 +17,6 @@ namespace BuildingTools
private readonly CommandUtils _commandUtils; private readonly CommandUtils _commandUtils;
private readonly BlockSelections _blockSelections; private readonly BlockSelections _blockSelections;
//private readonly MirrorModeEngine _mirrorModeEngine = new MirrorModeEngine();
public BuildingTools() public BuildingTools()
{ {
_blockSelections = new BlockSelections(); _blockSelections = new BlockSelections();
@ -35,8 +26,8 @@ namespace BuildingTools
public override void OnApplicationStart() public override void OnApplicationStart()
{ {
Main.Init(); Main.Init();
Game.AddPersistentDebugInfo("PlayerInfo", GetPlayerInfo); GameClient.SetDebugInfo("PlayerInfo", GetPlayerInfo);
Game.AddPersistentDebugInfo("BlockModInfo", GetBlockInfo); GameClient.SetDebugInfo("BlockModInfo", GetBlockInfo);
_commandUtils.RegisterBlockCommand("scaleBlocks", _commandUtils.RegisterBlockCommand("scaleBlocks",
"Scales the selected blocks, relative to current size (current scale * new scale)." + "Scales the selected blocks, relative to current size (current scale * new scale)." +
" The block you're looking at stays where it is, everything else is moved next to it.", " The block you're looking at stays where it is, everything else is moved next to it.",
@ -44,6 +35,7 @@ namespace BuildingTools
{ {
if (!GameState.IsBuildMode()) return; //Scaling & positioning is weird in simulation if (!GameState.IsBuildMode()) return; //Scaling & positioning is weird in simulation
if (_blockSelections.CheckNoBlocks(blocks)) return; if (_blockSelections.CheckNoBlocks(blocks)) return;
// ReSharper disable once PossibleNullReferenceException
float3? reference = Player.LocalPlayer.GetBlockLookedAt()?.Position; float3? reference = Player.LocalPlayer.GetBlockLookedAt()?.Position;
if (!reference.HasValue) if (!reference.HasValue)
{ {
@ -89,32 +81,12 @@ namespace BuildingTools
} }
foreach (var block in blocks) foreach (var block in blocks)
block.Color = new BlockColor(clr, darkness); block.Color = new BlockColor {Color = clr, Darkness = darkness};
Logging.CommandLog("Blocks colored."); Logging.CommandLog("Blocks colored.");
}); });
_commandUtils.RegisterBlockCommand("materialBlocks", "Sets the material of the selected blocks permanently both in time stopped and running. It won't be reset when stopping time.",
(material, darkness, blocks, refBlock) =>
{
if (!Enum.TryParse(material, true, out BlockMaterial mat))
{
Logging.CommandLogWarning("Material " + material + " not found");
}
IEnumerator<TaskContract> SetMaterial()
{
foreach (var block in blocks)
{
block.Material = mat;
yield return new WaitForSecondsEnumerator(0.2f).Continue();
}
}
SetMaterial().RunOn(ClientLean.UIScheduler);
Logging.CommandLog("Block materials set.");
});
CommandBuilder.Builder("selectBlocksLookedAt", CommandBuilder.Builder("selectBlocksLookedAt",
"Selects blocks (1 or more) to change. Only works in time stopped mode." + "Selects blocks (1 or more) to change. Only works in time stopped mode, however the blocks can be changed afterwards in both modes." +
" Parameter: whether one (true) or all connected (false) blocks should be selected.") " Parameter: whether one (true) or all connected (false) blocks should be selected.")
.Action<bool>(single => .Action<bool>(single =>
{ {
@ -138,8 +110,8 @@ namespace BuildingTools
.Action<char>(id => .Action<char>(id =>
{ {
_blockSelections.blocks = _blockSelections.blocks =
(_blockSelections.refBlock = ObjectID.GetByID(id).FirstOrDefault()) (_blockSelections.refBlock = ObjectIdentifier.GetByID(id).FirstOrDefault())
?.GetConnectedCubes() ?? Array.Empty<Block>(); ?.GetConnectedCubes() ?? new Block[0];
Logging.CommandLog(_blockSelections.blocks.Length + " blocks selected."); Logging.CommandLog(_blockSelections.blocks.Length + " blocks selected.");
}).Build(); }).Build();
CommandBuilder.Builder("selectSelectedBlocks", "Selects blocks that are box selected by the player.") CommandBuilder.Builder("selectSelectedBlocks", "Selects blocks that are box selected by the player.")
@ -221,7 +193,7 @@ namespace BuildingTools
uint refID = _blockSelections.refBlock.Id.entityID; uint refID = _blockSelections.refBlock.Id.entityID;
if (group is null) if (group is null)
{ {
var copy = _blockSelections.refBlock.Copy(); var copy = _blockSelections.refBlock.Copy<Block>();
group = BlockGroup.Create(copy); group = BlockGroup.Create(copy);
_blockSelections.refBlock.Remove(); _blockSelections.refBlock.Remove();
_blockSelections.refBlock = copy; _blockSelections.refBlock = copy;
@ -231,16 +203,17 @@ namespace BuildingTools
.Select(block => .Select(block =>
{ {
if (block.BlockGroup == group) return block; if (block.BlockGroup == group) return block;
var copy = block.Copy(); var copy = block.Copy<Block>();
group.Add(copy); group.Add(copy);
block.Remove(); block.Remove();
return copy; return copy;
}).ToArray(); }).ToArray();
}).Build(); }).Build();
var setLimits = new SetLimitsCommandEngine();
CommandBuilder.Builder("setBuildLimits", "Set build limits").Action((Action<int, int, int>)setLimits.SetLimits).Build();
GameEngineManager.AddGameEngine(setLimits);
var noClip = new NoClipCommand();
GameEngineManager.AddGameEngine(noClip);
CommandBuilder.Builder("noclip", "Allows you to go through blocks. Run again to disable. Disable before entering the menu.")
.Action(noClip.Toggle).Build();
CommandBuilder.Builder("freeScaling", "This command removes scaling restrictions on the selected block. Reselect block to apply.") CommandBuilder.Builder("freeScaling", "This command removes scaling restrictions on the selected block. Reselect block to apply.")
.Action(() => .Action(() =>
{ {
@ -252,55 +225,8 @@ namespace BuildingTools
} }
FullGameFields._dataDb.GetValue<CubeListData>((int) blockID).scalingPermission = FullGameFields._dataDb.GetValue<CubeListData>((int) blockID).scalingPermission =
ScalingPermission.NonUniform; ScalingPermission.NonUniform;
Logging.CommandLog("Free scaling enabled for " + blockID + " until the game is restarted. Reselect block to apply."); Logging.CommandLog("Free scaling enabled for " + blockID + " until the game is restarted.");
}).Build(); }).Build();
CommandBuilder.Builder("setTweakLimit",
"Sets the limit on the tweakable stat on selected block. Usage: setTweakLimit [stat] [value]. Sets all stats to 1000 by default.")
.Action((string stat, int value) =>
{
var bl = Player.LocalPlayer.SelectedBlock;
if (bl == BlockIDs.Invalid)
{
Logging.CommandLogError("Select the block in the inventory first.");
return;
}
if (!FullGameFields._dataDb.TryGetValue<TweakableStatsData>((int)bl, out var data))
{
Logging.CommandLogError($"No tweakable stats found on {bl} (selected)");
return;
}
TweakPropertyInfo[] stats;
if (stat is null || stat.Length == 0)
{
stats = data.Stats;
}
else
{
if (!data.statsByName.TryGetValue(stat, out var statInfo))
{
Logging.CommandLogError($"Tweakable stat {stat} not found. Stats: {data.statsByName.Keys.Aggregate((a, b) => a + ", " + b)}");
return;
}
stats = new[] { statInfo };
}
foreach (var statInfo in stats)
{
statInfo.max = value == 0 ? 1000 : value;
statInfo.min = -1000;
}
Logging.CommandLog($"{(stat is null || stat.Length == 0 ? "All stats" : $"Stat {stat}")} max changed to {(value == 0 ? 1000 : value)} on {bl}");
}).Build();
//_mirrorModeEngine.Init();
UI.Init();
new Harmony("BuildTools").PatchAll(Assembly.GetExecutingAssembly());
} }
private string GetBlockInfo() private string GetBlockInfo()
@ -316,32 +242,17 @@ namespace BuildingTools
private static string GetBlockInfoInBuildMode() private static string GetBlockInfoInBuildMode()
{ {
var block = Player.LocalPlayer.GetBlockLookedAt(); var block = Player.LocalPlayer.GetBlockLookedAt();
if (block == null) return GetWireInfoInBuildMode(); if (block == null) return "";
float3 pos = block.Position; float3 pos = block.Position;
float3 rot = block.Rotation; float3 rot = block.Rotation;
float3 scale = block.Scale; float3 scale = block.Scale;
return $"Block: {block.Type} at {pos.x:F} {pos.y:F} {pos.z:F}\n" + return $"Block: {block.Type} at {pos.x:F} {pos.y:F} {pos.z:F}\n" +
$"- Rotation: {rot.x:F}° {rot.y:F}° {rot.z:F}°\n" + $"- Rotation: {rot.x:F}° {rot.y:F}° {rot.z:F}°\n" +
$"- Color: {block.Color.Color} darkness: {block.Color.Darkness}\n" + $"- Color: {block.Color.Color} darkness: {block.Color.Darkness}\n" +
$"- Material: {block.Material}\n" +
$"- Scale: {scale.x:F} {scale.y:F} {scale.z:F}\n" + $"- Scale: {scale.x:F} {scale.y:F} {scale.z:F}\n" +
$"- Label: {block.Label}\n" + $"- Label: {block.Label}\n" +
$"- ID: {block.Id}\n" + $"- ID: {block.Id}\n" +
(block.BlockGroup != null ? $"- Group: {block.BlockGroup.Id}\n" : "") + $"- Group: {block.BlockGroup.Id}";
$"- Mass: {block.Mass}";
}
private static string GetWireInfoInBuildMode()
{
var wire = Player.LocalPlayer.GetWireLookedAt();
if (wire == null) return "";
var startPos = wire.Start.Position;
var endPos = wire.End.Position;
return $"Wire with {wire.Id}\n" +
$"- From block {wire.Start.Type} at {startPos.x:F} {startPos.y:F} {startPos.z:F}\n" +
$"- at port {wire.StartPortName}\n" +
$"- To block {wire.End.Type} at {endPos.x:F} {endPos.y:F} {endPos.z:F}\n" +
$"- at port {wire.EndPortName}";
} }
private static string GetBodyInfoInSimMode() private static string GetBodyInfoInSimMode()
@ -358,37 +269,36 @@ namespace BuildingTools
$"- Rotation: {rot.x:F}° {rot.y:F}° {rot.z:F}°\n" + $"- Rotation: {rot.x:F}° {rot.y:F}° {rot.z:F}°\n" +
$"- Velocity: {vel.x:F} {vel.y:F} {vel.z:F}\n" + $"- Velocity: {vel.x:F} {vel.y:F} {vel.z:F}\n" +
$"- Angular velocity: {ave.x:F} {ave.y:F} {ave.z:F}\n" + $"- Angular velocity: {ave.x:F} {ave.y:F} {ave.z:F}\n" +
$"- {(body.Static ? "Static body" : $"Center of mass: {com.x:F} {com.y:F} {com.z:F}")}\n" + $"- {(body.Static ? "Static body" : $"Mass: {body.Mass:F} center: {com.x:F} {com.y:F} {com.z:F}")}\n" +
$"- Volume: {body.Volume:F}\n" + $"- Volume: {body.Volume:F}\n" +
$"- Chunk health: {body.CurrentHealth:F} / {body.InitialHealth:F} - Multiplier: {body.HealthMultiplier:F}\n" + $"- Chunk health: {body.CurrentHealth:F} / {body.InitialHealth:F} - Multiplier: {body.HealthMultiplier:F}\n" +
(cluster == null (cluster == null
? "" ? ""
: $"- Cluster health: {cluster.CurrentHealth:F} / {cluster.InitialHealth:F} - Multiplier: {cluster.HealthMultiplier:F}\n" + : $"- Cluster health: {cluster.CurrentHealth:F} / {cluster.InitialHealth:F} - Multiplier: {cluster.HealthMultiplier:F}"
$"- Cluster mass: {cluster.Mass}"
); );
} }
private string GetPlayerInfo() private string GetPlayerInfo()
{ {
var player = Player.LocalPlayer; var player = Player.LocalPlayer;
if (player == null) return ""; if (player == null) return GetBlockInfoInBuildMode();
float3 pos = player.Position; float3 pos = player.Position;
float3 rot = player.Rotation; float3 rot = player.Rotation;
float3 vel = player.Velocity; float3 vel = player.Velocity;
float3 ave = player.AngularVelocity; float3 ave = player.AngularVelocity;
return $"Player position: {pos.x:F} {pos.y:F} {pos.z:F}\n" + return $"Player rotation: {rot.x:F}° {rot.y:F}° {rot.z:F}°\n" +
$"- Rotation: {rot.x:F}° {rot.y:F}° {rot.z:F}°\n" +
$"- Velocity: {vel.x:F} {vel.y:F} {vel.z:F}\n" + $"- Velocity: {vel.x:F} {vel.y:F} {vel.z:F}\n" +
$"- Angular velocity: {ave.x:F} {ave.y:F} {ave.z:F}\n" + $"- Angular velocity: {ave.x:F} {ave.y:F} {ave.z:F}\n" +
$"- Mass: {player.Mass:F}\n" +
$"- Health: {player.CurrentHealth:F} / {player.InitialHealth:F}"; $"- Health: {player.CurrentHealth:F} / {player.InitialHealth:F}";
} }
private IEnumerable<SimBody> GetSimBodies(Block[] blocks) private IEnumerable<SimBody> GetSimBodies(Block[] blocks)
=> blocks.Select(block => block.GetSimBody()).Where(block => !(block is null)).Distinct(); => blocks.Select(block => block.GetSimBody()).Distinct();
public override void OnApplicationQuit() => Main.Shutdown(); public override void OnApplicationQuit() => Main.Shutdown();
public override string Name => "BuildingTools"; public override string Name { get; } = "BuildingTools";
public override string Version => "v1.1.0"; public override string Version { get; } = "v1.1.0";
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,9 @@
using System; using System;
using Gamecraft.Wires; using Gamecraft.Wires;
using TechbloxModdingAPI; using GamecraftModdingAPI;
using TechbloxModdingAPI.Commands; using GamecraftModdingAPI.Commands;
using TechbloxModdingAPI.Utility; using GamecraftModdingAPI.Utility;
using RobocraftX.CommandLine.Custom;
namespace BuildingTools namespace BuildingTools
{ {
@ -21,6 +22,12 @@ namespace BuildingTools
{ {
action(a1, _blockSelections.blocks, _blockSelections.refBlock); action(a1, _blockSelections.blocks, _blockSelections.refBlock);
}).Build(); }).Build();
ConsoleCommands.RegisterWithChannel<string>(name + "Chan", (a1, ch) =>
{
Console.WriteLine($"Command {name} with args {a1} and channel {ch} executing");
var blks = _blockSelections.SelectBlocks(ch);
action(a1, blks, blks[0]);
}, ChannelType.Object, desc);
} }
public void RegisterBlockCommand(string name, string desc, Action<float, float, float, Block[], Block> action) public void RegisterBlockCommand(string name, string desc, Action<float, float, float, Block[], Block> action)

View file

@ -1,122 +0,0 @@
using System;
using System.Collections.Generic;
using Gamecraft.GUI.Blueprints;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Common;
using RobocraftX.CR.MachineEditing.BoxSelect;
using RobocraftX.Physics;
using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Svelto.Tasks;
using Svelto.Tasks.Enumerators;
using Svelto.Tasks.Lean;
using Techblox.Blocks;
using TechbloxModdingAPI;
using TechbloxModdingAPI.App;
using TechbloxModdingAPI.Blocks;
using TechbloxModdingAPI.Blocks.Engines;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Interface.IMGUI;
using TechbloxModdingAPI.Players;
using TechbloxModdingAPI.Tasks;
using TechbloxModdingAPI.Utility;
using Unity.Mathematics;
using UnityEngine;
namespace BuildingTools
{
public class MirrorModeEngine : IApiEngine
{
private Button _button;
private bool _enabled;
private Block _lastPlaced;
private Block _ghostBlock;
private float3 _offset;
private void BlockOnPlaced(object sender, BlockPlacedRemovedEventArgs e)
{
if (!_enabled) return;
if (Player.LocalPlayer.BuildingMode != PlayerBuildingMode.BlockMode) return;
if (e.ID == _lastPlaced?.Id) return;
_lastPlaced = e.Block.Copy();
_lastPlaced.Position = MirrorPos(_lastPlaced.Position);
_lastPlaced.Flipped = !_lastPlaced.Flipped;
if (math.abs(_lastPlaced.Rotation.y - 90) < float.Epsilon ||
math.abs(_lastPlaced.Rotation.y - 270) < float.Epsilon)
_lastPlaced.Rotation += new float3(0, 180, 0);
}
private void BlockOnRemoved(object sender, BlockPlacedRemovedEventArgs e)
{
if (!_enabled) return;
if (Player.LocalPlayer.BuildingMode != PlayerBuildingMode.BlockMode) return;
var newpos = MirrorPos(e.Block.Position);
foreach (var block in Game.CurrentGame().GetBlocksInGame())
{
if (math.all(math.abs(block.Position - newpos) < 0.1f))
block.Remove();
}
}
private float3 MirrorPos(float3 pos)
{
pos -= _offset;
pos *= new float3(-1, 1, 1);
pos += _offset;
return pos;
}
public void Init()
{
Block.Placed += BlockOnPlaced;
Block.Removed+=BlockOnRemoved;
Game.Enter += OnGameOnEnter;
Game.Exit += (sender, args) => _button = null;
}
private void OnGameOnEnter(object sender, GameEventArgs args)
{
_button = new Button("Mirror mode");
_button.OnClick += (_, __) =>
{
_enabled = !_enabled;
if(_enabled)
_offset = new float3((float)(Math.Round(Player.LocalPlayer.Position.x / 2, 1) * 2), 0, 0);
};
//TryCreateGhostBlock().RunOn(Scheduler.leanRunner);
}
private IEnumerator<TaskContract> TryCreateGhostBlock()
{
int c = 0;
while (_ghostBlock == null && c++ < 10)
{
Console.WriteLine($"Ghost block is {_ghostBlock} and c is {c}");
try
{
//_ghostBlock = Block.CreateGhostBlock();
Console.WriteLine($"New block: {_ghostBlock}");
_ghostBlock.Position += 1;
}
catch (Exception e)
{
Console.WriteLine(e);
}
yield return new WaitForSecondsEnumerator(1f).Continue();
}
}
public void Ready()
{
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
}
public string Name { get; } = "BuildingToolsMirroModeEngine";
public bool isRemovable { get; } = true;
}
}

View file

@ -0,0 +1,120 @@
using System;
using System.Collections;
using System.Reflection;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Players;
using GamecraftModdingAPI.Utility;
using HarmonyLib;
using RobocraftX.Character;
using RobocraftX.Character.Camera;
using RobocraftX.Character.Factories;
using RobocraftX.Character.Movement;
using RobocraftX.Common;
using RobocraftX.Common.Input;
using RobocraftX.Common.UnityECSWrappers;
using RobocraftX.UECS;
using Svelto.ECS;
using Svelto.Tasks.ExtraLean;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Physics;
using UnityEngine;
using Collider = Unity.Physics.Collider;
using Yield = Svelto.Tasks.Yield;
namespace BuildingTools
{
public class NoClipCommand : IApiEngine
{
private readonly CollisionFilter _collisionFilter = new CollisionFilter
{ //AddCollidersToRigidBodyEngineUECS._simCubeNoCollisionFilter
BelongsTo = 0,
CollidesWith = 239532
};
private EntityManager _entityManager;
private CollisionFilter _oldFilter;
private bool _enabled;
private void Enable()
{
if (_entityManager == default) _entityManager = FullGameFields._physicsWorld.EntityManager;
Logging.CommandLog("Enabling noclip");
_oldFilter = ChangeCollider(_collisionFilter);
OnUpdate().RunOn(GamecraftModdingAPI.Tasks.Scheduler.extraLeanRunner);
_enabled = true;
Logging.CommandLog("Noclip enabled");
}
private void Disable()
{
Logging.CommandLog("Disabling noclip");
ChangeCollider(_oldFilter);
_enabled = false;
Logging.CommandLog("Noclip disabled");
}
public void Toggle()
{
if (_enabled) Enable();
else Disable();
}
private IEnumerator OnUpdate()
{ //ScreenshotTakerCompositionRoot
while (_enabled)
{
EnsureFlying();
ChangeCollider(_collisionFilter);
if (!entitiesDB.Exists<LocalInputEntityStruct>(0U, CommonExclusiveGroups.GameStateGroup))
{
yield break;
}
yield return Yield.It;
}
}
private CollisionFilter ChangeCollider(CollisionFilter newFilter)
{
foreach (var group in CharacterExclusiveGroups.AllCharacters)
{
if (!entitiesDB.Exists<UECSPhysicsEntityStruct>(new EGID(Player.LocalPlayer.Id, group)))
continue;
ref var uecsEntity =
ref entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(new EGID(Player.LocalPlayer.Id, group));
var collider = _entityManager.GetComponentData<PhysicsCollider>(uecsEntity.uecsEntity);
unsafe
{
var coll = (CompoundCollider*) collider.Value.GetUnsafePtr();
var filter = coll->Filter;
coll->Filter = newFilter;
return filter;
}
}
throw new InvalidOperationException("No character physics found!");
}
private void EnsureFlying()
{
foreach (var ((coll, count), _) in entitiesDB.QueryEntities<CharacterMovementEntityStruct>(CharacterExclusiveGroups.AllCharacters))
for (int i = 0; i < count; i++)
coll[i].moveState = MovementState.Flying;
}
public void Ready()
{
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
}
public string Name { get; } = "BuildingToolsNoClipEngine";
public bool isRemovable { get; } = true;
}
}

View file

@ -1,48 +0,0 @@
using System;
using Svelto.ECS;
using Techblox.Building.Rules;
using Techblox.Building.Rules.Entities;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;
using Unity.Mathematics;
namespace BuildingTools
{
public class SetLimitsCommandEngine : IApiEngine
{
public void Ready()
{
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
}
public void SetLimits(int cpu, int power, int clusters)
{
if (entitiesDB is null)
{
Logging.CommandLog("This command only works in build mode. If you're in build mode, well, report pls.");
return;
}
ref var rules = ref entitiesDB.QueryUniqueEntity<MachineRulesComponent>(GroupCompound<MACHINE, LOCAL>.BuildGroup);
Logging.CommandLog($"Old CPU limit: {rules.cpu.max}, power limit: {rules.power.max}, cluster limit: {rules.clusters.max}");
rules.cpu.max = cpu;
rules.power.max = power;
rules.clusters.max = clusters;
if (BuildRulesUtils.GetLocalMachine(entitiesDB, out var egid))
{
entitiesDB.QueryEntity<MachineVolumeLimitAabbComponent>(egid).aabb =
new AABB { Center = 0, Extents = float.MaxValue };
Logging.CommandLog("Removed volume limits");
}
Logging.CommandLog($"New CPU limit: {rules.cpu.max}, power limit: {rules.power.max}, cluster limit: {rules.clusters.max}");
}
public string Name => "SetLimitsEngine";
public bool isRemovable => true;
}
}

View file

@ -1,45 +0,0 @@
using TechbloxModdingAPI;
using TechbloxModdingAPI.App;
using TechbloxModdingAPI.Interface.IMGUI;
using TechbloxModdingAPI.Tasks;
using Unity.Mathematics;
using UnityEngine;
namespace BuildingTools
{
public class UI
{
private static Label _speedLabel = new Label(new Rect(Screen.width - 200, 0, 200, 20), "Speed: ", "SpeedLabel")
{
Enabled = false
};
public static void Init()
{
Game.Simulate += OnGameOnSimulate;
Game.Edit += OnGameOnEditOrExit;
Game.Exit += OnGameOnEditOrExit;
}
private static void OnGameOnSimulate(object sender, GameEventArgs args)
{
_speedLabel.Enabled = true;
Scheduler.Schedule(new Repeatable(UpdateTask, ShouldLabelBeUpdated));
}
private static void OnGameOnEditOrExit(object sender, GameEventArgs args)
{
_speedLabel.Enabled = false;
}
private static void UpdateTask()
{
_speedLabel.Text = $"Speed: {math.length(Player.LocalPlayer?.Velocity ?? 0) * 3.6:F} km/h";
}
private static bool ShouldLabelBeUpdated()
{
return _speedLabel.Enabled;
}
}
}

View file

@ -1,6 +1,7 @@
# BuildingTools # BuildingTools
Tools for building games, mainly focused on changing and displaying (F3) block properties. Tools for building games, mainly focused on changing and displaying (F3) block properties.
And no clip.
## Commands ## Commands
### Selection commands ### Selection commands
@ -58,6 +59,12 @@ Only works in time running mode.
### Push player ### Push player
The `pushPlayer` and `pushRotatePlayer` commands will apply a specified (regular or angular) force to the player in any mode. The `pushPlayer` and `pushRotatePlayer` commands will apply a specified (regular or angular) force to the player in any mode.
### No clip
The `noClip` command allows you to go through blocks. Run to toggle.
It works in both time stopped and running modes.
**Always exit noClip before leaving a game save or it will crash the game at the moment.**
### Examples ### Examples
* Select and move box selected blocks by 5 blocks in the +X direction: * Select and move box selected blocks by 5 blocks in the +X direction:
``` ```