Adjustor mod plugin for VS
修订版 | 75ca75c4e259bc1467deb686d287e2fc25ec2d97 (tree) |
---|---|
时间 | 2021-01-28 13:53:21 |
作者 | melchior <melchior@user...> |
Commiter | melchior |
W.I.P. chute fixes
@@ -65,6 +65,7 @@ | ||
65 | 65 | <Compile Include="Items\ItemAdjustor.cs" /> |
66 | 66 | <Compile Include="Skills\AdjustorSkills.cs" /> |
67 | 67 | <Compile Include="Skills\RotationModes.cs" /> |
68 | + <Compile Include="Helpers.cs" /> | |
68 | 69 | </ItemGroup> |
69 | 70 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
70 | 71 | <ItemGroup> |
@@ -33,7 +33,7 @@ namespace AdjustorMod | ||
33 | 33 | private const string _axialRotationKey = @"rotation";//Trees and Pillars; ns, we, ud - axial rotation |
34 | 34 | private const string _verticalCode = @"vertical"; |
35 | 35 | |
36 | - private const string _chuteCode = @"chute";//Just for "normal" Chutes... | |
36 | + | |
37 | 37 | private const string _chuteTypeStraight = @"straight"; |
38 | 38 | private const string _chuteTypeCross = @"cross"; |
39 | 39 | private const string _chuteTypeTjunction = @"t"; |
@@ -154,7 +154,7 @@ namespace AdjustorMod | ||
154 | 154 | Block thatBlock = byEntity.World.BlockAccessor.GetBlock(position); |
155 | 155 | var mode = CurrentRotationMode(itemslot); |
156 | 156 | |
157 | - if (RotatableByVariant(thatBlock) || RotatableByBehavior(thatBlock) || RotatableByAngledMeshEntity(thatBlock, position) || IsChute(thatBlock)) { | |
157 | + if (RotatableByVariant(thatBlock) || RotatableByBehavior(thatBlock) || RotatableByAngledMeshEntity(thatBlock, position) || thatBlock.IsChute( )) { | |
158 | 158 | #if DEBUG |
159 | 159 | Logger.VerboseDebug("[{0}] Looks Rotatable, FromFace: {1}", thatBlock.Code.Path, blockSel.Face.Code); |
160 | 160 | ClientApi.ShowChatMessage(string.Format("Appears Rotatable: {0}", thatBlock.Code)); |
@@ -821,10 +821,7 @@ namespace AdjustorMod | ||
821 | 821 | return false; |
822 | 822 | } |
823 | 823 | |
824 | - private bool IsChute(Block thatBlock) | |
825 | - { | |
826 | - return thatBlock.Code.BeginsWith(GlobalConstants.DefaultDomain, _chuteCode); | |
827 | - } | |
824 | + | |
828 | 825 | |
829 | 826 | |
830 | 827 |
@@ -873,7 +870,7 @@ namespace AdjustorMod | ||
873 | 870 | #endif |
874 | 871 | } |
875 | 872 | |
876 | - if (IsChute(thatBlock)) { | |
873 | + if (thatBlock.IsChute()) { | |
877 | 874 | renamedAsset = ChuteSpecificFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); |
878 | 875 | } |
879 | 876 |
@@ -885,6 +882,7 @@ namespace AdjustorMod | ||
885 | 882 | var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); |
886 | 883 | if (rotatedBlock != null) { |
887 | 884 | ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); |
885 | + ServerApi.TryUnborkChute(rotatedBlock, position); | |
888 | 886 | return true; |
889 | 887 | } else { |
890 | 888 | Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); |
@@ -913,7 +911,7 @@ namespace AdjustorMod | ||
913 | 911 | #endif |
914 | 912 | } |
915 | 913 | |
916 | - if (IsChute(thatBlock)) { | |
914 | + if (thatBlock.IsChute( )) { | |
917 | 915 | renamedAsset = ChuteSpecificFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); |
918 | 916 | } |
919 | 917 |
@@ -926,6 +924,7 @@ namespace AdjustorMod | ||
926 | 924 | var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); |
927 | 925 | if (rotatedBlock != null) { |
928 | 926 | ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); |
927 | + ServerApi.TryUnborkChute(rotatedBlock, position); | |
929 | 928 | return true; |
930 | 929 | } else { |
931 | 930 | Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); |
@@ -948,7 +947,7 @@ namespace AdjustorMod | ||
948 | 947 | private bool FixedRotation(RotationModes rotationMode, BlockSelection blockSel, EntityAgent byEntity, IPlayer thePlayer, Block thatBlock, BlockPos position) |
949 | 948 | { |
950 | 949 | AssetLocation renamedAsset; |
951 | - if (IsChute(thatBlock)) | |
950 | + if (thatBlock.IsChute( )) | |
952 | 951 | { renamedAsset = ChuteSpecificForce(thatBlock, rotationMode); } |
953 | 952 | else { renamedAsset = RenameBlockFace(thatBlock, rotationMode); } |
954 | 953 |
@@ -962,6 +961,7 @@ namespace AdjustorMod | ||
962 | 961 | var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); |
963 | 962 | if (rotatedBlock != null) { |
964 | 963 | ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); |
964 | + ServerApi.TryUnborkChute(rotatedBlock, position); | |
965 | 965 | return true; |
966 | 966 | } else { |
967 | 967 | Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); |
@@ -0,0 +1,60 @@ | ||
1 | +using System; | |
2 | + | |
3 | +using Vintagestory.API.Common; | |
4 | +using Vintagestory.API.Config; | |
5 | +using Vintagestory.API.MathTools; | |
6 | +using Vintagestory.API.Server; | |
7 | +using Vintagestory.GameContent; | |
8 | + | |
9 | +namespace AdjustorMod | |
10 | +{ | |
11 | + public static class Tamperers | |
12 | + { | |
13 | + private const string _chuteCode = @"chute";//Just for "normal" Chutes... | |
14 | + | |
15 | + public static bool TryUnborkChute(this ICoreServerAPI ServerAPI, Block thatBlock, BlockPos position) | |
16 | + { | |
17 | + if (thatBlock.IsChute( )) { | |
18 | + var entity = ServerAPI.World.BlockAccessor.GetBlockEntity(position) as BlockEntityItemFlow; | |
19 | + UnborkChute_ItemFlowStates(entity); | |
20 | + return true; | |
21 | + } | |
22 | + return false; | |
23 | + } | |
24 | + | |
25 | + private static void UnborkChute_ItemFlowStates( BlockEntityItemFlow itemFlowEntity) | |
26 | + { | |
27 | + if (itemFlowEntity == null) return; | |
28 | + | |
29 | + var theChute = itemFlowEntity.Block as BlockChute; | |
30 | + | |
31 | + if (theChute.Attributes != null) | |
32 | + { | |
33 | + if (theChute.Attributes["pullFaces"].Exists) { | |
34 | + string[ ] faces = theChute.Attributes["pullFaces"].AsArray<string>(null); | |
35 | + itemFlowEntity.PullFaces = new BlockFacing[faces.Length]; | |
36 | + for (int i = 0; i < faces.Length; i++) itemFlowEntity.PullFaces[i] = BlockFacing.FromCode(faces[i]); | |
37 | + } | |
38 | + | |
39 | + if (theChute.Attributes["pushFaces"].Exists) { | |
40 | + string[ ] faces = theChute.Attributes["pushFaces"].AsArray<string>(null); | |
41 | + itemFlowEntity.PushFaces = new BlockFacing[faces.Length]; | |
42 | + for (int i = 0; i < faces.Length; i++) itemFlowEntity.PushFaces[i] = BlockFacing.FromCode(faces[i]); | |
43 | + } | |
44 | + | |
45 | + if (theChute.Attributes["acceptFromFaces"].Exists) { | |
46 | + string[ ] faces = theChute.Attributes["acceptFromFaces"].AsArray<string>(null); | |
47 | + itemFlowEntity.AcceptFromFaces = new BlockFacing[faces.Length]; | |
48 | + for (int i = 0; i < faces.Length; i++) itemFlowEntity.AcceptFromFaces[i] = BlockFacing.FromCode(faces[i]); | |
49 | + } | |
50 | + } | |
51 | + | |
52 | + } | |
53 | + | |
54 | + public static bool IsChute(this Block thatBlock) | |
55 | + { | |
56 | + return thatBlock.Code.BeginsWith(GlobalConstants.DefaultDomain, _chuteCode); | |
57 | + } | |
58 | + } | |
59 | +} | |
60 | + |