Adjustor mod plugin for VS
Revision | 0be55ec229ad88a4b854fb1f73231ba2774bdb59 (tree) |
---|---|
Zeit | 2019-06-06 07:18:55 |
Autor | melchior <melchior@user...> |
Commiter | melchior |
Reworked applicability detection,
removed outdated comments
@@ -29,7 +29,7 @@ namespace Adjustor | ||
29 | 29 | base.Start(api); |
30 | 30 | api.RegisterItemClass(_name, typeof(ItemAdjustor)); |
31 | 31 | Mod.Logger.Debug( "Registered - {0}", _name ); |
32 | - //TODO: Register client / server side tool config command | |
32 | + | |
33 | 33 | } |
34 | 34 | } |
35 | 35 | } |
@@ -27,35 +27,43 @@ namespace Adjustor | ||
27 | 27 | private ICoreClientAPI ClientApi { get; set; } |
28 | 28 | |
29 | 29 | private const string _toolMode = @"toolMode"; |
30 | + private const string _sideKey = @"side"; | |
31 | + private const string _rotKey = @"rot";//Slabs use this key instead.... | |
32 | + private const string _axialRotationKey = @"rotation";//Trees and Pillars; ns, we, ud - axial rotation | |
30 | 33 | |
31 | - private static string[] rotationCodes = new string[] | |
34 | + private static string _simpleCoatingClass = @"BlockSimpleCoating";//Similar to slabs... | |
35 | + | |
36 | + private static string[] _cardinalCodes = new string[] | |
32 | 37 | { |
33 | - @"up", | |
34 | - @"down", | |
35 | 38 | @"north", |
36 | 39 | @"south", |
37 | 40 | @"east", |
38 | 41 | @"west", |
39 | - //tree logs; | |
42 | + }; | |
43 | + | |
44 | + private static string[] _verticalCodes = new string[] | |
45 | + { | |
46 | + @"up", | |
47 | + @"down", | |
48 | + }; | |
49 | + | |
50 | + private static string[] _axialRotationCodes = new string[] | |
51 | + { | |
52 | + //tree logs, and tree log-like things; pillars, axles....; | |
40 | 53 | @"ud", |
41 | 54 | @"ns", |
42 | 55 | @"we" |
43 | 56 | }; |
44 | 57 | |
45 | - private static string[] blacklistedClasses = new string[] | |
58 | + private static string[] _blacklistedClasses = new string[] | |
46 | 59 | { |
47 | 60 | @"BlockBed", |
48 | 61 | @"BlockDoor", |
49 | 62 | @"BlockTroughDoubleBlock", |
50 | - @"BlockFence" //TODO:Need to figure out a better way.. | |
51 | - }; | |
52 | - | |
53 | - private static string[] whitelistedClasses = new string[] //FIXME This should work... | |
54 | - { | |
55 | - @"placeholder", | |
63 | + @"BlockFence" //FIXME: Blacklist of Multi-block entites until futher notice. | |
56 | 64 | }; |
57 | 65 | |
58 | - private static string[] blacklistedEntityClasses = new string[] | |
66 | + private static string[] _blacklistedEntityClasses = new string[] | |
59 | 67 | { |
60 | 68 | @"GenericTypedContainer", |
61 | 69 | }; |
@@ -64,6 +72,7 @@ namespace Adjustor | ||
64 | 72 | { |
65 | 73 | "verticalorientation", |
66 | 74 | "rot", |
75 | + "side"//linen, plates, ect... used inconsistently | |
67 | 76 | }; |
68 | 77 | |
69 | 78 | private static string[] _horizontalVariantKeys = new string[] |
@@ -73,6 +82,15 @@ namespace Adjustor | ||
73 | 82 | "side" |
74 | 83 | }; |
75 | 84 | |
85 | + private static string[] _slabesqueCodes = new string[] | |
86 | + { | |
87 | + "slab",//many things with 'slab' in name, some at begin some at end... | |
88 | + | |
89 | + }; | |
90 | + | |
91 | + | |
92 | + | |
93 | + | |
76 | 94 | public ItemAdjustor( ) : base( ) |
77 | 95 | { |
78 | 96 |
@@ -122,7 +140,7 @@ namespace Adjustor | ||
122 | 140 | BlockPos position = blockSel.Position; |
123 | 141 | Block thatBlock = byEntity.World.BlockAccessor.GetBlock(position); |
124 | 142 | |
125 | - if (RotatableByDirection(thatBlock) || RotatableByBehavior(thatBlock)) { | |
143 | + if (RotatableByVariant(thatBlock) || RotatableByBehavior(thatBlock)) { | |
126 | 144 | #if DEBUG |
127 | 145 | Logger.VerboseDebug("[{0}] Looks Rotatable, FromFace: {1}", thatBlock.Code.Path, blockSel.Face.Code); |
128 | 146 | ClientApi.ShowChatMessage(string.Format("Appears Rotatable: {0}", thatBlock.Code)); |
@@ -313,31 +331,29 @@ namespace Adjustor | ||
313 | 331 | /// <param name="thatBlock">That block.</param> |
314 | 332 | private static bool IsBlacklisted(Block thatBlock) |
315 | 333 | { |
316 | - if (blacklistedEntityClasses.Contains(thatBlock.EntityClass) | |
317 | - || blacklistedClasses.Contains(thatBlock.Class)) | |
334 | + if (_blacklistedEntityClasses.Contains(thatBlock.EntityClass) | |
335 | + || _blacklistedClasses.Contains(thatBlock.Class)) | |
318 | 336 | return true; |
319 | 337 | |
320 | 338 | return false; |
321 | 339 | } |
322 | 340 | |
323 | 341 | /// <summary> |
324 | - /// Is it Rotatable, possibly with Known direction? | |
342 | + /// Is it Rotatable, possibly with Variant key that is known to be a direction? | |
325 | 343 | /// </summary> |
326 | 344 | /// <returns><c>true</c>, if rotatable, <c>false</c> otherwise.</returns> |
327 | 345 | /// <param name="thatBlock">A block.</param> |
328 | - private static bool RotatableByDirection(Block thatBlock) | |
346 | + private static bool RotatableByVariant(Block thatBlock) | |
329 | 347 | { |
330 | 348 | if (thatBlock != null) { |
331 | 349 | |
332 | - if (thatBlock.Class != null && whitelistedClasses.Any(wc => thatBlock.Class.Equals(wc)))//BROKEN! | |
333 | - { | |
334 | - //Whitelisted | |
335 | - return true; | |
336 | - } else if | |
337 | - (thatBlock.IsMissing == false | |
338 | - && thatBlock.MatterState == EnumMatterState.Solid | |
339 | - && rotationCodes.Any(rc => thatBlock.Code.Path.Contains(rc)) | |
340 | - ) { | |
350 | + if (thatBlock.IsMissing == false && thatBlock.MatterState == EnumMatterState.Solid | |
351 | + && (_verticalVariantKeys.Any(vvk => thatBlock.Variant.Keys.Contains(vvk)) || | |
352 | + _horizontalVariantKeys.Any(hvk => thatBlock.Variant.Keys.Contains(hvk)) || | |
353 | + thatBlock.Variant.Keys.Contains(_axialRotationKey) | |
354 | + ) | |
355 | + ) | |
356 | + { | |
341 | 357 | return true; |
342 | 358 | } |
343 | 359 | } |
@@ -355,7 +371,9 @@ namespace Adjustor | ||
355 | 371 | if (thatBlock != null) { |
356 | 372 | |
357 | 373 | if (thatBlock.BlockBehaviors.Length > 0) { |
374 | + #if DEBUG | |
358 | 375 | Logger.VerboseDebug("Block {0} has {1} #behaviors", thatBlock.Code.ToShortString( ), thatBlock.BlockBehaviors.Length); |
376 | + #endif | |
359 | 377 | } |
360 | 378 | |
361 | 379 | if (thatBlock.HasBehavior("OmniRotatable", ClientApi.ClassRegistry) |
@@ -371,20 +389,71 @@ namespace Adjustor | ||
371 | 389 | } |
372 | 390 | |
373 | 391 | /// <summary> |
392 | + /// Determines if slab, sheet, plate type block in a N/E/W/S configuration | |
393 | + /// </summary> | |
394 | + /// <returns><c>true</c> if is slab NEW the specified thatBlock; otherwise, <c>false</c>.</returns> | |
395 | + /// <param name="thatBlock">That block.</param> | |
396 | + private static bool IsSpecialCaseNEWS(Block thatBlock) | |
397 | + { | |
398 | + if (_simpleCoatingClass.Equals(thatBlock.Class, StringComparison.OrdinalIgnoreCase)) { | |
399 | + | |
400 | + if (thatBlock.Variant.ContainsKey(_sideKey)) { | |
401 | + | |
402 | + if (_cardinalCodes.Contains(thatBlock.Variant[_sideKey])) return true; | |
403 | + } | |
404 | + } | |
405 | + | |
406 | + if (_slabesqueCodes.Any(thatBlock.Code.Path.Contains)) { | |
407 | + | |
408 | + string rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_horizontalVariantKeys.Contains); | |
409 | + | |
410 | + if (_cardinalCodes.Contains(thatBlock.Variant[rotationKey])) return true; | |
411 | + } | |
412 | + return false; | |
413 | + } | |
414 | + | |
415 | + /// <summary> | |
416 | + /// Determines if slab, sheet, plate type block in a U/D configuration | |
417 | + /// </summary> | |
418 | + /// <returns><c>true</c> if is slab NEW the specified thatBlock; otherwise, <c>false</c>.</returns> | |
419 | + /// <param name="thatBlock">That block.</param> | |
420 | + private static bool IsSpecialCaseUD(Block thatBlock) | |
421 | + { | |
422 | + if (_simpleCoatingClass.Equals(thatBlock.Class, StringComparison.OrdinalIgnoreCase)) { | |
423 | + | |
424 | + if (thatBlock.Variant.ContainsKey(_sideKey)) { | |
425 | + | |
426 | + if (_verticalCodes.Contains(thatBlock.Variant[_sideKey])) return true; | |
427 | + } | |
428 | + } | |
429 | + | |
430 | + if (_slabesqueCodes.Any(thatBlock.Code.Path.Contains)) { | |
431 | + | |
432 | + string rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_verticalVariantKeys.Contains); | |
433 | + | |
434 | + if (_verticalCodes.Contains(thatBlock.Variant[rotationKey])) return true; | |
435 | + } | |
436 | + return false; | |
437 | + } | |
438 | + | |
439 | + /// <summary> | |
374 | 440 | /// Changes AssetLocation from a N/E/W/S Slab into a UP slab. |
375 | 441 | /// </summary> |
376 | 442 | /// <returns>The slab vertical flip case.</returns> |
377 | 443 | /// <param name="thatBlock">That block.</param> |
378 | - private static AssetLocation SpecialSlabVerticalFlipCase(Block thatBlock) | |
379 | - { | |
380 | - //Slab in North / East / West / South - but needs to be UP | |
381 | - string directionName = thatBlock.Code.Path.Split("-".ToCharArray( )).Last( ); | |
382 | - var redirectionPath = thatBlock.Code.Path.Replace(directionName, @"up"); | |
383 | - //Regex.Replace( thatBlock.Code.Path, @"-\w*$", @"-up" ); | |
444 | + private static AssetLocation SpecialVerticalFlipCase(Block thatBlock) | |
445 | + { | |
446 | + string rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_horizontalVariantKeys.Contains);//There better be only 1 dimension here! | |
447 | + string redirectionPath = null; | |
448 | + | |
449 | + if (!string.IsNullOrEmpty(rotationKey)) { | |
450 | + string horizontalValue = thatBlock.Variant[rotationKey]; | |
451 | + //Slab in North / East / West / South - but needs to be UP | |
384 | 452 | |
385 | - //AssetLocation.LocationSeparator | |
453 | + redirectionPath = thatBlock.Code.Path.Replace(horizontalValue, @"up"); | |
454 | + } | |
386 | 455 | |
387 | - return new AssetLocation(thatBlock.Code.Domain, redirectionPath);//game or item tags? | |
456 | + return new AssetLocation(thatBlock.Code.Domain, redirectionPath); | |
388 | 457 | } |
389 | 458 | |
390 | 459 | /// <summary> |
@@ -392,24 +461,34 @@ namespace Adjustor | ||
392 | 461 | /// </summary> |
393 | 462 | /// <returns>The slab vertical flip case.</returns> |
394 | 463 | /// <param name="thatBlock">That block.</param> |
395 | - private static AssetLocation SpecialSlabHorizontalFlipCase(Block thatBlock) | |
464 | + private static AssetLocation SpecialHorizontalFlipCase(Block thatBlock) | |
396 | 465 | { |
397 | - //Slab in UP / DOWN - but needs to be north | |
398 | - string directionName = thatBlock.Code.Path.Split("-".ToCharArray( )).Last( ); | |
399 | - var redirectionPath = thatBlock.Code.Path.Replace(directionName, @"north"); | |
400 | - //Regex.Replace( thatBlock.Code.Path, @"-\w*$", @"-up" ); | |
466 | + string rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_verticalVariantKeys.Contains);//There better be only 1 dimension here! | |
467 | + string redirectionPath = null; | |
468 | + | |
469 | + if (!string.IsNullOrEmpty(rotationKey)) { | |
470 | + string verticalValue = thatBlock.Variant[rotationKey]; | |
471 | + //Slab in Up / Down - but needs to be NORTH | |
401 | 472 | |
402 | - //AssetLocation.LocationSeparator | |
473 | + redirectionPath = thatBlock.Code.Path.Replace(verticalValue, @"north"); | |
474 | + } | |
403 | 475 | |
404 | - return new AssetLocation(thatBlock.Code.Domain, redirectionPath);//game or item tags? | |
476 | + return new AssetLocation(thatBlock.Code.Domain, redirectionPath); | |
405 | 477 | } |
406 | 478 | |
407 | - private static AssetLocation WoodOmniFlip(Block thatBlock, EnumAxis axis, bool axisNormal) | |
479 | + /// <summary> | |
480 | + /// For flipping Axial oriented things | |
481 | + /// </summary> | |
482 | + /// <returns>The omni flip.</returns> | |
483 | + /// <param name="thatBlock">That block.</param> | |
484 | + /// <param name="axis">Axis.</param> | |
485 | + /// <param name="axisNormal">Axis normal.</param> | |
486 | + private static AssetLocation AxialOmniFlip(Block thatBlock, EnumAxis axis, bool axisNormal) | |
408 | 487 | { |
409 | 488 | string oppositeDirection = string.Empty; |
410 | 489 | |
411 | 490 | //wood Log by: ns / we - change to opposite |
412 | - string directionName = thatBlock.Code.Path.Split("-".ToCharArray( )).Last( ); | |
491 | + string directionName = thatBlock.Variant[_axialRotationKey]; | |
413 | 492 | if (axisNormal) { |
414 | 493 | switch (directionName) { |
415 | 494 | case @"ud": |
@@ -442,49 +521,13 @@ namespace Adjustor | ||
442 | 521 | } |
443 | 522 | |
444 | 523 | /// <summary> |
445 | - /// Determines if is slab in N/E/W/S configuration | |
524 | + /// Is this a axial type thing / wood log? | |
446 | 525 | /// </summary> |
447 | - /// <returns><c>true</c> if is slab NEW the specified thatBlock; otherwise, <c>false</c>.</returns> | |
448 | - /// <param name="thatBlock">That block.</param> | |
449 | - private static bool IsSlabNEWS(Block thatBlock) | |
450 | - { | |
451 | - string firstName = thatBlock.Code.Path.Split("-".ToCharArray( )).First( ); | |
452 | - | |
453 | - if (firstName.EndsWith(@"slab", StringComparison.Ordinal)) { | |
454 | - if (thatBlock.Code.Path.EndsWith("north", StringComparison.Ordinal) | |
455 | - || thatBlock.Code.Path.EndsWith("south", StringComparison.Ordinal) | |
456 | - || thatBlock.Code.Path.EndsWith("east", StringComparison.Ordinal) | |
457 | - || thatBlock.Code.Path.EndsWith("west", StringComparison.Ordinal)) { | |
458 | - return true; | |
459 | - } | |
460 | - //Its UP/DOWN...Thus false. | |
461 | - } | |
462 | - return false; | |
463 | - } | |
464 | - | |
465 | - /// <summary> | |
466 | - /// Determines if is slab in N/E/W/S configuration | |
467 | - /// </summary> | |
468 | - /// <returns><c>true</c> if is slab NEW the specified thatBlock; otherwise, <c>false</c>.</returns> | |
526 | + /// <returns>If its axial.</returns> | |
469 | 527 | /// <param name="thatBlock">That block.</param> |
470 | - private static bool IsSlabUD(Block thatBlock) | |
528 | + private static bool IsAxialOriented(Block thatBlock) | |
471 | 529 | { |
472 | - string firstName = thatBlock.Code.Path.Split("-".ToCharArray( )).First( ); | |
473 | - | |
474 | - if (firstName.EndsWith(@"slab", StringComparison.Ordinal)) { | |
475 | - if (thatBlock.Code.Path.EndsWith("up", StringComparison.Ordinal) | |
476 | - || thatBlock.Code.Path.EndsWith("down", StringComparison.Ordinal) | |
477 | - ) { | |
478 | - return true; | |
479 | - } | |
480 | - //Its UP/DOWN...Thus false. | |
481 | - } | |
482 | - return false; | |
483 | - } | |
484 | - | |
485 | - private static bool IsWoodLog(Block thatBlock) | |
486 | - { | |
487 | - return thatBlock.Code.FirstPathPart(0).StartsWith(@"log", StringComparison.Ordinal); | |
530 | + return thatBlock.Variant.ContainsKey(_axialRotationKey); | |
488 | 531 | } |
489 | 532 | |
490 | 533 |
@@ -513,22 +556,33 @@ namespace Adjustor | ||
513 | 556 | } |
514 | 557 | |
515 | 558 | if (rotateHorizontal) { |
516 | -#if DEBUG | |
559 | + #if DEBUG | |
517 | 560 | ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle N/E/W/S.", EnumChatType.Notification); |
518 | -#endif | |
561 | + #endif | |
519 | 562 | |
520 | 563 | //So many HORIZONTAL Special Cases... |
521 | 564 | renamedAsset = thatBlock.GetRotatedBlockCode(90);//Except Fences |
522 | 565 | |
523 | - if (IsSlabUD(thatBlock)) renamedAsset = SpecialSlabHorizontalFlipCase(thatBlock); | |
566 | + if (IsSpecialCaseUD(thatBlock)) { | |
567 | + renamedAsset = SpecialHorizontalFlipCase(thatBlock); | |
568 | + #if DEBUG | |
569 | + Logger.VerboseDebug("{0} Special UP/DN Case {1}", thatBlock.Code, renamedAsset); | |
570 | + #endif | |
571 | + } | |
524 | 572 | |
525 | - if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special | |
573 | + if (IsAxialOriented(thatBlock)) { | |
574 | + | |
575 | + renamedAsset = AxialOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special | |
576 | + #if DEBUG | |
577 | + Logger.VerboseDebug("{0} Special Axial Case {1}", thatBlock.Code, renamedAsset); | |
578 | + #endif | |
579 | + } | |
526 | 580 | |
527 | 581 | |
528 | 582 | if (renamedAsset != thatBlock.Code) { |
529 | -#if DEBUG | |
530 | - Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset); | |
531 | -#endif | |
583 | + #if DEBUG | |
584 | + Logger.VerboseDebug("{0} Horizontalize: {1}", thatBlock.Code, renamedAsset); | |
585 | + #endif | |
532 | 586 | |
533 | 587 | var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); |
534 | 588 | if (rotatedBlock != null) { |
@@ -538,22 +592,33 @@ namespace Adjustor | ||
538 | 592 | } |
539 | 593 | } |
540 | 594 | } else { |
541 | -#if DEBUG | |
595 | + #if DEBUG | |
542 | 596 | ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle U/D.", EnumChatType.Notification); |
543 | -#endif | |
597 | + #endif | |
544 | 598 | |
545 | 599 | renamedAsset = thatBlock.GetVerticallyFlippedBlockCode( ); |
546 | 600 | |
547 | - //Special Case for Slabs in N/E/S/W mode when trying to rotate them back 'up' | |
548 | - if (IsSlabNEWS(thatBlock)) renamedAsset = SpecialSlabVerticalFlipCase(thatBlock); | |
601 | + //Special Case for Slabs, Sheets in N/E/S/W mode when trying to rotate them back 'up' | |
602 | + if (IsSpecialCaseNEWS(thatBlock)) { | |
603 | + renamedAsset = SpecialVerticalFlipCase(thatBlock); | |
604 | + #if DEBUG | |
605 | + Logger.VerboseDebug("{0} Special N/E/W/S Case {1}", thatBlock.Code, renamedAsset); | |
606 | + #endif | |
607 | + } | |
549 | 608 | |
550 | - if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special | |
609 | + if (IsAxialOriented(thatBlock)) | |
610 | + { | |
611 | + renamedAsset = AxialOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special | |
612 | + #if DEBUG | |
613 | + Logger.VerboseDebug("{0} Special Axial Case {1}", thatBlock.Code, renamedAsset); | |
614 | + #endif | |
615 | + } | |
551 | 616 | |
552 | 617 | if (renamedAsset != thatBlock.Code) { |
553 | 618 | |
554 | -#if DEBUG | |
555 | - Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset); | |
556 | -#endif | |
619 | + #if DEBUG | |
620 | + Logger.VerboseDebug("{0} Verticallize: {1}", thatBlock.Code, renamedAsset); | |
621 | + #endif | |
557 | 622 | |
558 | 623 | var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); |
559 | 624 | if (rotatedBlock != null) { |
@@ -594,7 +659,9 @@ namespace Adjustor | ||
594 | 659 | Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); |
595 | 660 | } |
596 | 661 | } else { |
662 | + #if DEBUG | |
597 | 663 | Logger.VerboseDebug("{0} IDENTICAL!? {1}", thatBlock.Code, renamedAsset); |
664 | + #endif | |
598 | 665 | } |
599 | 666 | } |
600 | 667 | } |
@@ -609,7 +676,7 @@ namespace Adjustor | ||
609 | 676 | case RotationModes.Up: |
610 | 677 | case RotationModes.Down: |
611 | 678 | |
612 | - rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_verticalVariantKeys.Contains);//There better be only 1 axies here! | |
679 | + rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_verticalVariantKeys.Contains);//There better be only 1 dimension here! | |
613 | 680 | if (!string.IsNullOrEmpty(rotationKey)) |
614 | 681 | { |
615 | 682 | string roatableValue = thatBlock.Variant[rotationKey]; |
@@ -629,7 +696,7 @@ namespace Adjustor | ||
629 | 696 | case RotationModes.West: |
630 | 697 | case RotationModes.South: |
631 | 698 | |
632 | - rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_horizontalVariantKeys.Contains);//There better be only 1 axies here! | |
699 | + rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_horizontalVariantKeys.Contains);//There better be only 1 dimension here! | |
633 | 700 | if (!string.IsNullOrEmpty(rotationKey)) { |
634 | 701 | string roatableValue = thatBlock.Variant[rotationKey]; |
635 | 702 |