private void SelectSimilarBlocksAround(BlockLogSection[] around, string rotation) { int f1 = BlockFacing.FromFirstLetter(rotation[0]).Index; int f2 = BlockFacing.FromFirstLetter(rotation[1]).Index; for (int i = 0; i < 6; i++) { BlockLogSection neib = around[i]; if (neib == null) { continue; } if (neib.LastCodePart() != rotation) { around[i] = null; continue; } if (i != f1 && i != f2) { if (!neib.IsBarkFace(i)) { around[i] = null; } } } }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode) { BlockLogSection[] around = new BlockLogSection[6]; string rotation = GetBlocksAround(around, world.BlockAccessor, blockSel.Position.Copy()); if (rotation == null || byPlayer?.Entity.Controls.Sneak == true) { switch (blockSel.Face.Axis) { case EnumAxis.X: rotation = "we"; break; case EnumAxis.Y: rotation = "ud"; break; case EnumAxis.Z: rotation = "ns"; break; } } SelectSimilarBlocksAround(around, rotation); int normal0 = 0; int normal1 = 1; int normal2 = 2; int normal3 = 3; int normal4 = 4; int normal5 = 5; if (rotation == "we") { normal0 = 4; normal1 = 0; normal2 = 5; normal3 = 2; normal4 = 3; normal5 = 1; } else if (rotation == "ns") { normal0 = 4; normal1 = 1; normal2 = 5; normal3 = 3; normal4 = 0; normal5 = 2; } string seg = null; if (around[normal0] != null && around[normal2] == null) { seg = "s" + BlockFacing.FromFirstLetter(around[normal0].LastCodePart(1)[1]).Code.ToLower()[0]; } if (around[normal2] != null && around[normal0] == null) { seg = "n" + BlockFacing.FromFirstLetter(around[normal2].LastCodePart(1)[1]).Code.ToLower()[0]; } if (around[normal1] != null && around[normal3] == null) { seg = BlockFacing.FromFirstLetter(around[normal1].LastCodePart(1)[0]).Code.ToLower()[0] + "w"; } if (around[normal3] != null && around[normal1] == null) { seg = BlockFacing.FromFirstLetter(around[normal3].LastCodePart(1)[0]).Code.ToLower()[0] + "e"; } if (seg == null) { seg = around[normal5]?.LastCodePart(1) ?? around[normal4]?.LastCodePart(1) ?? "ne"; } Block orientedBlock = world.BlockAccessor.GetBlock(CodeWithParts(seg, rotation)); if (orientedBlock == null) { orientedBlock = world.BlockAccessor.GetBlock(CodeWithParts(rotation)); } if (orientedBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode)) { orientedBlock.DoPlaceBlock(world, byPlayer, blockSel, itemstack); return(true); } return(false); }