Adjustor mod plugin for VS
修訂 | 6340b87b164e47a8226af68f2fa159f998acc8f3 (tree) |
---|---|
時間 | 2021-01-06 12:15:58 |
作者 | melchior <melchior@user...> |
Commiter | melchior |
Mesh rotation works....mostly
@@ -7,7 +7,7 @@ | ||
7 | 7 | <OutputType>Library</OutputType> |
8 | 8 | <RootNamespace>AdjustorMod</RootNamespace> |
9 | 9 | <AssemblyName>AdjustorMod</AssemblyName> |
10 | - <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | |
10 | + <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | |
11 | 11 | </PropertyGroup> |
12 | 12 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
13 | 13 | <DebugSymbols>true</DebugSymbols> |
@@ -56,6 +56,8 @@ | ||
56 | 56 | <HintPath>VC_libs\cairo-sharp.dll</HintPath> |
57 | 57 | <Private>False</Private> |
58 | 58 | </Reference> |
59 | + <Reference Include="System.Dynamic" /> | |
60 | + <Reference Include="Microsoft.CSharp" /> | |
59 | 61 | </ItemGroup> |
60 | 62 | <ItemGroup> |
61 | 63 | <Compile Include="Properties\AssemblyInfo.cs" /> |
@@ -1,20 +1,17 @@ | ||
1 | 1 | using System; |
2 | - | |
3 | -using System.Collections; | |
4 | -using System.Collections.Generic; | |
5 | -using System.Collections.ObjectModel; | |
6 | 2 | using System.Linq; |
7 | -using System.Text.RegularExpressions; | |
3 | +using System.Text; | |
4 | +using System.Dynamic; | |
5 | +using System.Runtime; | |
8 | 6 | |
9 | 7 | using Vintagestory.API.Common; |
10 | -using Vintagestory.API.Datastructures; | |
11 | 8 | using Vintagestory.API.MathTools; |
12 | 9 | using Vintagestory.API.Config; |
13 | 10 | using Vintagestory.API.Server; |
14 | 11 | using Vintagestory.API.Client; |
15 | 12 | |
16 | -using Cairo; | |
17 | -using System.Text; | |
13 | +using Vintagestory.GameContent; | |
14 | + | |
18 | 15 | |
19 | 16 | //using Vintagestory.ServerMods; |
20 | 17 |
@@ -27,6 +24,7 @@ namespace AdjustorMod | ||
27 | 24 | private ILogger Logger { get; set; } |
28 | 25 | private ICoreClientAPI ClientApi { get; set; } |
29 | 26 | |
27 | + private const string _meshAngleKey = @"MeshAngle"; | |
30 | 28 | private const string _toolMode = @"toolMode"; |
31 | 29 | private const string _sideKey = @"side"; |
32 | 30 | private const string _rotKey = @"rot";//Slabs use this key instead.... |
@@ -69,9 +67,10 @@ namespace AdjustorMod | ||
69 | 67 | |
70 | 68 | private static string[] _blacklistedEntityClasses = new string[] |
71 | 69 | { |
72 | - @"GenericTypedContainer", | |
70 | + //@"GenericTypedContainer", | |
73 | 71 | }; |
74 | 72 | |
73 | + | |
75 | 74 | private static string[] _verticalVariantKeys = new string[] |
76 | 75 | { |
77 | 76 | "verticalorientation", |
@@ -108,7 +107,9 @@ namespace AdjustorMod | ||
108 | 107 | this.ClientApi = ( ICoreClientAPI )api; |
109 | 108 | this.Logger = this.ClientApi.World.Logger; |
110 | 109 | } |
111 | - Logger.VerboseDebug("ItemAdjustor ~ OnLoaded"); | |
110 | + #if DEBUG | |
111 | + Logger.VerboseDebug("{0} >> ItemAdjustor ~ OnLoaded", this.Code); | |
112 | + #endif | |
112 | 113 | } |
113 | 114 | |
114 | 115 | public override bool OnHeldInteractCancel(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason) |
@@ -138,7 +139,7 @@ namespace AdjustorMod | ||
138 | 139 | BlockPos position = blockSel.Position; |
139 | 140 | Block thatBlock = byEntity.World.BlockAccessor.GetBlock(position); |
140 | 141 | |
141 | - if (RotatableByVariant(thatBlock) || RotatableByBehavior(thatBlock)) { | |
142 | + if (RotatableByVariant(thatBlock) || RotatableByBehavior(thatBlock) || RotatableByAngledMeshEntity(thatBlock, position)) { | |
142 | 143 | #if DEBUG |
143 | 144 | Logger.VerboseDebug("[{0}] Looks Rotatable, FromFace: {1}", thatBlock.Code.Path, blockSel.Face.Code); |
144 | 145 | ClientApi.ShowChatMessage(string.Format("Appears Rotatable: {0}", thatBlock.Code)); |
@@ -176,7 +177,6 @@ namespace AdjustorMod | ||
176 | 177 | Block thatBlock = byEntity.World.BlockAccessor.GetBlock(position); |
177 | 178 | IPlayer thePlayer = null; |
178 | 179 | |
179 | - | |
180 | 180 | if (byEntity is EntityPlayer) { |
181 | 181 | thePlayer = ServerApi.World.PlayerByUid((( EntityPlayer )byEntity).PlayerUID); |
182 | 182 | } |
@@ -191,11 +191,16 @@ namespace AdjustorMod | ||
191 | 191 | ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, string.Format("Not permitted, {0}", why), EnumChatType.Notification); |
192 | 192 | return false; |
193 | 193 | } |
194 | + var meshSpin = RotatableByAngledMeshEntity(thatBlock, position); | |
194 | 195 | |
195 | - if (this.CurrentRotationMode(slot) == RotationModes.Free) { | |
196 | - madeAdjustment = FreeRotation(blockSel, byEntity, thePlayer, thatBlock, position); | |
197 | - } else { | |
198 | - madeAdjustment = FixedRotation(this.CurrentRotationMode(slot),blockSel, byEntity, thePlayer, thatBlock, position); | |
196 | + if (meshSpin) { | |
197 | + madeAdjustment = MeshRotation(this.CurrentRotationMode(slot), thePlayer, thatBlock, position); | |
198 | + } | |
199 | + else if (this.CurrentRotationMode(slot) == RotationModes.Free) { | |
200 | + madeAdjustment = FreeRotation(blockSel, byEntity, thePlayer, thatBlock, position); | |
201 | + } | |
202 | + else { | |
203 | + madeAdjustment = FixedRotation(this.CurrentRotationMode(slot), blockSel, byEntity, thePlayer, thatBlock, position); | |
199 | 204 | } |
200 | 205 | |
201 | 206 | if (madeAdjustment) DamageItem(ServerApi.World, byEntity, slot); |
@@ -354,6 +359,22 @@ namespace AdjustorMod | ||
354 | 359 | return false; |
355 | 360 | } |
356 | 361 | |
362 | + private bool RotatableByAngledMeshEntity(Block thatBlock, BlockPos pos) | |
363 | + { | |
364 | + //Coulda: (IAngledMeshBlockEnt >>> public virtual float MeshAngle ) ---but Nooooo.... | |
365 | + //Annnd the 1st thing is to try for the BlockEntity... | |
366 | + var mabeyBE = Api.World.BlockAccessor.GetBlockEntity(pos.Copy( )); | |
367 | + if (mabeyBE != null) | |
368 | + { | |
369 | + var someType = mabeyBE.GetType( ); | |
370 | + if (someType.GetProperty(_meshAngleKey) != null) return true; | |
371 | + if (someType.GetField(_meshAngleKey) != null) return true; | |
372 | + } | |
373 | + | |
374 | + | |
375 | + return false; | |
376 | + } | |
377 | + | |
357 | 378 | /// <summary> |
358 | 379 | /// Determines if slab, sheet, plate type block in a N/E/W/S configuration |
359 | 380 | /// </summary> |
@@ -637,6 +658,30 @@ namespace AdjustorMod | ||
637 | 658 | return false; |
638 | 659 | } |
639 | 660 | |
661 | + /// <summary> | |
662 | + /// rotation by/to MESH - not block! | |
663 | + /// </summary> | |
664 | + /// <returns>The rotation.</returns> | |
665 | + /// <param name="rotationModes">Rotation modes.</param> | |
666 | + /// <param name="thePlayer">The player.</param> | |
667 | + /// <param name="thatBlock">That block.</param> | |
668 | + /// <param name="position">Position.</param> | |
669 | + private bool MeshRotation(RotationModes rotationModes, IPlayer thePlayer, Block thatBlock, BlockPos position) | |
670 | + {//Context: SERVER! | |
671 | + bool rotateClockwise = rotationModes != RotationModes.West; | |
672 | + | |
673 | + dynamic subjectBE = ServerApi.World.BlockAccessor.GetBlockEntity(position); | |
674 | + | |
675 | + if (rotateClockwise) | |
676 | + { subjectBE.MeshAngle += 45; } | |
677 | + else | |
678 | + { subjectBE.MeshAngle -= 45; } | |
679 | + | |
680 | + subjectBE.MarkDirty(true); | |
681 | + | |
682 | + return false; | |
683 | + } | |
684 | + | |
640 | 685 | private AssetLocation RenameBlockFace(Block thatBlock, RotationModes rotationMode) |
641 | 686 | { |
642 | 687 | string renamedLocationPath = null; |
@@ -1,12 +1,12 @@ | ||
1 | 1 | { |
2 | 2 | ingredient: { type: "item", code: "game:ingot-*", name: "metal", allowedVariants: ["copper", "tinbronze", "bismuthbronze", "blackbronze", "iron"] }, |
3 | - pattern: [ | |
3 | + pattern: [[ | |
4 | 4 | "_####______#____", |
5 | 5 | "_#__#______##___", |
6 | 6 | "____############", |
7 | 7 | "_#__#______##___", |
8 | 8 | "_####______#____", |
9 | - ], | |
9 | + ]], | |
10 | 10 | name: "Adjustor", |
11 | 11 | output: { type: "item", code: "adjustmenttool-{metal}" } |
12 | 12 | } |
\ No newline at end of file |
@@ -1,12 +1,12 @@ | ||
1 | 1 | { |
2 | 2 | "type": "code", |
3 | 3 | "name": "Adjustment Tool", |
4 | - "description" : "Alter, Rotate blocks without breaking them. Now with Economy tool!", | |
4 | + "description" : "Reposition and Rotate blocks without breaking them. (Even chutes)", | |
5 | 5 | "authors": ["Melchior" ], |
6 | 6 | "contributors": ["bunnyviking"], |
7 | - "version": "0.1.10", | |
7 | + "version": "0.1.11", | |
8 | 8 | "dependencies": { |
9 | - "game": "1.12.0", | |
9 | + "game": "1.14.0", | |
10 | 10 | "survival": "" |
11 | 11 | }, |
12 | 12 | "website": "http://nowebsite.nope" |