First Machine Age's Mods (Combined repo.)
Revisión | f1188402afc64dcd42bf22797be7bed544e5ec11 (tree) |
---|---|
Tiempo | 2021-05-28 10:51:22 |
Autor | melchior <melchior@user...> |
Commiter | melchior |
W.I.P., More Work II
@@ -32,6 +32,14 @@ namespace ConstructionSupport | ||
32 | 32 | |
33 | 33 | return false; |
34 | 34 | } |
35 | + | |
36 | + public static string DiagonalInitial(this BlockPos pos, BlockPos other) | |
37 | + { | |
38 | + //Subtract, to Normal; then 'Cardinals'... | |
39 | + var normal = pos.SubCopy(other); | |
40 | + var diagonal = Cardinal.FromNormali(normal.ToVec3i( )); | |
41 | + return diagonal?.Initial ?? "?"; | |
42 | + } | |
35 | 43 | } |
36 | 44 | } |
37 | 45 |
@@ -82,22 +82,27 @@ namespace ConstructionSupport | ||
82 | 82 | return false; |
83 | 83 | } |
84 | 84 | |
85 | - public bool CheckCornerSolid(IBlockAccessor world, BlockPos checkPos ) | |
85 | + public bool CheckCornerSolid(IBlockAccessor world, BlockPos checkPos, out BlockPos foundCorner ) | |
86 | 86 | { |
87 | 87 | //Visit all diagonal combinations |
88 | 88 | Stack<BlockPos> checkList = new Stack<BlockPos>( ); |
89 | 89 | |
90 | - checkList.Push(checkPos.Copy( ).Add( 1, 1, 0)); | |
91 | - checkList.Push(checkPos.Copy( ).Add( 1,-1, 0)); | |
92 | - checkList.Push(checkPos.Copy( ).Add(-1, 1, 0)); | |
93 | - checkList.Push(checkPos.Copy( ).Add(-1,-1, 0)); | |
90 | + checkList.Push(checkPos.Copy( ).Add( 1, 0, 1)); | |
91 | + checkList.Push(checkPos.Copy( ).Add( 1, 0,-1)); | |
92 | + checkList.Push(checkPos.Copy( ).Add(-1, 0, 1)); | |
93 | + checkList.Push(checkPos.Copy( ).Add(-1, 0,-1)); | |
94 | 94 | Block toCheck; |
95 | 95 | while (checkList.Count > 0 ) |
96 | 96 | { |
97 | - toCheck = world.GetBlock(checkList.Pop( )); | |
98 | - if (toCheck != null && toCheck.IsSolid()) return true; | |
99 | - } | |
100 | - | |
97 | + var here = checkList.Pop( ); | |
98 | + toCheck = world.GetBlock(here); | |
99 | + if (toCheck != null && toCheck.IsSolid( )) | |
100 | + { | |
101 | + foundCorner = here; | |
102 | + return true; | |
103 | + } | |
104 | + } | |
105 | + foundCorner = null; | |
101 | 106 | return false; |
102 | 107 | } |
103 | 108 |
@@ -32,21 +32,22 @@ namespace ConstructionSupport | ||
32 | 32 | |
33 | 33 | public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode) |
34 | 34 | { |
35 | - var placeSpot = blockSel.Position.AddCopy(blockSel.Face.Opposite, 1); | |
35 | + var placeSpot = blockSel.Position.AddCopy(blockSel.Face, 1); | |
36 | 36 | var lookSpot = blockSel.Position.Copy( ).Offset(blockSel.Face.Opposite); |
37 | 37 | var surfaceBlock = world.BlockAccessor.GetBlock(lookSpot); |
38 | + BlockPos cornerPos; | |
38 | 39 | |
39 | 40 | if (base.ValidAttachmentFaces.Contains(blockSel.Face)) { |
40 | 41 | |
41 | 42 | //of the 4 Corners - any 1 a solid block; AND attachment to deckwork on faces... |
42 | 43 | if (IsDeckwork(world.BlockAccessor, lookSpot) |
43 | - && CheckCornerSolid(world.BlockAccessor, placeSpot )) | |
44 | + && CheckCornerSolid(world.BlockAccessor, placeSpot, out cornerPos)) | |
44 | 45 | { |
46 | + | |
47 | + if (CanPlaceBlock(world, byPlayer, blockSel, ref failureCode)) { | |
45 | 48 | #if DEBUG |
46 | - api.World.Logger.VerboseDebug($"Success: {blockSel.Face} for {this.Code} onto {surfaceBlock.Code} @ {blockSel.Position}"); | |
49 | + api.World.Logger.VerboseDebug($"Valid: {blockSel.Face} for {this.Code} onto {surfaceBlock.Code} @ {blockSel.Position}"); | |
47 | 50 | #endif |
48 | - | |
49 | - if (CanPlaceBlock(world, byPlayer, blockSel, ref failureCode)) { | |
50 | 51 | return DoPlaceBlock(world, byPlayer, blockSel, itemstack); |
51 | 52 | } |
52 | 53 | } |
@@ -79,13 +80,27 @@ namespace ConstructionSupport | ||
79 | 80 | } |
80 | 81 | |
81 | 82 | if (preventDefault) return result; |
83 | + //Find Corner; | |
84 | + var lookSpot = blockSel.Position.Copy( ).Offset(blockSel.Face.Opposite); | |
85 | + var placeSpot = blockSel.Position.AddCopy(blockSel.Face, 1); | |
86 | + BlockPos cornerPos; | |
87 | + CheckCornerSolid(world.BlockAccessor, placeSpot, out cornerPos); | |
88 | + var realCornerInitial = placeSpot.DiagonalInitial(cornerPos); | |
89 | + | |
90 | + #if DEBUG | |
91 | + api.World.Logger.VerboseDebug($"Diagonal Changed: {realCornerInitial} for {this.Code}, Look: {lookSpot} ,Place: {placeSpot}, Corner: {cornerPos}"); | |
92 | + #endif | |
82 | 93 | |
83 | - var rotatedBlockId = RotateToFace(blockSel.Face.Opposite); | |
84 | - //Switcheroo! | |
85 | - world.BlockAccessor.SetBlock(rotatedBlockId.BlockId, blockSel.Position, byItemStack); | |
94 | + var blockAssetCode = this.CodeWithVariant(@"corner", realCornerInitial); | |
86 | 95 | |
96 | + var rotatedBlock = api.World.BlockAccessor.GetBlock(blockAssetCode); | |
97 | + if (rotatedBlock != null) | |
98 | + { | |
99 | + world.BlockAccessor.SetBlock(rotatedBlock.BlockId, placeSpot, byItemStack); | |
100 | + return true; | |
101 | + } | |
87 | 102 | |
88 | - return true; | |
103 | + return false; | |
89 | 104 | } |
90 | 105 | |
91 | 106 |
@@ -19,7 +19,7 @@ | ||
19 | 19 | drops: [{ code: "deckwork_corner-ne" }], |
20 | 20 | shapebytype: { |
21 | 21 | "*-ne": { base: "block/frames/deckwork_diag", rotateY: 0 }, |
22 | - "*-nw": { base: "block/frames/deckwork_diag", rotateY: 90 }, | |
22 | + "*-nw": { base: "block/frames/deckwork_diag", rotateY: -90 }, | |
23 | 23 | "*-se": { base: "block/frames/deckwork_diag", rotateY: 180 }, |
24 | 24 | "*-sw": { base: "block/frames/deckwork_diag", rotateY: 270 }, |
25 | 25 | }, |
@@ -15,15 +15,15 @@ | ||
15 | 15 | { |
16 | 16 | "name": "Deck", |
17 | 17 | "from": [ 0.0, 15.0, 0.0 ], |
18 | - "to": [ 16.0, 16.0, 14.0 ], | |
18 | + "to": [ 15.0, 16.0, 14.0 ], | |
19 | 19 | "rotationOrigin": [ 0.0, 4.0, 0.0 ], |
20 | 20 | "faces": { |
21 | - "north": { "texture": "#generic", "uv": [ 0.0, 5.0, 16.0, 6.0 ] }, | |
21 | + "north": { "texture": "#generic", "uv": [ 0.0, 5.0, 15.0, 6.0 ] }, | |
22 | 22 | "east": { "texture": "#generic", "uv": [ 0.0, 1.0, 1.0, 15.0 ], "rotation": 90 }, |
23 | - "south": { "texture": "#generic", "uv": [ 0.0, 4.0, 16.0, 5.0 ] }, | |
23 | + "south": { "texture": "#generic", "uv": [ 0.0, 4.0, 15.0, 5.0 ] }, | |
24 | 24 | "west": { "texture": "#generic", "uv": [ 0.0, 2.0, 1.0, 16.0 ], "rotation": 90 }, |
25 | - "up": { "texture": "#generic", "uv": [ 0.0, 1.0, 16.0, 15.0 ] }, | |
26 | - "down": { "texture": "#generic", "uv": [ 0.0, 1.0, 16.0, 15.0 ] } | |
25 | + "up": { "texture": "#generic", "uv": [ 0.0, 1.0, 15.0, 15.0 ] }, | |
26 | + "down": { "texture": "#generic", "uv": [ 0.0, 1.0, 15.0, 15.0 ] } | |
27 | 27 | }, |
28 | 28 | "children": [ |
29 | 29 | { |