Start of Machinations...

This commit is contained in:
melchior 2021-05-07 18:55:47 -04:00
parent bbe6c7ab3b
commit bfd828f5f3
7 changed files with 293 additions and 0 deletions

View file

@ -0,0 +1,28 @@
using System;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
namespace Machinations
{
public class LocalClientCommand : ClientChatCommand
{
protected ICoreClientAPI ClientAPI;
protected ILogger Logger;
public LocalClientCommand(ICoreClientAPI _clientAPI)
{
ClientAPI = _clientAPI;
Logger = _clientAPI.World.Logger;
}
private LocalClientCommand( )
{
throw new NotSupportedException( );
}
}
}

View file

@ -0,0 +1,67 @@
using System;
using System.Text;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.MathTools;
using Vintagestory.GameContent.Mechanics;
namespace Machinations
{
public class MechNetAnalyser : LocalClientCommand
{
public MechNetAnalyser(ICoreClientAPI _clientAPI) : base(_clientAPI)
{
this.Command = @"mprobe";
this.Description = "Probes local information about Mechanical-Network block(s).";
this.handler += ProbeMechnet;
this.Syntax = " {facing} | blockPos";
}
internal void ProbeMechnet(int groupId, CmdArgs args)
{
var pos = ClientAPI.World.Player.CurrentBlockSelection.Position.Copy( );
if (args.Length > 1) {
pos = args.PopVec3i( ).AsBlockPos;
}
var someBlock = ClientAPI.World.BlockAccessor.GetBlock(pos);
if (someBlock != null && !someBlock.IsMissing && someBlock.MatterState == EnumMatterState.Solid)
{
if (someBlock is IMechanicalPowerBlock)
{
var mechNetInterface = someBlock as IMechanicalPowerBlock;
var mpNetwork = mechNetInterface.GetNetwork(ClientAPI.World, pos);
if (mpNetwork == null)
{
ClientAPI.ShowChatMessage("No valid network present.");
return;
}
var report = ReportOnMechnetwork(mpNetwork);
ClientAPI.ShowChatMessage(report.ToString( ));
}
else
{
ClientAPI.ShowChatMessage(string.Format("Block: '{0}' not Mechanical...", someBlock.GetPlacedBlockName(ClientAPI.World, pos)));
}
}
}
internal StringBuilder ReportOnMechnetwork(MechanicalNetwork mpNetwork)
{
var report = new StringBuilder(1000);
report.AppendLine($"Network #{mpNetwork.networkId} OK:{mpNetwork.Valid} Loaded:{mpNetwork.fullyLoaded} ");
report.AppendLine($"DIR:{mpNetwork.TurnDir} REV:{mpNetwork.DirectionHasReversed} SPD:{mpNetwork.Speed:F1} LSPD:{mpNetwork.clientSpeed:F1} %TRQ:{mpNetwork.TotalAvailableTorque:F1} NTRQ:{mpNetwork.NetworkTorque:F1} NRST:{mpNetwork.NetworkResistance:F1} ");
report.AppendLine($"TURNS:{mpNetwork.AngleRad:F2} Nodes: {mpNetwork.nodes.Count}");
return report;
}
}
}

View file

@ -0,0 +1,16 @@
using System;
using Vintagestory.API.Common;
namespace Machinations
{
public partial class MachinationsLoader : ModSystem
{
private void AttachClientCommands( )
{
ClientAPI.RegisterCommand(new MechNetAnalyser(ClientAPI));
}
}
}

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8FB150BD-DA28-4BCA-9EE0-05C463A5781C}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Machinations</RootNamespace>
<AssemblyName>Machinations</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CustomCommands>
<CustomCommands>
<Command type="AfterBuild" command="7z a -tzip -x!*.zip -aoa Machinations_${ProjectConfig}.zip" workingdir="${TargetDir}" />
<Command type="AfterClean" command="rm -f *.zip" workingdir="${TargetDir}" />
</CustomCommands>
</CustomCommands>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="0Harmony">
<HintPath>VS_libs\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>VS_libs\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="protobuf-net">
<HintPath>VS_libs\protobuf-net.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VintagestoryAPI">
<HintPath>VS_libs\VintagestoryAPI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VintagestoryLib">
<HintPath>VS_libs\VintagestoryLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VSCreativeMod">
<HintPath>VS_libs\VSCreativeMod.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VSEssentials">
<HintPath>VS_libs\VSEssentials.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VSSurvivalMod">
<HintPath>VS_libs\VSSurvivalMod.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MachinationsLoader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Abstracts\LocalClientCommand.cs" />
<Compile Include="ML_Collection.cs" />
<Compile Include="Commands\MechNetAnalyser.cs" />
</ItemGroup>
<ItemGroup>
<None Include="modinfo.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Abstracts\" />
<Folder Include="Commands\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -0,0 +1,51 @@
using System;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.Server;
using Vintagestory.Client.NoObf;
using Vintagestory.Server;
namespace Machinations
{
public partial class MachinationsLoader : ModSystem
{
private ICoreAPI CoreAPI;
private ICoreServerAPI ServerAPI;
private ICoreClientAPI ClientAPI;
private ServerCoreAPI ServerCore { get { return ServerAPI as ServerCoreAPI; } }
private ClientCoreAPI ClientCore { get { return ClientAPI as ClientCoreAPI; } }
public override bool AllowRuntimeReload {
get { return false; }
}
public override bool ShouldLoad(EnumAppSide forSide)
{
return true;
}
public override double ExecuteOrder( )
{
return 0.10d;
}
public override void Start(ICoreAPI api)
{
this.CoreAPI = api;
}
public override void StartServerSide(ICoreServerAPI api)
{
this.ServerAPI = api;
}
public override void StartClientSide(ICoreClientAPI api)
{
this.ClientAPI = api;
AttachClientCommands();
}
}
}

View file

@ -0,0 +1,31 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Machinations")]
[assembly: AssemblyDescription("Vintage Story Plugin")]
#if RELEASE
[assembly: AssemblyConfiguration("RELEASE")]
#else
[assembly: AssemblyConfiguration("DEBUG")]
#endif
[assembly: AssemblyProduct("First-Macgine-Age (component)")]
[assembly: AssemblyCopyright("Melchior")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

13
Machinations/modinfo.json Normal file
View file

@ -0,0 +1,13 @@
{
"type": "code",
"name": "Machinations",
"description" : "The Machine AGE starts here.",
"authors": ["Melchior"],
"ModID":"machinations",
"version": "0.1.0",
"dependencies": {
"game": "1.14.8",
"survival": ""
},
"website": "http://nowebsite.nope"
}