Carbon Copy plugin for VS
修訂 | a5cd9edb6a7d9b0acd4bb4ba4a4f13047cbefb8e (tree) |
---|---|
時間 | 2020-12-25 09:54:27 |
作者 | melchior <melchior@user...> |
Commiter | melchior |
Improved Block/Item export command(s) - domain aware
@@ -8,6 +8,7 @@ using Vintagestory.API.Common; | ||
8 | 8 | using Vintagestory.API.Config; |
9 | 9 | using Vintagestory.API.MathTools; |
10 | 10 | |
11 | + | |
11 | 12 | namespace CarbonCopy |
12 | 13 | { |
13 | 14 | public class CarbonCopyCommand : ClientChatCommand |
@@ -25,12 +26,21 @@ namespace CarbonCopy | ||
25 | 26 | private List<BlockPos> markedBlocks = new List<BlockPos>( ); |
26 | 27 | private List<int> colorList = new List<int> { ColorUtil.ToRgba(180, 0, 195, 0) }; |
27 | 28 | |
29 | + internal ModInfo InternalVersion | |
30 | + { | |
31 | + get | |
32 | + { | |
33 | + var gameMod = ClientAPI.ModLoader.GetMod(@"survival");//TODO: Figure out which; Creative / Survival ? | |
34 | + return gameMod.Info; | |
35 | + } | |
36 | + } | |
37 | + | |
28 | 38 | |
29 | 39 | public CarbonCopyCommand(ICoreClientAPI clientAPI) |
30 | 40 | { |
31 | 41 | this.Command = _name; |
32 | - this.Syntax = @"mark: start/end/ (x/y/z), save [name], clear; dump {items/blocks}"; | |
33 | - this.Description = "Export carbon-copies of block selections locally.(as json export schematic)"; | |
42 | + this.Syntax = @"mark: start/end/ (x/y/z), save [name], clear; dump [items/blocks] [domain?]"; | |
43 | + this.Description = @"Export carbon-copies of block selections locally.(as json export schematic) - also Block info..."; | |
34 | 44 | |
35 | 45 | ClientAPI = clientAPI; |
36 | 46 | Logger = clientAPI.Logger; |
@@ -75,7 +85,13 @@ namespace CarbonCopy | ||
75 | 85 | |
76 | 86 | case "dump": |
77 | 87 | string ofType = args.PopWord("blocks"); |
78 | - if (ofType == "items") { Dump_ItemList( ); } else { Dump_BlockList( ); } | |
88 | + string domainFilter = null; | |
89 | + if (args.Length == 1) | |
90 | + { | |
91 | + domainFilter = args.PopWord( ); | |
92 | + } | |
93 | + | |
94 | + if (ofType == "items") { Dump_ItemList(domainFilter); } else { Dump_BlockList(domainFilter); } | |
79 | 95 | break; |
80 | 96 | |
81 | 97 | default: |
@@ -225,18 +241,29 @@ namespace CarbonCopy | ||
225 | 241 | ClientAPI.ShowChatMessage("Mark(s) Cleared."); |
226 | 242 | } |
227 | 243 | |
228 | - private void Dump_BlockList( ) | |
244 | + private void Dump_BlockList(string domainFilter ) | |
229 | 245 | { |
230 | - var filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), "vs_block_list_export_" + GameVersion.OverallVersion + ".tsv"); | |
246 | + var filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), "vs_block_list_export_" + InternalVersion.Version + ".tsv"); | |
247 | + | |
248 | + IEnumerable<Block> bQuery; | |
249 | + if (string.IsNullOrWhiteSpace(domainFilter)) { | |
250 | + bQuery = ClientAPI.World.Blocks.Where(blk => blk.Code != null); | |
251 | + } | |
252 | + else { | |
253 | + bQuery = ClientAPI.World.Blocks.Where(blk => blk.Code != null && blk.Code.Domain.Equals(domainFilter, StringComparison.OrdinalIgnoreCase)); | |
254 | + filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), "vs_block_list_export_" + InternalVersion.Version+ "_["+domainFilter +"]" + ".tsv"); | |
255 | + } | |
231 | 256 | |
232 | 257 | using (StreamWriter reporter = new StreamWriter(filename, false)) { |
233 | 258 | |
234 | - reporter.WriteLine("MC Block Name\tVS Block Name\tVS ID#\tMaterial\t"); | |
259 | + reporter.WriteLine("MC Block Name\tVS Block Name\tVS ID#\tDomain\tMaterial\t"); | |
235 | 260 | Logger.VerboseDebug("Dumping {0} Blocks", ClientAPI.World.Blocks.Count); |
236 | - foreach (var block in ClientAPI.World.Blocks.Where(blk => blk.Code != null && blk.Code.Domain == GlobalConstants.DefaultDomain)) { | |
237 | - if (block.Id != 0 && !block.IsMissing && block.Code.Path != "unknown" ) { | |
238 | - reporter.WriteLine($"____\t{block.Code.Path}\t{block.BlockId}\t{block.BlockMaterial}"); | |
239 | 261 | |
262 | + | |
263 | + | |
264 | + foreach (var block in bQuery) { | |
265 | + if (block.Id != 0 && !block.IsMissing && block.Code.Path != "unknown" ) { | |
266 | + reporter.WriteLine($"____\t{block.Code.Path}\t{block.BlockId}\t{block.Code.Domain}\t{block.BlockMaterial}"); | |
240 | 267 | } |
241 | 268 | |
242 | 269 | } |
@@ -244,20 +271,32 @@ namespace CarbonCopy | ||
244 | 271 | reporter.Flush( ); |
245 | 272 | } |
246 | 273 | |
247 | - ClientAPI.ShowChatMessage("Created Block List...."); | |
274 | + ClientAPI.ShowChatMessage("Created Blocks List...."); | |
248 | 275 | } |
249 | 276 | |
250 | - private void Dump_ItemList( ) | |
277 | + private void Dump_ItemList(string domainFilter ) | |
251 | 278 | { |
252 | - var filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), "vs_item_list_export_" + GameVersion.OverallVersion + ".tsv"); | |
279 | + var filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), "vs_item_list_export_" + InternalVersion.Version + ".tsv"); | |
280 | + | |
281 | + IEnumerable<Item> iQuery; | |
282 | + if (string.IsNullOrWhiteSpace(domainFilter)) { | |
283 | + iQuery = ClientAPI.World.Items.Where(itm => itm.Code != null); | |
284 | + } | |
285 | + else { | |
286 | + iQuery = ClientAPI.World.Items.Where(itm => itm.Code != null && itm.Code.Domain.Equals(domainFilter, StringComparison.OrdinalIgnoreCase)); | |
287 | + filename = Path.Combine(ClientAPI.GetOrCreateDataPath(_exportPath), "vs_item_list_export_" + InternalVersion.Version + "_[" + domainFilter + "]" + ".tsv"); | |
288 | + } | |
253 | 289 | |
254 | 290 | using (StreamWriter reporter = new StreamWriter(filename, false)) { |
255 | 291 | |
256 | - reporter.WriteLine("MC Item Name\tVS Item Name\tVS ID#\tStorage Flags\tMax Stack Size\tC.I. Tabs\t"); | |
292 | + reporter.WriteLine("MC Item Name\tVS Item Name\tVS ID#\tDomain\tStorage Flags\tMax Stack Size\tC.I. Tabs\t"); | |
257 | 293 | Logger.VerboseDebug("Dumping {0} Items", ClientAPI.World.Items.Count); |
258 | - foreach (var item in ClientAPI.World.Items.Where(itm => itm.Code != null && itm.Code.Domain == GlobalConstants.DefaultDomain)) { | |
294 | + | |
295 | + | |
296 | + | |
297 | + foreach (var item in iQuery ) { | |
259 | 298 | if (item.Id != 0 && !item.IsMissing && item.Code.Path != "unknown") { |
260 | - 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): " ")}"); | |
299 | + reporter.WriteLine($"____\t{item.Code.Path}\t{item.ItemId}\t{item.Code.Domain}\t{String.Join(",", item.StorageFlags)}\t{item.MaxStackSize}\t{(item.CreativeInventoryTabs != null ? String.Join(",",item.CreativeInventoryTabs): " ")}"); | |
261 | 300 | } |
262 | 301 | |
263 | 302 | } |
@@ -1,14 +1,12 @@ | ||
1 | 1 | { |
2 | 2 | "type": "code", |
3 | 3 | "name": "Carbon-Copy", |
4 | - "description" : "Export schematics from MP (clientside!)", | |
4 | + "description" : "Export schematics, and more from SP/MP (clientside!)", | |
5 | 5 | "authors": ["Melchior"], |
6 | - "version": "0.1.5", | |
6 | + "version": "0.1.6", | |
7 | 7 | "side": "client", |
8 | 8 | "dependencies": { |
9 | 9 | "game": "1.13.0" |
10 | 10 | }, |
11 | 11 | "website": "http://nowebsite.nope" |
12 | -} | |
13 | - | |
14 | - | |
12 | +} | |
\ No newline at end of file |