├── thumb.png
├── .gitattributes
├── App.config
├── metadata.mod
├── README.md
├── SeShipwrightTools.sln
├── ShipwrightTools.csproj
├── .gitignore
└── Data
└── Scripts
└── SeShipwrightTools
└── SeShipwrightTools.cs
/thumb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chozabu/SeShipwrightTools/main/thumb.png
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/metadata.mod:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1.0
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SeShipwrightTools
2 | Tools to aid ship building in SE - currently has ConveyorReplacor and TransparentArmour
3 |
4 | Check it out on the steam workshop here: https://steamcommunity.com/sharedfiles/filedetails/?id=2938853980
5 |
6 | ## ConveyorReplacer - Backup your ship before using this tool. It may delete your conveyors, eat your homework or cause demons to fly out your nose
7 |
8 | type `/conv` in chat while looking at a grid to convert all conveyor blocks to tube/corner/Tjunctions, fitting the surrounding blocks with coneyors/ports
9 |
10 | use `/convp` for industrial pipe
11 |
12 | or `/convr` for the ducted steel tubes
13 |
14 | https://user-images.githubusercontent.com/937160/221367260-701e890e-3f9e-4dd1-8771-1765211d964c.mp4
15 |
16 |
17 | ## Transparent Armour
18 |
19 | use `/hidearmor` in chat while looking at a grid to make its armour 80% transparent
20 |
21 | use `/showarmor` in chat while looking at a grid to make its armor return to opaque
22 |
23 |
24 | https://user-images.githubusercontent.com/937160/221373627-59d9d728-83e5-4d55-8cbe-3800df67f702.mp4
25 |
26 |
--------------------------------------------------------------------------------
/SeShipwrightTools.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.33328.57
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShipwrightTools", "ShipwrightTools.csproj", "{157CD328-055C-4CB3-9802-0B6606F5E10C}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Release|Any CPU = Release|Any CPU
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {157CD328-055C-4CB3-9802-0B6606F5E10C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {157CD328-055C-4CB3-9802-0B6606F5E10C}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {157CD328-055C-4CB3-9802-0B6606F5E10C}.Debug|x64.ActiveCfg = Debug|x64
19 | {157CD328-055C-4CB3-9802-0B6606F5E10C}.Debug|x64.Build.0 = Debug|x64
20 | {157CD328-055C-4CB3-9802-0B6606F5E10C}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {157CD328-055C-4CB3-9802-0B6606F5E10C}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {157CD328-055C-4CB3-9802-0B6606F5E10C}.Release|x64.ActiveCfg = Release|x64
23 | {157CD328-055C-4CB3-9802-0B6606F5E10C}.Release|x64.Build.0 = Release|x64
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {D07946DF-0256-42C5-A8CB-D8C0A552EA26}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/ShipwrightTools.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {157CD328-055C-4CB3-9802-0B6606F5E10C}
8 | Exe
9 | Project1
10 | Project1
11 | v4.7.2
12 | 512
13 | true
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 | true
37 | bin\x64\Debug\
38 | DEBUG;TRACE
39 | full
40 | x64
41 | 7.3
42 | prompt
43 | true
44 |
45 |
46 | bin\x64\Release\
47 | TRACE
48 | true
49 | pdbonly
50 | x64
51 | 7.3
52 | prompt
53 | true
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\ProtoBuf.Net.dll
62 | False
63 |
64 |
65 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Common.dll
66 | False
67 |
68 |
69 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Game.dll
70 | False
71 |
72 |
73 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Graphics.dll
74 | False
75 |
76 |
77 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.Game.dll
78 | False
79 |
80 |
81 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.ObjectBuilders.dll
82 | False
83 |
84 |
85 | False
86 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\System.Collections.Immutable.dll
87 | False
88 |
89 |
90 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.dll
91 | False
92 |
93 |
94 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Game.dll
95 | False
96 |
97 |
98 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Input.dll
99 | False
100 |
101 |
102 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Library.dll
103 | False
104 |
105 |
106 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Math.dll
107 | False
108 |
109 |
110 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Render.dll
111 | False
112 |
113 |
114 | D:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Render11.dll
115 | False
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.tlog
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.)
298 | *.vbp
299 |
300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project)
301 | *.dsw
302 | *.dsp
303 |
304 | # Visual Studio 6 technical files
305 | *.ncb
306 | *.aps
307 |
308 | # Visual Studio LightSwitch build output
309 | **/*.HTMLClient/GeneratedArtifacts
310 | **/*.DesktopClient/GeneratedArtifacts
311 | **/*.DesktopClient/ModelManifest.xml
312 | **/*.Server/GeneratedArtifacts
313 | **/*.Server/ModelManifest.xml
314 | _Pvt_Extensions
315 |
316 | # Paket dependency manager
317 | .paket/paket.exe
318 | paket-files/
319 |
320 | # FAKE - F# Make
321 | .fake/
322 |
323 | # CodeRush personal settings
324 | .cr/personal
325 |
326 | # Python Tools for Visual Studio (PTVS)
327 | __pycache__/
328 | *.pyc
329 |
330 | # Cake - Uncomment if you are using it
331 | # tools/**
332 | # !tools/packages.config
333 |
334 | # Tabs Studio
335 | *.tss
336 |
337 | # Telerik's JustMock configuration file
338 | *.jmconfig
339 |
340 | # BizTalk build output
341 | *.btp.cs
342 | *.btm.cs
343 | *.odx.cs
344 | *.xsd.cs
345 |
346 | # OpenCover UI analysis results
347 | OpenCover/
348 |
349 | # Azure Stream Analytics local run output
350 | ASALocalRun/
351 |
352 | # MSBuild Binary and Structured Log
353 | *.binlog
354 |
355 | # NVidia Nsight GPU debugger configuration file
356 | *.nvuser
357 |
358 | # MFractors (Xamarin productivity tool) working folder
359 | .mfractor/
360 |
361 | # Local History for Visual Studio
362 | .localhistory/
363 |
364 | # Visual Studio History (VSHistory) files
365 | .vshistory/
366 |
367 | # BeatPulse healthcheck temp database
368 | healthchecksdb
369 |
370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
371 | MigrationBackup/
372 |
373 | # Ionide (cross platform F# VS Code tools) working folder
374 | .ionide/
375 |
376 | # Fody - auto-generated XML schema
377 | FodyWeavers.xsd
378 |
379 | # VS Code files for those working on multiple tools
380 | .vscode/*
381 | !.vscode/settings.json
382 | !.vscode/tasks.json
383 | !.vscode/launch.json
384 | !.vscode/extensions.json
385 | *.code-workspace
386 |
387 | # Local History for Visual Studio Code
388 | .history/
389 |
390 | # Windows Installer files from build outputs
391 | *.cab
392 | *.msi
393 | *.msix
394 | *.msm
395 | *.msp
396 |
397 | # JetBrains Rider
398 | *.sln.iml
399 |
--------------------------------------------------------------------------------
/Data/Scripts/SeShipwrightTools/SeShipwrightTools.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Sandbox.Definitions;
4 | using Sandbox.Game;
5 | using Sandbox.Game.Entities;
6 | using Sandbox.ModAPI;
7 | using Sandbox.ModAPI.Weapons;
8 | using Sandbox.ModAPI.Interfaces;
9 | using VRage.Game;
10 | using VRage.Game.Components;
11 | using VRage.Game.ModAPI;
12 | using VRage.ObjectBuilders;
13 | using VRage.Utils;
14 | using VRageMath;
15 | using Sandbox.Common.ObjectBuilders;
16 | //using BlendTypeEnum = VRageRender.MyBillboard.BlendTypeEnum;
17 |
18 | namespace Chozabu.ConveyorReplacer
19 | {
20 | [MySessionComponentDescriptor(MyUpdateOrder.AfterSimulation)]
21 | public class ArmorReplacer : MySessionComponentBase
22 | {
23 | float armorTransparancy = 0.0f;
24 |
25 | struct replaceinfo
26 | {
27 | public IMySlimBlock block;
28 | public MyObjectBuilder_CubeBlock objectBuilder;
29 |
30 | }
31 | public override void HandleInput()
32 | {
33 | if (MyAPIGateway.Input.IsNewKeyPressed(VRage.Input.MyKeys.O))
34 | {
35 | if (MyAPIGateway.Input.IsAnyCtrlKeyPressed())
36 | {
37 | CycleArmorTransparancy();
38 | }
39 | }
40 | }
41 |
42 | private void CycleArmorTransparancy()
43 | {
44 | if (armorTransparancy == 0.0f)
45 | {
46 | armorTransparancy = .5f;
47 |
48 | } else if (armorTransparancy == 0.5f)
49 | {
50 | armorTransparancy = .8f;
51 |
52 | } else if (armorTransparancy == 0.8f)
53 | {
54 | armorTransparancy = .0f;
55 |
56 | }
57 | SetArmorTransparancy(armorTransparancy);
58 | }
59 |
60 | public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
61 | {
62 | MyAPIGateway.Utilities.MessageEntered += Utilities_MessageEntered;
63 | }
64 |
65 | private void Utilities_MessageEntered(string messageText, ref bool sendToOthers)
66 | {
67 | if (messageText == "/conv" && MyAPIGateway.Session.IsServer)
68 | {
69 | MyAPIGateway.Utilities.ShowMessage("", "conv converting to tube");
70 | ReplaceAllConveyorBlocks();
71 | sendToOthers = false;
72 | MyAPIGateway.Utilities.ShowMessage("", "conv converted");
73 | }
74 | if (messageText == "/convp" && MyAPIGateway.Session.IsServer)
75 | {
76 | MyAPIGateway.Utilities.ShowMessage("", "conv converting to pipe");
77 | ReplaceAllConveyorBlocks("p");
78 | sendToOthers = false;
79 | MyAPIGateway.Utilities.ShowMessage("", "conv converted");
80 | }
81 | if (messageText == "/convr" && MyAPIGateway.Session.IsServer)
82 | {
83 | MyAPIGateway.Utilities.ShowMessage("", "conv converting to ducts");
84 | ReplaceAllConveyorBlocks("r");
85 | sendToOthers = false;
86 | MyAPIGateway.Utilities.ShowMessage("", "conv converted");
87 | }
88 | if (messageText == "/convj" && MyAPIGateway.Session.IsServer)
89 | {
90 | MyAPIGateway.Utilities.ShowMessage("", "conv converting to junc");
91 | ReplaceAllConveyorBlocks("j");
92 | sendToOthers = false;
93 | MyAPIGateway.Utilities.ShowMessage("", "conv converted");
94 | }
95 |
96 | if (messageText == "/names" && MyAPIGateway.Session.IsServer)
97 | {
98 | MyAPIGateway.Utilities.ShowMessage("", "blocknames");
99 | PrintBlockNames();
100 | sendToOthers = false;
101 | }
102 | if (messageText == "/showarmor" && MyAPIGateway.Session.IsServer)
103 | {
104 | MyAPIGateway.Utilities.ShowMessage("", "ShowingArmor");
105 | SetArmorTransparancy(.0f);
106 | sendToOthers = false;
107 | }
108 | if (messageText == "/hidearmor" && MyAPIGateway.Session.IsServer)
109 | {
110 | MyAPIGateway.Utilities.ShowMessage("", "HidingArmor");
111 | SetArmorTransparancy(.8f);
112 | sendToOthers = false;
113 | }
114 | if (messageText == "/hidearmor50" && MyAPIGateway.Session.IsServer)
115 | {
116 | MyAPIGateway.Utilities.ShowMessage("", "HidingArmor");
117 | SetArmorTransparancy(.5f);
118 | sendToOthers = false;
119 | }
120 |
121 | }
122 | public IMyCubeGrid GetTargetedGrid()
123 | {
124 | var MaxRaycastDistance = 10000;
125 | var player = MyAPIGateway.Session?.LocalHumanPlayer;
126 | if (player == null) return null;
127 |
128 | var cameraMatrix = MyAPIGateway.Session.Camera.WorldMatrix;
129 | var forwardVector = Vector3D.Normalize(cameraMatrix.Forward);
130 | var toVector = cameraMatrix.Translation + forwardVector * MaxRaycastDistance;
131 |
132 | IHitInfo hitInfo;
133 | if (!MyAPIGateway.Physics.CastRay(cameraMatrix.Translation, toVector, out hitInfo))
134 | return null;
135 |
136 | var entity = hitInfo?.HitEntity;
137 | if (entity?.Physics == null) return null;
138 |
139 | var grid = entity.GetTopMostParent() as IMyCubeGrid;
140 | return grid;
141 | }
142 |
143 | public void SetArmorTransparancy(float transparancy)
144 | {
145 | IMyCubeGrid grid = GetTargetedGrid();
146 | if (grid == null) return;
147 |
148 | List allBlocks = new List();
149 |
150 | grid.GetBlocks(allBlocks);
151 |
152 | // Replace each conveyor block with the correct type
153 | foreach (IMySlimBlock block in allBlocks)
154 | {
155 |
156 | if (block.GetObjectBuilder().SubtypeName.Contains("Armor"))// && block.FatBlock != null)
157 | {
158 | //MyAPIGateway.Utilities.ShowMessage("", block.GetObjectBuilder().SubtypeName);
159 | block.Dithering = transparancy;
160 | }
161 | }
162 |
163 | }
164 |
165 | public void PrintBlockNames()
166 | {
167 | IMyCubeGrid grid = GetTargetedGrid();
168 | if (grid == null) return;
169 |
170 | List allBlocks = new List();
171 |
172 | grid.GetBlocks(allBlocks);
173 |
174 | // Replace each conveyor block with the correct type
175 | foreach (IMySlimBlock block in allBlocks)
176 | {
177 |
178 | MyAPIGateway.Utilities.ShowMessage("", block.GetObjectBuilder().SubtypeName);
179 | }
180 |
181 | }
182 | public void ReplaceAllConveyorBlocks(string tubetype = "t")
183 | {
184 | IMyCubeGrid grid = GetTargetedGrid();
185 | if (grid == null) return;
186 |
187 | if (grid.GridSizeEnum == MyCubeSize.Small)//TODO Rotations need correcting too
188 | {
189 | MyAPIGateway.Utilities.ShowMessage("", "Skipping small grid");
190 | return;
191 |
192 | }
193 |
194 | // Find all conveyor blocks on the grid
195 | List conveyorBlocks = new List();
196 | List replaceList = new List();
197 |
198 | //grid.GetBlocks(conveyorBlocks, block => block.FatBlock != null && block.FatBlock.BlockDefinition.TypeId.ToString() == "MyObjectBuilder_Conveyor");
199 | grid.GetBlocks(conveyorBlocks, block => block.FatBlock != null && block.FatBlock.BlockDefinition.TypeId.ToString().Contains("Conveyor"));
200 |
201 |
202 | // Replace each conveyor block with the correct type
203 | foreach (IMySlimBlock conveyorBlock in conveyorBlocks)
204 | {
205 | if (conveyorBlock.FatBlock.BlockDefinition.TypeId.ToString().ToLower().Contains("sort"))
206 | {
207 | continue;
208 | }
209 | replaceinfo blockinfo;
210 | blockinfo.block = conveyorBlock;
211 | blockinfo.objectBuilder = GetBuilderToReplaceConveyor(conveyorBlock, tubetype);
212 | // Replace the conveyor block
213 | replaceList.Add(blockinfo);
214 | }
215 |
216 | foreach (replaceinfo ri in replaceList)
217 | {
218 | grid.RemoveBlock(ri.block);
219 | grid.AddBlock(ri.objectBuilder, true);
220 | }
221 | }
222 |
223 | public bool HasMatchingAxis(IMySlimBlock block1, IMySlimBlock block2)
224 | {
225 | Vector3I pos1 = block1.Position;
226 | Vector3I pos2 = block2.Position;
227 |
228 | if (pos1.X == pos2.X && pos1.Y == pos2.Y) return true;
229 | if (pos1.Z == pos2.Z && pos1.Y == pos2.Y) return true;
230 | if (pos1.X == pos2.X && pos1.Z == pos2.Z) return true;
231 | return false;
232 |
233 | }
234 |
235 | public Vector3 getPerpAxis(IMySlimBlock block1, IMySlimBlock block2)
236 | {
237 | Vector3I pos1 = block1.Position;
238 | Vector3I pos2 = block2.Position;
239 |
240 | if (pos1.X == pos2.X && pos1.Y == pos2.Y) return new Vector3(1, 0, 0);
241 | if (pos1.Z == pos2.Z && pos1.Y == pos2.Y) return new Vector3(0, 1, 0);
242 | if (pos1.X == pos2.X && pos1.Z == pos2.Z) return new Vector3(0, 0, 1);
243 | return new Vector3(1, 0, 0);
244 |
245 | }
246 | //based on digis code at: https://github.com/THDigi/BuildInfo/blob/ac69e815a9c82e3d0e27013f86109af556a1f503/Data/Scripts/BuildInfo/Features/LiveData/LiveDataHandler.cs#L178
247 | bool CheckConveyorSupport(IMyCubeBlock block, IMySlimBlock testblock)
248 | {
249 | if (block == null) return false;
250 |
251 | Type[] interfaces = MyAPIGateway.Reflection.GetInterfaces(block.GetType());
252 | bool supportsConveyors = false;
253 |
254 | for (int i = (interfaces.Length - 1); i >= 0; i--)
255 | {
256 | Type iface = interfaces[i];
257 | if (iface.Name == "IMyConveyorEndpointBlock")
258 | {
259 | supportsConveyors = true;
260 | break;
261 | }
262 | else if (iface.Name == "IMyConveyorSegmentBlock")
263 | {
264 | supportsConveyors = true;
265 | break;
266 | }
267 | }
268 |
269 | return supportsConveyors;
270 | }
271 | //todo check if port is in right direction: https://github.com/THDigi/BuildInfo/blob/master/Data/Scripts/BuildInfo/Features/LiveData/Base.cs#L238
272 |
273 |
274 | bool CheckConveyorPortNearTestblock(IMyCubeBlock block, IMySlimBlock testblock)
275 | {
276 | Dictionary dummies = new Dictionary();
277 | block.Model.GetDummies(dummies);
278 |
279 | foreach (IMyModelDummy dummy in dummies.Values)
280 | {
281 |
282 | //Vector3 portpos = dummy.Matrix.Translation + block.Position;
283 | //Vector3 testpos = testblock.Position;
284 |
285 | //Vector3 portpos = Vector3.Transform(dummy.Matrix.Translation, block.WorldMatrix);
286 | //Vector3 testpos = Vector3.Transform(testblock.Position, testblock.CubeGrid.WorldMatrix);
287 |
288 | Vector3 portpos = Vector3.Transform(dummy.Matrix.Translation, block.LocalMatrix);
289 | Vector3 testpos = testblock.Position;
290 |
291 | //need to do both blocks, using one of these
292 | //new MyOrientedBoundingBox(dummy.Matrix * block.LocalMatrix)
293 | //new BoundingBox()
294 |
295 | if ((portpos - testpos).Length() < 3.0f)
296 | return true;
297 | }
298 | return false;
299 | }
300 |
301 | public List GetConveyorNeighbors(IMySlimBlock block)
302 | {
303 | List conveyorBlocks = new List();
304 | List neighbors = new List();
305 | block.GetNeighbours(neighbors);
306 | //block.CubeGrid.GetBlocks(neighbors, b => b != null && b != block && b.FatBlock != null);
307 |
308 | foreach (IMySlimBlock neighbor in neighbors)
309 | {
310 | if (neighbor.GetObjectBuilder().SubtypeName.Contains("Conveyor"))
311 | //if (neighbor.FatBlock is IMyConveyor)
312 | {
313 | conveyorBlocks.Add(neighbor);
314 | } else
315 | {
316 | if (CheckConveyorSupport(neighbor.FatBlock, block))
317 | {
318 |
319 | List uglyhack = new List();
320 | uglyhack.Add(neighbor);
321 | uglyhack.Add(neighbor);
322 | uglyhack.Add(neighbor);
323 | uglyhack.Add(neighbor);
324 | uglyhack.Add(neighbor);
325 | uglyhack.Add(neighbor);
326 | return uglyhack;//TODO remove this, use dummys...
327 |
328 | }
329 | //neighbor.FatBlock.CheckConnectionAllowed
330 | if (CheckConveyorPortNearTestblock(neighbor.FatBlock, block)) {
331 | //if (conveyorBlock != null)
332 | //{
333 | conveyorBlocks.Add(neighbor);
334 | }
335 | }
336 | }
337 |
338 | return conveyorBlocks;
339 | }
340 |
341 | public MyObjectBuilder_CubeBlock GetBuilderToReplaceConveyor(IMySlimBlock block, string tubetype)
342 | {
343 |
344 | string junctionS = "LargeBlockConveyor";
345 | string straightS = "ConveyorTube";
346 | string cornerS = "ConveyorTubeCurved";
347 | string tS = "ConveyorTubeT";
348 | if (tubetype.Equals("p"))
349 | {
350 | junctionS = "LargeBlockConveyorPipeJunction";
351 | straightS = "LargeBlockConveyorPipeSeamless";
352 | cornerS = "LargeBlockConveyorPipeCorner";
353 | tS = "LargeBlockConveyorPipeT";
354 | }
355 | else if (tubetype.Equals("r"))
356 | {
357 | junctionS = "LargeBlockConveyor";
358 | straightS = "ConveyorTubeDuct";
359 | cornerS = "ConveyorTubeDuctCurved";
360 | tS = "ConveyorTubeDuctT";
361 |
362 | }
363 | else if (tubetype.Equals("j"))
364 | {
365 | junctionS = "LargeBlockConveyor";
366 | straightS = "LargeBlockConveyor";
367 | cornerS = "LargeBlockConveyor";
368 | tS = "LargeBlockConveyor";
369 |
370 | }
371 |
372 | if (block.CubeGrid.GridSizeEnum == MyCubeSize.Small)//TODO Rotations need correcting too
373 | {
374 | junctionS = "SmallBlockConveyor";
375 | straightS = "ConveyorTubeSmall";
376 | cornerS = "ConveyorTubeSmallCurved";
377 | tS = "ConveyorTubeSmallT";
378 | if (tubetype.Equals("r"))
379 | {
380 | junctionS = "SmallBlockConveyor";
381 | straightS = "ConveyorTubeDuctSmall";
382 | cornerS = "ConveyorTubeDuctSmallCurved";
383 | tS = "ConveyorTubeDuctSmallT";
384 | }
385 | }
386 |
387 | var surroundings = GetConveyorNeighbors(block);
388 | var snum = surroundings.Count;
389 | var ConveyorType = "LargeBlockConveyor";
390 |
391 | var orientation = block.Orientation;
392 |
393 | var forward = Base6Directions.GetVector(orientation.Forward);
394 | var up = Base6Directions.GetVector(orientation.Up);
395 | var right = Vector3.Cross(forward, up); //for local calc only
396 | MyAPIGateway.Utilities.ShowMessage("", "block nei num " + snum);
397 | if (snum == 1 || snum == 0)
398 | {// dead end or isolated conveyor
399 | //leave as-is, should perhaps set to junction?
400 | }
401 | else if (snum == 2)
402 | { //straight or corner
403 | if (HasMatchingAxis(surroundings[0], surroundings[1]))
404 | {
405 | ConveyorType = straightS;
406 |
407 | //up = surroundings[0].Position - block.Position;
408 | //right = up + new Vector3(1, 1, 1); //lame method
409 | //forward = Vector3.Cross(up, right);
410 |
411 | var a = surroundings[0].Position - block.Position;
412 | var b = getPerpAxis(surroundings[0], surroundings[1]);
413 | var c = Vector3.Cross(a, b);
414 |
415 |
416 | if (tubetype.Equals("r"))/// why are ducts rotated differently :(
417 | {
418 | forward = c;
419 | up = b;
420 | }
421 | else
422 | {
423 | forward = b;
424 | up = a;
425 | }
426 | }
427 | else
428 | {
429 | ConveyorType = cornerS;
430 | up = block.Position - surroundings[0].Position;
431 | right = surroundings[1].Position - block.Position;
432 | forward = Vector3.Cross(up, right);
433 |
434 | }
435 | }
436 | else if (snum == 3)
437 | { //T junction if two on same line
438 | var line01 = HasMatchingAxis(surroundings[0], surroundings[1]);
439 | var line02 = HasMatchingAxis(surroundings[0], surroundings[2]);
440 | var line12 = HasMatchingAxis(surroundings[1], surroundings[2]);
441 | if (line01 || line02 || line12)
442 | {
443 | var a = surroundings[0];
444 | var b = surroundings[1];
445 | var c = surroundings[2];
446 | ConveyorType = tS;
447 | if (line01)
448 | {
449 | }
450 | if (line02)
451 | {
452 | a = surroundings[0];
453 | b = surroundings[2];
454 | c = surroundings[1];
455 | }
456 | if (line12)
457 | {
458 | a = surroundings[1];
459 | b = surroundings[2];
460 | c = surroundings[0];
461 | }
462 |
463 | right = b.Position - a.Position;
464 | up = block.Position - c.Position;
465 | forward = Vector3.Cross(right, up) * -1;
466 | }
467 | else
468 | {
469 | //cant do T, should do junction
470 | ConveyorType = junctionS;
471 |
472 | }
473 | }
474 | else
475 | {
476 | //4 or more, set to junction
477 | ConveyorType = junctionS;
478 | }
479 |
480 | return GetBuilderWithSpecs(block.CubeGrid, block, ConveyorType, up, forward);
481 |
482 | }
483 | public MyObjectBuilder_CubeBlock GetBuilderWithSpecs(IMyCubeGrid grid, IMySlimBlock blockToReplace, string conveyorType, Vector3D upVector, Vector3D forwardVector)
484 | {
485 | Vector3I position = blockToReplace.Position;
486 |
487 | var forwardDir = Base6Directions.GetClosestDirection(forwardVector);
488 | var upDir = Base6Directions.GetClosestDirection(upVector);
489 |
490 | var orientation = new MyBlockOrientation(forwardDir, upDir);
491 |
492 | //MyObjectBuilder_CubeBlock objectBuilder = MyObjectBuilderSerializer.CreateNewObject(conveyorType);
493 | MyObjectBuilder_CubeBlock objectBuilder = blockToReplace.GetObjectBuilder();
494 | MyAPIGateway.Utilities.ShowMessage("", "replacing... " + objectBuilder.SubtypeName + " with " + conveyorType);
495 | //MyObjectBuilder_CubeBlock objectBuilder = blockToReplace.GetObjectBuilder(true);
496 |
497 | objectBuilder.SubtypeName = conveyorType;
498 | objectBuilder.EntityId = 0;
499 | //objectBuilder.Min = position;
500 | objectBuilder.BlockOrientation = orientation;
501 |
502 | return objectBuilder;
503 | }
504 |
505 | protected override void UnloadData()
506 | {
507 | MyAPIGateway.Utilities.MessageEntered -= Utilities_MessageEntered;
508 | }
509 | }
510 | }
--------------------------------------------------------------------------------