//Called ClientSide public void OnUseOver(IPlayer byPlayer, BlockSelection blockSel, bool mouseBreakMode) { Cuboidf[] boxes = Circuit.GetCurrentSelectionBoxes(); //If true, something is wrong with selection boxes or the board was selected. if (blockSel.SelectionBoxIndex >= boxes.Length) { return; } //From the hit position and the face we can infere a voxel position without using selection box index //It works but could be refined Vec3f rotation = SignalsUtils.FacingToRotation(this.orientation, this.facing); Vec3f hitPos = blockSel.HitPosition.ToVec3f().Mul(16); BlockFacing selectionFacing = blockSel.Face; //We translate using the normal to avoid rounding and precision issues Vec3f hitPos2 = hitPos.AddCopy(selectionFacing.Normalf.NormalizedCopy().Mul(-0.5f)); //We need to apply rotation now RotateFromBEtoCircuit(ref hitPos2, ref selectionFacing, new Vec3f(8, 8, 8)); Vec3i voxelPos = new Vec3i((int)Math.Floor(hitPos2.X), (int)Math.Floor(hitPos2.Y), (int)Math.Floor(hitPos2.Z)); Cuboidf box = boxes[blockSel.SelectionBoxIndex]; Vec3i voxelBoxPos = new Vec3i((int)Math.Floor(box.MinX * 16), (int)Math.Floor(box.MinY * 16), (int)Math.Floor(box.MinZ * 16)); OnUseOver(byPlayer, voxelPos, voxelBoxPos, selectionFacing, mouseBreakMode); }
internal Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos, ItemStack holdingItemStack = null) { ICoreClientAPI capi = Api as ICoreClientAPI; if (capi == null) { return(null); } VoxelCircuit.EnumCircuitSelectionType selType; Item heldItem = holdingItemStack?.Item; Vec3i compSize = SignalsUtils.GetCircuitComponentSizeFromItem(capi, heldItem); if (heldItem?.Code?.ToString() == "signals:el_wire") { selType = VoxelCircuit.EnumCircuitSelectionType.PlaceWire; } else if (compSize != null) { selType = VoxelCircuit.EnumCircuitSelectionType.PlaceComponent; } else { selType = VoxelCircuit.EnumCircuitSelectionType.PlaceNothing; } Cuboidf[] boxes = Circuit?.GetSelectionBoxes(compSize, selType); if (selType == VoxelCircuit.EnumCircuitSelectionType.PlaceNothing) { Array.Resize(ref boxes, boxes.Length + 1); boxes[boxes.Length - 1] = new Cuboidf(0, 0, 0, 1, 1f / 16, 1); } //----------- Cuboidf[] rotatedBoxes = new Cuboidf[boxes.Length]; Vec3f rotation = SignalsUtils.FacingToRotation(orientation, facing); for (int i = 0; i < boxes.Length; i++) { rotatedBoxes[i] = boxes[i].RotatedCopy(rotation.X, rotation.Y, rotation.Z, new Vec3d(0.5d, 0.5, 0.5)); } return(rotatedBoxes); }
private void RotateFromCircuittoBE(ref Vec3f vector, ref BlockFacing facing, Vec3f center) { Vec3f rotation = SignalsUtils.FacingToRotation(this.orientation, this.facing); if (vector != null) { SignalsUtils.RotateVector(ref vector, 0, 0, rotation.Z, center); SignalsUtils.RotateVector(ref vector, 0, rotation.Y, 0, center); SignalsUtils.RotateVector(ref vector, rotation.X, 0, 0, center); } if (facing != null) { facing = facing.FaceWhenRotatedBy(0, 0, rotation.Z * GameMath.DEG2RAD); facing = facing.FaceWhenRotatedBy(0, rotation.Y * GameMath.DEG2RAD, 0); facing = facing.FaceWhenRotatedBy(rotation.X * GameMath.DEG2RAD, 0, 0); } }