• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

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

Adjustor mod plugin for VS


Commit MetaInfo

Revision0be55ec229ad88a4b854fb1f73231ba2774bdb59 (tree)
Zeit2019-06-06 07:18:55
Autormelchior <melchior@user...>
Commitermelchior

Log Message

Reworked applicability detection,
removed outdated comments

Ändern Zusammenfassung

Diff

--- a/AdjustorMod/AdjustorMod.cs
+++ b/AdjustorMod/AdjustorMod.cs
@@ -29,7 +29,7 @@ namespace Adjustor
2929 base.Start(api);
3030 api.RegisterItemClass(_name, typeof(ItemAdjustor));
3131 Mod.Logger.Debug( "Registered - {0}", _name );
32- //TODO: Register client / server side tool config command
32+
3333 }
3434 }
3535 }
--- a/AdjustorMod/ItemAdjustor.cs
+++ b/AdjustorMod/ItemAdjustor.cs
@@ -27,35 +27,43 @@ namespace Adjustor
2727 private ICoreClientAPI ClientApi { get; set; }
2828
2929 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
3033
31- private static string[] rotationCodes = new string[]
34+ private static string _simpleCoatingClass = @"BlockSimpleCoating";//Similar to slabs...
35+
36+ private static string[] _cardinalCodes = new string[]
3237 {
33- @"up",
34- @"down",
3538 @"north",
3639 @"south",
3740 @"east",
3841 @"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....;
4053 @"ud",
4154 @"ns",
4255 @"we"
4356 };
4457
45- private static string[] blacklistedClasses = new string[]
58+ private static string[] _blacklistedClasses = new string[]
4659 {
4760 @"BlockBed",
4861 @"BlockDoor",
4962 @"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.
5664 };
5765
58- private static string[] blacklistedEntityClasses = new string[]
66+ private static string[] _blacklistedEntityClasses = new string[]
5967 {
6068 @"GenericTypedContainer",
6169 };
@@ -64,6 +72,7 @@ namespace Adjustor
6472 {
6573 "verticalorientation",
6674 "rot",
75+ "side"//linen, plates, ect... used inconsistently
6776 };
6877
6978 private static string[] _horizontalVariantKeys = new string[]
@@ -73,6 +82,15 @@ namespace Adjustor
7382 "side"
7483 };
7584
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+
7694 public ItemAdjustor( ) : base( )
7795 {
7896
@@ -122,7 +140,7 @@ namespace Adjustor
122140 BlockPos position = blockSel.Position;
123141 Block thatBlock = byEntity.World.BlockAccessor.GetBlock(position);
124142
125- if (RotatableByDirection(thatBlock) || RotatableByBehavior(thatBlock)) {
143+ if (RotatableByVariant(thatBlock) || RotatableByBehavior(thatBlock)) {
126144 #if DEBUG
127145 Logger.VerboseDebug("[{0}] Looks Rotatable, FromFace: {1}", thatBlock.Code.Path, blockSel.Face.Code);
128146 ClientApi.ShowChatMessage(string.Format("Appears Rotatable: {0}", thatBlock.Code));
@@ -313,31 +331,29 @@ namespace Adjustor
313331 /// <param name="thatBlock">That block.</param>
314332 private static bool IsBlacklisted(Block thatBlock)
315333 {
316- if (blacklistedEntityClasses.Contains(thatBlock.EntityClass)
317- || blacklistedClasses.Contains(thatBlock.Class))
334+ if (_blacklistedEntityClasses.Contains(thatBlock.EntityClass)
335+ || _blacklistedClasses.Contains(thatBlock.Class))
318336 return true;
319337
320338 return false;
321339 }
322340
323341 /// <summary>
324- /// Is it Rotatable, possibly with Known direction?
342+ /// Is it Rotatable, possibly with Variant key that is known to be a direction?
325343 /// </summary>
326344 /// <returns><c>true</c>, if rotatable, <c>false</c> otherwise.</returns>
327345 /// <param name="thatBlock">A block.</param>
328- private static bool RotatableByDirection(Block thatBlock)
346+ private static bool RotatableByVariant(Block thatBlock)
329347 {
330348 if (thatBlock != null) {
331349
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+ {
341357 return true;
342358 }
343359 }
@@ -355,7 +371,9 @@ namespace Adjustor
355371 if (thatBlock != null) {
356372
357373 if (thatBlock.BlockBehaviors.Length > 0) {
374+ #if DEBUG
358375 Logger.VerboseDebug("Block {0} has {1} #behaviors", thatBlock.Code.ToShortString( ), thatBlock.BlockBehaviors.Length);
376+ #endif
359377 }
360378
361379 if (thatBlock.HasBehavior("OmniRotatable", ClientApi.ClassRegistry)
@@ -371,20 +389,71 @@ namespace Adjustor
371389 }
372390
373391 /// <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>
374440 /// Changes AssetLocation from a N/E/W/S Slab into a UP slab.
375441 /// </summary>
376442 /// <returns>The slab vertical flip case.</returns>
377443 /// <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
384452
385- //AssetLocation.LocationSeparator
453+ redirectionPath = thatBlock.Code.Path.Replace(horizontalValue, @"up");
454+ }
386455
387- return new AssetLocation(thatBlock.Code.Domain, redirectionPath);//game or item tags?
456+ return new AssetLocation(thatBlock.Code.Domain, redirectionPath);
388457 }
389458
390459 /// <summary>
@@ -392,24 +461,34 @@ namespace Adjustor
392461 /// </summary>
393462 /// <returns>The slab vertical flip case.</returns>
394463 /// <param name="thatBlock">That block.</param>
395- private static AssetLocation SpecialSlabHorizontalFlipCase(Block thatBlock)
464+ private static AssetLocation SpecialHorizontalFlipCase(Block thatBlock)
396465 {
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
401472
402- //AssetLocation.LocationSeparator
473+ redirectionPath = thatBlock.Code.Path.Replace(verticalValue, @"north");
474+ }
403475
404- return new AssetLocation(thatBlock.Code.Domain, redirectionPath);//game or item tags?
476+ return new AssetLocation(thatBlock.Code.Domain, redirectionPath);
405477 }
406478
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)
408487 {
409488 string oppositeDirection = string.Empty;
410489
411490 //wood Log by: ns / we - change to opposite
412- string directionName = thatBlock.Code.Path.Split("-".ToCharArray( )).Last( );
491+ string directionName = thatBlock.Variant[_axialRotationKey];
413492 if (axisNormal) {
414493 switch (directionName) {
415494 case @"ud":
@@ -442,49 +521,13 @@ namespace Adjustor
442521 }
443522
444523 /// <summary>
445- /// Determines if is slab in N/E/W/S configuration
524+ /// Is this a axial type thing / wood log?
446525 /// </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>
469527 /// <param name="thatBlock">That block.</param>
470- private static bool IsSlabUD(Block thatBlock)
528+ private static bool IsAxialOriented(Block thatBlock)
471529 {
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);
488531 }
489532
490533
@@ -513,22 +556,33 @@ namespace Adjustor
513556 }
514557
515558 if (rotateHorizontal) {
516-#if DEBUG
559+ #if DEBUG
517560 ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle N/E/W/S.", EnumChatType.Notification);
518-#endif
561+ #endif
519562
520563 //So many HORIZONTAL Special Cases...
521564 renamedAsset = thatBlock.GetRotatedBlockCode(90);//Except Fences
522565
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+ }
524572
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+ }
526580
527581
528582 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
532586
533587 var rotatedBlock = ServerApi.World.GetBlock(renamedAsset);
534588 if (rotatedBlock != null) {
@@ -538,22 +592,33 @@ namespace Adjustor
538592 }
539593 }
540594 } else {
541-#if DEBUG
595+ #if DEBUG
542596 ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle U/D.", EnumChatType.Notification);
543-#endif
597+ #endif
544598
545599 renamedAsset = thatBlock.GetVerticallyFlippedBlockCode( );
546600
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+ }
549608
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+ }
551616
552617 if (renamedAsset != thatBlock.Code) {
553618
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
557622
558623 var rotatedBlock = ServerApi.World.GetBlock(renamedAsset);
559624 if (rotatedBlock != null) {
@@ -594,7 +659,9 @@ namespace Adjustor
594659 Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset);
595660 }
596661 } else {
662+ #if DEBUG
597663 Logger.VerboseDebug("{0} IDENTICAL!? {1}", thatBlock.Code, renamedAsset);
664+ #endif
598665 }
599666 }
600667 }
@@ -609,7 +676,7 @@ namespace Adjustor
609676 case RotationModes.Up:
610677 case RotationModes.Down:
611678
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!
613680 if (!string.IsNullOrEmpty(rotationKey))
614681 {
615682 string roatableValue = thatBlock.Variant[rotationKey];
@@ -629,7 +696,7 @@ namespace Adjustor
629696 case RotationModes.West:
630697 case RotationModes.South:
631698
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!
633700 if (!string.IsNullOrEmpty(rotationKey)) {
634701 string roatableValue = thatBlock.Variant[rotationKey];
635702