• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Carbon Copy plugin for VS


Commit MetaInfo

修訂86d1411ba92f0116f2dd57ab46892518934e7a2a (tree)
時間2020-04-17 06:48:12
作者melchior <melchior@user...>
Commitermelchior

Log Message

Version update; items export list V0.1.4

Change Summary

差異

--- a/CarbonCopy/CarbonCopy.csproj
+++ b/CarbonCopy/CarbonCopy.csproj
@@ -60,9 +60,11 @@
6060 <ItemGroup>
6161 <Compile Include="CarbonCopyMod.cs" />
6262 <Compile Include="Properties\AssemblyInfo.cs" />
63+ <Compile Include="ClientCommands\CarbonCopyCommand.cs" />
6364 </ItemGroup>
6465 <ItemGroup>
6566 <Folder Include="VS_Libs\" />
67+ <Folder Include="ClientCommands\" />
6668 </ItemGroup>
6769 <ItemGroup>
6870 <None Include="modinfo.json">
--- a/CarbonCopy/CarbonCopyMod.cs
+++ b/CarbonCopy/CarbonCopyMod.cs
@@ -1,7 +1,7 @@
11 using System;
2-
32 using System.Collections.Generic;
43 using System.IO;
4+
55 using Vintagestory.API.Client;
66 using Vintagestory.API.Common;
77 using Vintagestory.API.Common.Entities;
@@ -9,256 +9,35 @@ using Vintagestory.API.Config;
99 using Vintagestory.API.MathTools;
1010 using Vintagestory.API.Server;
1111
12-namespace VCMiscMods
12+namespace CarbonCopy
1313 {
1414 public class CarbonCopyMod : ModSystem
1515 {
16- private const int _highlightSlot = 42;
17- private const string _exportPath = @"Exports";
1816
1917 private ICoreAPI API { get; set; }
2018 private ICoreServerAPI ServerAPI { get; set; }
2119 private ICoreClientAPI ClientAPI { get; set; }
2220
23- private BlockPos start;
24- private BlockPos end;
25- private bool validSelection;
26- private List<BlockPos> markedBlocks;
27- private List<int> colorList;
2821
29- public CarbonCopyMod()
30- {
31- this.markedBlocks = new List<BlockPos>( );
32- this.colorList = new List<int> { ColorUtil.ToRgba(180, 0, 195, 0) };
33- }
3422
3523 public override bool ShouldLoad(EnumAppSide forSide)
3624 {
37- return forSide.IsClient();
25+ return forSide.IsClient( );
3826 }
3927
4028 public override void StartClientSide(ICoreClientAPI api)
41- {
42- this.API = api;
43- this.ClientAPI = api as ICoreClientAPI;
44-
45- if (api.Side == EnumAppSide.Client) {
46-
47- ClientAPI.RegisterCommand("export", "Export Carbon copies of selections locally.", "mark: start/end/ (x/y/z), save [name], clear", CarbonCopyCommand);
48- Mod.Logger.Notification("Registered Carbon Copy command (export)");
49-
50- }
51-
52- base.StartClientSide(api);
53- }
54-
55- /* .export
56- * mark
57- * mark start
58- * mark end
59- * mark start x+1
60- * mark end y-1
61- * mark start z+20
62- * mark clear
63- * save {NAME}
64- *
65- *
66- */
67-
68- private void CarbonCopyCommand(int groupId, CmdArgs args)
69- {
70- if (args.Length > 0) {
71- string command = args.PopWord( );
72-
73- switch (command) {
74-
75- case "mark":
76-
77- Process_MarkSubcommand(args);
78-
79- break;
80-
81- case "save":
82- if (validSelection) {
83- var filename = args.PopWord("export_" + Math.Round(DateTime.UtcNow.TimeOfDay.TotalSeconds));
84- Process_SaveCommand(filename);
85- }
86- break;
87-
88- case "clear":
89- Process_ClearCommand( );
90- break;
91-
92- case "dumpblocklist":
93- Dump_BlockList( );
94- break;
95-
96- default:
97- ClientAPI.ShowChatMessage("Wrong argument? mark/save/clear");
98- break;
99- }
100- } else {
101- ClientAPI.ShowChatMessage("Need arguments; must be: mark/save/clear");
102- }
103- }
104-
105- private void Process_MarkSubcommand(CmdArgs args )
106- {
107- if (args.Length > 0) {
108- string subCommand = args.PopWord( ).ToLowerInvariant( );
109-
110-
111- switch (subCommand) {
112- case "start":
113- if (this.start == null) {
114- this.start = ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Copy( );
115- }
116- BendBlockPosition(this.start, args);
117-
118- ClientAPI.ShowChatMessage(string.Format("Marked start; ({0}).", start));
119- break;
120-
121- case "end":
122- if (this.end == null) {
123- this.end = ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Copy( );
124- }
125- BendBlockPosition(this.end, args);
126-
127- ClientAPI.ShowChatMessage(string.Format("Marked end; ({0}).", end));
128- break;
129-
130- default:
131- ClientAPI.ShowChatMessage("Mark: start or end ?");
132- break;
133- }
134-
135- this.validSelection = false;
136-
137- if (this.start != null &&
138- this.end != null &&
139- ClientAPI.World.BulkBlockAccessor.IsValidPos(this.start) &&
140- ClientAPI.World.BulkBlockAccessor.IsValidPos(this.end)
141- ) {
142-
143- //Calc. Vol:
144- var size = start.DistanceTo(end);
145-
146- if (size > 1) {
147-
148- this.validSelection = true;
149-
150- this.markedBlocks.Clear( );
151-
152- ClientAPI.World.BulkBlockAccessor.WalkBlocks(start, end, addToMarked);
153-
154- ClientAPI.World.HighlightBlocks(ClientAPI.World.Player, _highlightSlot, this.markedBlocks, colorList, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary);
155-
156- ClientAPI.ShowChatMessage(string.Format("Marked area: {0:f1}diag = {1} blocks", size, markedBlocks.Count));
157- }
158- else {
159- ClientAPI.ShowChatMessage("Marked area: volume too small"); ;
160- }
161- }
162- }
163- else {
164- ClientAPI.ShowChatMessage("Mark: start / end (x,y,z +-1#)");
165- }
166-
167- }
168-
169- private void BendBlockPosition(BlockPos position, CmdArgs args)
170- {
171- char? axis = args.PopChar( );
172- int? offset = args.PopInt( );
173-
174- if (axis.HasValue && offset.HasValue) {
175- switch (Char.ToLowerInvariant(axis.Value)) {
176-
177- case 'x':
178- ClientAPI.ShowChatMessage(string.Format("applied X offset {0},", offset.Value));
179- position.Add(dx:offset.Value, dy:0, dz:0);
180- break;
181-
182- case 'y':
183- ClientAPI.ShowChatMessage(string.Format("applied Y offset {0},", offset.Value));
184- position.Add(dx:0, dy:offset.Value, dz:0);
185- break;
186-
187- case 'z':
188- ClientAPI.ShowChatMessage(string.Format("applied Z offset {0},", offset.Value));
189- position.Add(dx:0, dy:0, dz:offset.Value);
190- break;
191-
192- default:
193- //Nothing to do.
194- break;
195- }}
196- }
197-
198- private void addToMarked(Block aBlock, BlockPos aPos)
199- {
200- this.markedBlocks.Add(aPos.Copy());
201- }
202-
203- private void Process_SaveCommand(string filename)
204- {
205- if (validSelection) {
206-
207- BlockSchematic blockExport = new BlockSchematic( );
208-
209- blockExport.Init(ClientAPI.World.BlockAccessor);
210-
211- blockExport.AddArea(ClientAPI.World, this.start, this.end);
212-
213- if (blockExport.Pack(ClientAPI.World, this.start))//What should start Be?
214- {
215- ClientAPI.ShowChatMessage(string.Format("Export packed OK: {0} Blocks {1} Entities {2} BlockEntity", blockExport.BlockIds.Count, blockExport.Entities.Count, blockExport.BlockEntities.Count));
216-
217- filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), filename);
218-
219- blockExport.Save(filename);
220-
221- Process_ClearCommand( );
222- } else {
223- ClientAPI.ShowChatMessage("Error; can't pack for export...");
224- }
225- }
226- }
227-
228-
229- private void Process_ClearCommand( )
23029 {
231- this.start = null;
232- this.end = null;
233- this.validSelection = false;
234- this.markedBlocks.Clear( );
235- ClientAPI.World.HighlightBlocks(ClientAPI.World.Player, _highlightSlot, this.markedBlocks, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary);
30+ this.API = api;
31+ this.ClientAPI = api as ICoreClientAPI;
23632
237- ClientAPI.ShowChatMessage("Mark(s) Cleared.");
238- }
239-
240- private void Dump_BlockList( )
241- {
242- var filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), "vs_block_list_export_" + GameVersion.OverallVersion + ".tsv");
243-
244- using (StreamWriter reporter = new StreamWriter(filename)) {
245-
246- reporter.WriteLine("MC Block Name\tVS Block Name\tVS ID#\tMaterial\t");
247-
248- foreach (var block in ClientAPI.World.Blocks) {
249- if (block.Id != 0 && !block.IsMissing && block.Code.Domain == GlobalConstants.DefaultDomain) {
250- reporter.WriteLine($"<FILL>\t{block.Code.Path}\t{block.BlockId}\t{block.BlockMaterial}");
33+ if (api.Side == EnumAppSide.Client) {
25134
35+ ClientAPI.RegisterCommand(new CarbonCopyCommand(ClientAPI));
36+ Mod.Logger.Notification("Registered Carbon Copy command (export)");
25237 }
25338
39+ base.StartClientSide(api);
25440 }
255-
256- reporter.Flush( );
257- }
258-
259- ClientAPI.ShowChatMessage("Created Block List....");
260- }
261-
26241 }
26342 }
26443
--- /dev/null
+++ b/CarbonCopy/ClientCommands/CarbonCopyCommand.cs
@@ -0,0 +1,278 @@
1+using System;
2+using System.Collections.Generic;
3+using System.IO;
4+
5+using Vintagestory.API.Client;
6+using Vintagestory.API.Common;
7+using Vintagestory.API.Config;
8+using Vintagestory.API.MathTools;
9+
10+namespace CarbonCopy
11+{
12+ public class CarbonCopyCommand : ClientChatCommand
13+ {
14+ private const int _highlightSlot = 42;
15+ private const string _exportPath = @"Exports";
16+ private const string _name = @"export";
17+
18+ private ICoreClientAPI ClientAPI { get; set; }
19+ private ILogger Logger { get; set; }
20+
21+ private BlockPos start;
22+ private BlockPos end;
23+ private bool validSelection;
24+ private List<BlockPos> markedBlocks;
25+ private List<int> colorList;
26+
27+ public CarbonCopyCommand( )
28+ {
29+ this.markedBlocks = new List<BlockPos>( );
30+ this.colorList = new List<int> { ColorUtil.ToRgba(180, 0, 195, 0) };
31+ }
32+
33+ public CarbonCopyCommand(ICoreClientAPI clientAPI)
34+ {
35+ this.Command = _name;
36+ this.Syntax = @"mark: start/end/ (x/y/z), save [name], clear; dump {items/blocks}";
37+ this.Description = "Export crbon-copies of block selections locally.(as 'mex' file)";
38+
39+ ClientAPI = clientAPI;
40+ Logger = clientAPI.Logger;
41+ }
42+
43+
44+
45+ /* .export
46+ * mark
47+ * mark start
48+ * mark end
49+ * mark start x+1
50+ * mark end y-1
51+ * mark start z+20
52+ * mark clear
53+ * save {NAME}
54+ *
55+ *
56+ */
57+
58+ public override void CallHandler(IPlayer player, int groupId, CmdArgs args)
59+ {
60+ if (args.Length > 0) {
61+ string command = args.PopWord( );
62+
63+ switch (command) {
64+
65+ case "mark":
66+
67+ Process_MarkSubcommand(args);
68+
69+ break;
70+
71+ case "save":
72+ if (validSelection) {
73+ var filename = args.PopWord("export_" + Math.Round(DateTime.UtcNow.TimeOfDay.TotalSeconds));
74+ Process_SaveCommand(filename);
75+ }
76+ break;
77+
78+ case "clear":
79+ Process_ClearCommand( );
80+ break;
81+
82+ case "dump":
83+ string ofType = args.PopWord("blocks");
84+ if (ofType == "items") { Dump_ItemList( ); } else { Dump_BlockList( ); }
85+ break;
86+
87+ default:
88+ ClientAPI.ShowChatMessage("Unrecognised argument...");
89+ break;
90+ }
91+ }
92+ else {
93+ ClientAPI.ShowChatMessage("Needs a command: mark/save/clear/dump");
94+ }
95+ }
96+
97+ private void Process_MarkSubcommand(CmdArgs args)
98+ {
99+ if (args.Length > 0) {
100+ string subCommand = args.PopWord( ).ToLowerInvariant( );
101+
102+
103+ switch (subCommand) {
104+ case "start":
105+ if (this.start == null) {
106+ this.start = ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Copy( );
107+ }
108+ BendBlockPosition(this.start, args);
109+
110+ ClientAPI.ShowChatMessage(string.Format("Marked start; ({0}).", start));
111+ break;
112+
113+ case "end":
114+ if (this.end == null) {
115+ this.end = ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Copy( );
116+ }
117+ BendBlockPosition(this.end, args);
118+
119+ ClientAPI.ShowChatMessage(string.Format("Marked end; ({0}).", end));
120+ break;
121+
122+ default:
123+ ClientAPI.ShowChatMessage("Mark: start or end ?");
124+ break;
125+ }
126+
127+ this.validSelection = false;
128+
129+ if (this.start != null &&
130+ this.end != null &&
131+ ClientAPI.World.BulkBlockAccessor.IsValidPos(this.start) &&
132+ ClientAPI.World.BulkBlockAccessor.IsValidPos(this.end)
133+ ) {
134+
135+ //Calc. Vol:
136+ var size = start.DistanceTo(end);
137+
138+ if (size > 1) {
139+
140+ this.validSelection = true;
141+
142+ this.markedBlocks.Clear( );
143+
144+ ClientAPI.World.BulkBlockAccessor.WalkBlocks(start, end, addToMarked);
145+
146+ ClientAPI.World.HighlightBlocks(ClientAPI.World.Player, _highlightSlot, this.markedBlocks, colorList, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary);
147+
148+ ClientAPI.ShowChatMessage(string.Format("Marked area: {0:f1}diag = {1} blocks", size, markedBlocks.Count));
149+ }
150+ else {
151+ ClientAPI.ShowChatMessage("Marked area: volume too small"); ;
152+ }
153+ }
154+ }
155+ else {
156+ ClientAPI.ShowChatMessage("Mark: start / end (x,y,z +-1#)");
157+ }
158+
159+ }
160+
161+ private void BendBlockPosition(BlockPos position, CmdArgs args)
162+ {
163+ char? axis = args.PopChar( );
164+ int? offset = args.PopInt( );
165+
166+ if (axis.HasValue && offset.HasValue) {
167+ switch (Char.ToLowerInvariant(axis.Value)) {
168+
169+ case 'x':
170+ ClientAPI.ShowChatMessage(string.Format("applied X offset {0},", offset.Value));
171+ position.Add(dx: offset.Value, dy: 0, dz: 0);
172+ break;
173+
174+ case 'y':
175+ ClientAPI.ShowChatMessage(string.Format("applied Y offset {0},", offset.Value));
176+ position.Add(dx: 0, dy: offset.Value, dz: 0);
177+ break;
178+
179+ case 'z':
180+ ClientAPI.ShowChatMessage(string.Format("applied Z offset {0},", offset.Value));
181+ position.Add(dx: 0, dy: 0, dz: offset.Value);
182+ break;
183+
184+ default:
185+ //Nothing to do.
186+ break;
187+ }
188+ }
189+ }
190+
191+ private void addToMarked(Block aBlock, BlockPos aPos)
192+ {
193+ this.markedBlocks.Add(aPos.Copy( ));
194+ }
195+
196+ private void Process_SaveCommand(string filename)
197+ {
198+ if (validSelection) {
199+
200+ BlockSchematic blockExport = new BlockSchematic( );
201+
202+ blockExport.Init(ClientAPI.World.BlockAccessor);
203+
204+ blockExport.AddArea(ClientAPI.World, this.start, this.end);
205+
206+ if (blockExport.Pack(ClientAPI.World, this.start))//What should start Be?
207+ {
208+ ClientAPI.ShowChatMessage(string.Format("Export packed OK: {0} Blocks {1} Entities {2} BlockEntity", blockExport.BlockIds.Count, blockExport.Entities.Count, blockExport.BlockEntities.Count));
209+
210+ filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), filename);
211+
212+ blockExport.Save(filename);
213+
214+ Process_ClearCommand( );
215+ }
216+ else {
217+ ClientAPI.ShowChatMessage("Error; can't pack for export...");
218+ }
219+ }
220+ }
221+
222+
223+ private void Process_ClearCommand( )
224+ {
225+ this.start = null;
226+ this.end = null;
227+ this.validSelection = false;
228+ this.markedBlocks.Clear( );
229+ ClientAPI.World.HighlightBlocks(ClientAPI.World.Player, _highlightSlot, this.markedBlocks, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary);
230+
231+ ClientAPI.ShowChatMessage("Mark(s) Cleared.");
232+ }
233+
234+ private void Dump_BlockList( )
235+ {
236+ var filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), "vs_block_list_export_" + GameVersion.OverallVersion + ".tsv");
237+
238+ using (StreamWriter reporter = new StreamWriter(filename, false)) {
239+
240+ reporter.WriteLine("MC Block Name\tVS Block Name\tVS ID#\tMaterial\t");
241+ Logger.VerboseDebug("Dumping {0} Blocks", ClientAPI.World.Blocks.Count);
242+ foreach (var block in ClientAPI.World.Blocks.FindAll(blk => blk.Code != null && blk.Code.Domain == GlobalConstants.DefaultDomain)) {
243+ if (block.Id != 0 && !block.IsMissing ) {
244+ reporter.WriteLine($"____\t{block.Code.Path}\t{block.BlockId}\t{block.BlockMaterial}");
245+
246+ }
247+
248+ }
249+
250+ reporter.Flush( );
251+ }
252+
253+ ClientAPI.ShowChatMessage("Created Block List....");
254+ }
255+
256+ private void Dump_ItemList( )
257+ {
258+ var filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), "vs_item_list_export_" + GameVersion.OverallVersion + ".tsv");
259+
260+ using (StreamWriter reporter = new StreamWriter(filename, false)) {
261+
262+ reporter.WriteLine("MC Item Name\tVS Item Name\tVS ID#\tStorage Flags\tMax Stack Size\tC.I. Tabs\t");
263+ Logger.VerboseDebug("Dumping {0} Items", ClientAPI.World.Items.Count);
264+ foreach (var item in ClientAPI.World.Items.FindAll(itm => itm.Code != null && itm.Code.Domain == GlobalConstants.DefaultDomain)) {
265+ if (item.Id != 0 && !item.IsMissing) {
266+ reporter.WriteLine($"____\t{item.Code.Path}\t{item.ItemId}\t{String.Join(",", item.StorageFlags)}\t{item.MaxStackSize}\t{(item.CreativeInventoryTabs != null ? String.Join(",",item.CreativeInventoryTabs): " ")}");
267+ }
268+
269+ }
270+
271+ reporter.Flush( );
272+ }
273+
274+ ClientAPI.ShowChatMessage("Created Items List....");
275+ }
276+ }
277+}
278+
--- a/CarbonCopy/modinfo.json
+++ b/CarbonCopy/modinfo.json
@@ -3,7 +3,7 @@
33 "name": "Carbon-Copy",
44 "description" : "Export schematics from MP (clientside!)",
55 "authors": ["Melchior"],
6- "version": "0.1.3",
6+ "version": "0.1.4",
77 "side": "client",
88 "dependencies": {
99 "game": "1.11.0"