Adjustor mod plugin for VS
Revision | 5a362bba54a7e35b856c6bb5285b898f6320f8c1 (tree) |
---|---|
Zeit | 2019-06-07 05:53:47 |
Autor | melchior <melchior@user...> |
Commiter | melchior |
Item condition loss only when change made
Tool mode icons
Version incriment
@@ -172,6 +172,7 @@ namespace Adjustor | ||
172 | 172 | } |
173 | 173 | |
174 | 174 | if (api.Side.IsServer( )) { |
175 | + bool madeAdjustment = false; | |
175 | 176 | |
176 | 177 | BlockPos position = blockSel.Position; |
177 | 178 | Block thatBlock = byEntity.World.BlockAccessor.GetBlock(position); |
@@ -189,18 +190,17 @@ namespace Adjustor | ||
189 | 190 | |
190 | 191 | EnumWorldAccessResponse why = ServerApi.World.Claims.TestAccess(thePlayer, position, EnumBlockAccessFlags.BuildOrBreak); |
191 | 192 | if (why != EnumWorldAccessResponse.Granted) { |
192 | - ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, string.Format("Not permitted, {0}", why.ToString( )), EnumChatType.Notification); | |
193 | + ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, string.Format("Not permitted, {0}", why), EnumChatType.Notification); | |
193 | 194 | return false; |
194 | 195 | } |
195 | 196 | |
196 | 197 | if (this.CurrentRotationMode(slot) == RotationModes.Free) { |
197 | - FreeRotation(blockSel, byEntity, thePlayer, thatBlock, position); | |
198 | + madeAdjustment = FreeRotation(blockSel, byEntity, thePlayer, thatBlock, position); | |
198 | 199 | } else { |
199 | - FixedRotation(this.CurrentRotationMode(slot),blockSel, byEntity, thePlayer, thatBlock, position); | |
200 | + madeAdjustment = FixedRotation(this.CurrentRotationMode(slot),blockSel, byEntity, thePlayer, thatBlock, position); | |
200 | 201 | } |
201 | 202 | |
202 | - | |
203 | - DamageItem(ServerApi.World, byEntity, slot); | |
203 | + if (madeAdjustment) DamageItem(ServerApi.World, byEntity, slot); | |
204 | 204 | |
205 | 205 | return secondsUsed < 0.7; |
206 | 206 | } |
@@ -249,39 +249,7 @@ namespace Adjustor | ||
249 | 249 | { |
250 | 250 | RotationModes rotateMode = ( RotationModes )toolMode; |
251 | 251 | |
252 | - switch (rotateMode) { | |
253 | - case RotationModes.Free: | |
254 | - DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("adjustor:rotation-free").ToUpperInvariant( )); | |
255 | - break; | |
256 | - | |
257 | - case RotationModes.Up: | |
258 | - DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("adjustor:rotation-up").ToUpperInvariant( )); | |
259 | - break; | |
260 | - | |
261 | - case RotationModes.Down: | |
262 | - DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("adjustor:rotation-down").ToUpperInvariant( )); | |
263 | - break; | |
264 | - | |
265 | - case RotationModes.North: | |
266 | - DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("facing-north" ).ToUpperInvariant() ); | |
267 | - break; | |
268 | - | |
269 | - case RotationModes.East: | |
270 | - DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("facing-east").ToUpperInvariant( ) ); | |
271 | - break; | |
272 | - | |
273 | - case RotationModes.West: | |
274 | - DrawTextGlyph(cr, x, y, width, height, color,Lang.GetMatching("facing-west").ToUpperInvariant( ) ); | |
275 | - break; | |
276 | - | |
277 | - case RotationModes.South: | |
278 | - DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("facing-south").ToUpperInvariant( ) ); | |
279 | - break; | |
280 | - | |
281 | - default: | |
282 | - throw new ArgumentOutOfRangeException( ); | |
283 | - } | |
284 | - | |
252 | + DrawTextGlyph(cr, x, y, width, height, color, rotateMode ); | |
285 | 253 | } |
286 | 254 | |
287 | 255 | public override int GetToolMode(ItemSlot slot, IPlayer byPlayer, BlockSelection blockSelection) |
@@ -539,7 +507,7 @@ namespace Adjustor | ||
539 | 507 | /// <param name="blockSel">Block sel.</param> |
540 | 508 | /// <param name="byEntity">By entity.</param> |
541 | 509 | /// <param name="thePlayer">The player.</param> |
542 | - private void FreeRotation(BlockSelection blockSel, EntityAgent byEntity, IPlayer thePlayer, Block thatBlock, BlockPos position) | |
510 | + private bool FreeRotation(BlockSelection blockSel, EntityAgent byEntity, IPlayer thePlayer, Block thatBlock, BlockPos position) | |
543 | 511 | { |
544 | 512 | bool rotateHorizontal = false; |
545 | 513 | AssetLocation renamedAsset = null; |
@@ -587,6 +555,7 @@ namespace Adjustor | ||
587 | 555 | var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); |
588 | 556 | if (rotatedBlock != null) { |
589 | 557 | ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); |
558 | + return true; | |
590 | 559 | } else { |
591 | 560 | Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); |
592 | 561 | } |
@@ -623,13 +592,14 @@ namespace Adjustor | ||
623 | 592 | var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); |
624 | 593 | if (rotatedBlock != null) { |
625 | 594 | ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); |
595 | + return true; | |
626 | 596 | } else { |
627 | 597 | Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); |
628 | 598 | } |
629 | 599 | } |
630 | 600 | } |
631 | 601 | |
632 | - | |
602 | + return false; | |
633 | 603 | } |
634 | 604 | |
635 | 605 | /// <summary> |
@@ -641,7 +611,7 @@ namespace Adjustor | ||
641 | 611 | /// <param name="thePlayer">The player.</param> |
642 | 612 | /// <param name="thatBlock">That block.</param> |
643 | 613 | /// <param name="position">Position.</param> |
644 | - private void FixedRotation(RotationModes rotationMode, BlockSelection blockSel, EntityAgent byEntity, IPlayer thePlayer, Block thatBlock, BlockPos position) | |
614 | + private bool FixedRotation(RotationModes rotationMode, BlockSelection blockSel, EntityAgent byEntity, IPlayer thePlayer, Block thatBlock, BlockPos position) | |
645 | 615 | { |
646 | 616 | AssetLocation renamedAsset = RenameBlockFace(thatBlock, rotationMode); |
647 | 617 |
@@ -655,6 +625,7 @@ namespace Adjustor | ||
655 | 625 | var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); |
656 | 626 | if (rotatedBlock != null) { |
657 | 627 | ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); |
628 | + return true; | |
658 | 629 | } else { |
659 | 630 | Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); |
660 | 631 | } |
@@ -664,6 +635,8 @@ namespace Adjustor | ||
664 | 635 | #endif |
665 | 636 | } |
666 | 637 | } |
638 | + | |
639 | + return false; | |
667 | 640 | } |
668 | 641 | |
669 | 642 | private AssetLocation RenameBlockFace(Block thatBlock, RotationModes rotationMode) |
@@ -731,23 +704,97 @@ namespace Adjustor | ||
731 | 704 | return new Color(r: ColorUtil.ToRGBADoubles(color)[0], g: ColorUtil.ToRGBADoubles(color)[1], b: ColorUtil.ToRGBADoubles(color)[2], a: ColorUtil.ToRGBADoubles(color)[3]); |
732 | 705 | } |
733 | 706 | |
734 | - private void DrawTextGlyph(Context cr, int x, int y, int width, int height, int color, string text) | |
707 | + private void DrawTextGlyph(Context cr, int x, int y, int width, int height, int color, RotationModes toolMode) | |
735 | 708 | { |
709 | + string text = string.Empty; | |
736 | 710 | TextDrawUtil stampy = new TextDrawUtil( ); |
737 | 711 | |
738 | 712 | Pattern pattern = null; |
739 | 713 | Matrix matrix = cr.Matrix; |
740 | 714 | |
741 | 715 | cr.Save( ); |
716 | + | |
717 | + ElementBounds bounds = ElementBounds.Fixed(width, height); | |
718 | + | |
742 | 719 | /* |
743 | - float local_width = 220; | |
744 | - float local_height = 182; | |
745 | - float scale = Math.Min(width / local_width, height / local_height); | |
746 | - matrix.Translate(x + Math.Max(0, (width - local_width * scale) / 2), y + Math.Max(0, (height - local_height * scale) / 2)); | |
747 | - matrix.Scale(scale, scale); | |
748 | - cr.Matrix = matrix; | |
720 | + if (cr.GetTarget( ) is ImageSurface) { | |
721 | + ImageSurface imgSurface = ( ImageSurface )cr.GetTarget( ); | |
722 | + bounds = ElementBounds.Fixed(imgSurface.Width, imgSurface.Height); | |
723 | + } | |
749 | 724 | */ |
750 | 725 | |
726 | + CairoFont font = CairoFont.WhiteMediumText( ); | |
727 | + font.StrokeColor = ColorUtil.BlackArgbDouble; | |
728 | + font.FontWeight = FontWeight.Bold; | |
729 | + | |
730 | + switch (toolMode) { | |
731 | + case RotationModes.Free: | |
732 | + text = Lang.GetMatching("adjustor:rotation-free").ToUpper( ); | |
733 | + | |
734 | + cr.SetSourceRGB(0D, 0.75D, 0D); | |
735 | + cr.Arc(24, 24, 18, 0, 6D); | |
736 | + cr.Stroke( ); | |
737 | + | |
738 | + break; | |
739 | + | |
740 | + case RotationModes.Up: | |
741 | + text = Lang.GetMatching("adjustor:rotation-up").ToUpper( ); | |
742 | + | |
743 | + cr.SetSourceRGB(0.85D, 0.85D, 0.85D); | |
744 | + cr.Rectangle(4, 4, 38, 8); | |
745 | + cr.Stroke( ); | |
746 | + | |
747 | + break; | |
748 | + | |
749 | + case RotationModes.Down: | |
750 | + text = Lang.GetMatching("adjustor:rotation-down").ToUpper( ); | |
751 | + | |
752 | + cr.SetSourceRGB(0.85D, 0.85D, 0.85D); | |
753 | + cr.Rectangle(4, 34, 38, 8); | |
754 | + cr.Stroke( ); | |
755 | + | |
756 | + break; | |
757 | + | |
758 | + case RotationModes.North: | |
759 | + text = Lang.GetMatching("facing-north").ToUpper( ); | |
760 | + | |
761 | + cr.SetSourceRGB(0.95D, 0D, 0D); | |
762 | + cr.MoveTo(24, 24); | |
763 | + cr.RelLineTo(0, -16); | |
764 | + cr.Stroke( ); | |
765 | + break; | |
766 | + | |
767 | + case RotationModes.East: | |
768 | + text = Lang.GetMatching("facing-east").ToUpper( ); | |
769 | + | |
770 | + cr.SetSourceRGB(0.85D, 0.85D, 0.85D); | |
771 | + cr.LineWidth = 1.0D; | |
772 | + cr.MoveTo(24, 24); | |
773 | + cr.RelLineTo(16, 0); | |
774 | + cr.Stroke( ); | |
775 | + break; | |
776 | + | |
777 | + case RotationModes.West: | |
778 | + text = Lang.GetMatching("facing-west").ToUpper( ); | |
779 | + | |
780 | + cr.SetSourceRGB(0.85D, 0.85D, 0.85D); | |
781 | + cr.LineWidth = 1.0D; | |
782 | + cr.MoveTo(24, 24); | |
783 | + cr.RelLineTo(-16, 0); | |
784 | + cr.Stroke( ); | |
785 | + break; | |
786 | + | |
787 | + case RotationModes.South: | |
788 | + text = Lang.GetMatching("facing-south").ToUpper( ); | |
789 | + | |
790 | + cr.SetSourceRGB(0.85D, 0.85D, 0.85D); | |
791 | + cr.LineWidth = 1.0D; | |
792 | + cr.MoveTo(24, 24); | |
793 | + cr.RelLineTo(0, 16); | |
794 | + cr.Stroke( ); | |
795 | + break; | |
796 | + } | |
797 | + | |
751 | 798 | cr.Operator = Operator.Over; |
752 | 799 | pattern = new SolidPattern(ToCarioColor(color)); |
753 | 800 | cr.SetSource(pattern); |
@@ -758,17 +805,15 @@ namespace Adjustor | ||
758 | 805 | cr.Antialias = Antialias.Default; |
759 | 806 | cr.FillRule = FillRule.Winding; |
760 | 807 | |
761 | - stampy.DrawTextLine(cr, CairoFont.WhiteMediumText( ).WithFontSize(96F).WithWeight(FontWeight.Bold), text, 8D, 16D); | |
762 | - //cr.LineWidth = 3D; | |
763 | - //cr.MoveTo(64, 16); | |
764 | - //cr.RelLineTo(0D, 248D); | |
808 | + font.AutoFontSize(text, bounds); | |
809 | + font.UnscaledFontsize += 25; | |
810 | + | |
811 | + stampy.DrawTextLine(cr, font, text, 4D, height/2); | |
765 | 812 | |
766 | 813 | cr.FillPreserve( ); |
767 | 814 | } |
768 | 815 | |
769 | 816 | |
770 | - | |
771 | - | |
772 | 817 | #endregion |
773 | 818 | } |
774 | 819 | } |
@@ -3,7 +3,7 @@ | ||
3 | 3 | "name": "Adjustment Tool", |
4 | 4 | "description" : "Alter, Rotate blocks without breaking them. Now with Economy tool!", |
5 | 5 | "authors": ["Melchior", ], |
6 | - "version": "0.1.7", | |
6 | + "version": "0.1.8", | |
7 | 7 | "dependencies": { |
8 | 8 | "game": "1.9.6", |
9 | 9 | "survival": "" |