|
|
@@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using Gamecraft.Wires; |
|
|
|
using Gamecraft.Wires.ChannelsCommon; |
|
|
|
using GamecraftModdingAPI; |
|
|
|
using GamecraftModdingAPI.Blocks; |
|
|
@@ -90,6 +91,12 @@ namespace BlockMod |
|
|
|
refBlock = blocks.Length > 0 ? blocks[0] : null; |
|
|
|
}).Build(); |
|
|
|
|
|
|
|
ConsoleCommands.RegisterWithChannel("selectSendSignal", ch => |
|
|
|
{ |
|
|
|
|
|
|
|
}, ChannelType.Object, |
|
|
|
"Sends a signal for selecting a given object ID for a command block."); |
|
|
|
|
|
|
|
RegisterBlockCommand("pushBlocks", "Adds velocity to the selected blocks. Only works in simulation.", |
|
|
|
(x, y, z, blocks, refBlock) => |
|
|
|
{ |
|
|
@@ -118,35 +125,43 @@ namespace BlockMod |
|
|
|
private string GetBlockInfo() |
|
|
|
{ |
|
|
|
if (GameState.IsBuildMode()) |
|
|
|
{ |
|
|
|
var block = new Player(PlayerType.Local).GetBlockLookedAt(); |
|
|
|
float3 pos = block.Position; |
|
|
|
float3 rot = block.Rotation; |
|
|
|
float3 scale = block.Scale; |
|
|
|
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" + |
|
|
|
$"- Color: {block.Color.Color} darkness: {block.Color.Darkness}\n" + |
|
|
|
$"- Scale: {scale.x:F} {scale.y:F} {scale.z:F}\n" + |
|
|
|
$"- Label: {block.Label}"; |
|
|
|
} |
|
|
|
return GetBlockInfoInBuildMode(); |
|
|
|
if (GameState.IsSimulationMode()) |
|
|
|
{ |
|
|
|
var body = new Player(PlayerType.Local).GetSimBodyLookedAt(); |
|
|
|
float3 pos = body.Position; |
|
|
|
float3 rot = body.Rotation; |
|
|
|
float3 vel = body.Velocity; |
|
|
|
float3 ave = body.AngularVelocity; |
|
|
|
float3 com = body.CenterOfMass; |
|
|
|
return $"Body at {pos.x:F} {pos.y:F} {pos.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" + |
|
|
|
$"- Angular velocity: {ave.x:F} {ave.y:F} {ave.z:F}\n" + |
|
|
|
$"- {(body.Static ? "Static body" : $"Mass: {body.Mass:F} center: {com.x:F} {com.y:F} {com.z:F}")}"; |
|
|
|
} |
|
|
|
return GetBodyInfoInSimMode(); |
|
|
|
|
|
|
|
return "Switching modes..."; |
|
|
|
} |
|
|
|
|
|
|
|
private static string GetBlockInfoInBuildMode() |
|
|
|
{ |
|
|
|
var block = new Player(PlayerType.Local).GetBlockLookedAt(); |
|
|
|
if (block == null) return ""; |
|
|
|
float3 pos = block.Position; |
|
|
|
float3 rot = block.Rotation; |
|
|
|
float3 scale = block.Scale; |
|
|
|
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" + |
|
|
|
$"- Color: {block.Color.Color} darkness: {block.Color.Darkness}\n" + |
|
|
|
$"- Scale: {scale.x:F} {scale.y:F} {scale.z:F}\n" + |
|
|
|
$"- Label: {block.Label}"; |
|
|
|
} |
|
|
|
|
|
|
|
private static string GetBodyInfoInSimMode() |
|
|
|
{ |
|
|
|
var body = new Player(PlayerType.Local).GetSimBodyLookedAt(); |
|
|
|
if (body == null) return GetBlockInfoInBuildMode(); |
|
|
|
float3 pos = body.Position; |
|
|
|
float3 rot = body.Rotation; |
|
|
|
float3 vel = body.Velocity; |
|
|
|
float3 ave = body.AngularVelocity; |
|
|
|
float3 com = body.CenterOfMass; |
|
|
|
return $"Body at {pos.x:F} {pos.y:F} {pos.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" + |
|
|
|
$"- Angular velocity: {ave.x:F} {ave.y:F} {ave.z:F}\n" + |
|
|
|
$"- {(body.Static ? "Static body" : $"Mass: {body.Mass:F} center: {com.x:F} {com.y:F} {com.z:F}")}"; |
|
|
|
} |
|
|
|
|
|
|
|
private bool CheckNoBlocks(Block[] blocks) |
|
|
|
{ |
|
|
|
if (blocks.Length == 0) |
|
|
@@ -179,7 +194,7 @@ namespace BlockMod |
|
|
|
var blks = SelectBlocks(ch); |
|
|
|
if (CheckNoBlocks(blks)) return; |
|
|
|
action(a1, a2, blks, blks[0]); |
|
|
|
}, BinaryChannelUtilities.ChannelType.Object, desc); |
|
|
|
}, ChannelType.Object, desc); |
|
|
|
} |
|
|
|
|
|
|
|
private void RegisterBlockCommand(string name, string desc, Action<float, float, float, Block[], Block> action) |
|
|
@@ -195,7 +210,7 @@ namespace BlockMod |
|
|
|
var blks = SelectBlocks(ch); |
|
|
|
if (CheckNoBlocks(blks)) return; |
|
|
|
action(x, y, z, blks, blks[0]); |
|
|
|
}, BinaryChannelUtilities.ChannelType.Object, desc); |
|
|
|
}, ChannelType.Object, desc); |
|
|
|
} |
|
|
|
|
|
|
|
public void OnApplicationQuit() |
|
|
|