Veilheim/Blueprints/BlueprintManager.cs
/// <summary>
///     Incept placing of the meta pieces.
///     Cancels the real placement of the placeholder pieces.
/// </summary>
Incept placing of the meta pieces.
Cancels the real placement of the placeholder pieces.
Incept placing of the meta pieces . Cancels the real placement of the placeholder pieces .
private bool BeforePlaceBlueprintPiece(On.Player.orig_PlacePiece orig, Player self, Piece piece)
        {
            if (!ZNet.instance.IsServerInstance())
            {
                if (piece.name == "make_blueprint")
                {
                    var circleProjector = self.m_placementGhost.GetComponent<CircleProjector>();
                    if (circleProjector != null)
                    {
                        Destroy(circleProjector);
                    }
                    var bpname = $"blueprint{Instance.m_blueprints.Count() + 1:000}";
                    Jotunn.Logger.LogInfo($"Capturing blueprint {bpname}");
                    if (Player.m_localPlayer.m_hoveringPiece != null)
                    {
                        var bp = new Blueprint(bpname);
                        if (bp.Capture(Player.m_localPlayer.m_hoveringPiece.transform.position, Instance.selectionRadius, 1.0f))
                        {
                            TextInput.instance.m_queuedSign = new Blueprint.BlueprintSaveGUI(bp);
                            TextInput.instance.Show($"Save Blueprint ({bp.GetPieceCount()} pieces captured)", bpname, 50);
                        }
                        else
                        {
                            Jotunn.Logger.LogWarning($"Could not capture blueprint {bpname}");
                        }
                    }
                    else
                    {
                        Jotunn.Logger.LogInfo("Not hovering any piece");
                    }
                    Instance.cameraOffsetMake = 0f;
                    return false;
                }
                if (Player.m_localPlayer.m_placementStatus == Player.PlacementStatus.Valid && piece.name.StartsWith("piece_blueprint"))
                {
                    Blueprint bp = Instance.m_blueprints[piece.m_name];
                    var transform = self.m_placementGhost.transform;
                    var position = self.m_placementGhost.transform.position;
                    var rotation = self.m_placementGhost.transform.rotation;
                    if (ZInput.GetButton("Crouch") && !ConfigUtil.Get<bool>("Blueprints", "allowPlacementWithoutMaterial"))
                    {
                        MessageHud.instance.ShowMessage(MessageHud.MessageType.Center, "$plan_direct_build_disable");
                        return false;
                    }
                    if (ZInput.GetButton("AltPlace"))
                    {
                        Vector2 extent = bp.GetExtent();
                        FlattenTerrain.FlattenForBlueprint(transform, extent.x, extent.y, bp.m_pieceEntries);
                    }
                    uint cntEffects = 0u;
                    uint maxEffects = 10u;
                    foreach (var entry in bp.m_pieceEntries)
                    {
                        Vector3 entryPosition = position + transform.forward * entry.posZ + transform.right * entry.posX + new Vector3(0, entry.posY, 0);
                        Quaternion entryQuat = new Quaternion(entry.rotX, entry.rotY, entry.rotZ, entry.rotW);
                        entryQuat.eulerAngles += rotation.eulerAngles;
                        string prefabName = entry.name;
                        if (!ConfigUtil.Get<bool>("Blueprints", "allowPlacementWithoutMaterial") || !ZInput.GetButton("Crouch"))
                        {
                            prefabName += "_planned";
                        }
                        GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName);
                        if (!prefab)
                        {
                            Jotunn.Logger.LogError(entry.name + " not found?");
                            continue;
                        }
                        GameObject gameObject = Instantiate(prefab, entryPosition, entryQuat);
                        CraftingStation craftingStation = gameObject.GetComponentInChildren<CraftingStation>();
                        if (craftingStation)
                        {
                            self.AddKnownStation(craftingStation);
                        }
                        Piece newpiece = gameObject.GetComponent<Piece>();
                        if (newpiece != null)
                        {
                            newpiece.SetCreator(self.GetPlayerID());
                        }
                        PrivateArea privateArea = gameObject.GetComponent<PrivateArea>();
                        if (privateArea != null)
                        {
                            privateArea.Setup(Game.instance.GetPlayerProfile().GetName());
                        }
                        WearNTear wearntear = gameObject.GetComponent<WearNTear>();
                        if (wearntear != null)
                        {
                            wearntear.OnPlaced();
                        }
                        TextReceiver textReceiver = gameObject.GetComponent<TextReceiver>();
                        if (textReceiver != null)
                        {
                            textReceiver.SetText(entry.additionalInfo);
                        }
                        if (cntEffects < maxEffects)
                        {
                            newpiece.m_placeEffect.Create(gameObject.transform.position, rotation, gameObject.transform, 1f);
                            self.AddNoise(50f);
                            cntEffects++;
                        }
                        Game.instance.GetPlayerProfile().m_playerStats.m_builds++;
                    }
                    Instance.cameraOffsetPlace = 5f;
                    return false;
                }
            }
            return orig(self, piece);
        }
private bool BeforePlaceBlueprintPiece ( On . Player . orig_PlacePiece orig , Player self , Piece piece ) { if ( ! ZNet . instance . IsServerInstance ( ) ) { if ( piece . name == " " ) { var circleProjector = self . m_placementGhost . GetComponent < CircleProjector > ( ) ; if ( circleProjector != null ) { Destroy ( circleProjector ) ; } var bpname = $" blueprint { Instance . m_blueprints . Count ( ) + 1 : } " ; Jotunn . Logger . LogInfo ( $" Capturing blueprint  { bpname } " ) ; if ( Player . m_localPlayer . m_hoveringPiece != null ) { var bp = new Blueprint ( bpname ) ; if ( bp . Capture ( Player . m_localPlayer . m_hoveringPiece . transform . position , Instance . selectionRadius , 1.0f ) ) { TextInput . instance . m_queuedSign = new Blueprint . BlueprintSaveGUI ( bp ) ; TextInput . instance . Show ( $" Save Blueprint ( { bp . GetPieceCount ( ) }  pieces captured) " , bpname , 50 ) ; } else { Jotunn . Logger . LogWarning ( $" Could not capture blueprint  { bpname } " ) ; } } else { Jotunn . Logger . LogInfo ( " " ) ; } Instance . cameraOffsetMake = 0f ; return false ; } if ( Player . m_localPlayer . m_placementStatus == Player . PlacementStatus . Valid && piece . name . StartsWith ( " " ) ) { Blueprint bp = Instance . m_blueprints [ piece . m_name ] ; var transform = self . m_placementGhost . transform ; var position = self . m_placementGhost . transform . position ; var rotation = self . m_placementGhost . transform . rotation ; if ( ZInput . GetButton ( " " ) && ! ConfigUtil . Get < bool > ( " " , " " ) ) { MessageHud . instance . ShowMessage ( MessageHud . MessageType . Center , " " ) ; return false ; } if ( ZInput . GetButton ( " " ) ) { Vector2 extent = bp . GetExtent ( ) ; FlattenTerrain . FlattenForBlueprint ( transform , extent . x , extent . y , bp . m_pieceEntries ) ; } uint cntEffects = 0u ; uint maxEffects = 10u ; foreach ( var entry in bp . m_pieceEntries ) { Vector3 entryPosition = position + transform . forward * entry . posZ + transform . right * entry . posX + new Vector3 ( 0 , entry . posY , 0 ) ; Quaternion entryQuat = new Quaternion ( entry . rotX , entry . rotY , entry . rotZ , entry . rotW ) ; entryQuat . eulerAngles += rotation . eulerAngles ; string prefabName = entry . name ; if ( ! ConfigUtil . Get < bool > ( " " , " " ) || ! ZInput . GetButton ( " " ) ) { prefabName += " " ; } GameObject prefab = PrefabManager . Instance . GetPrefab ( prefabName ) ; if ( ! prefab ) { Jotunn . Logger . LogError ( entry . name + " " ) ; continue ; } GameObject gameObject = Instantiate ( prefab , entryPosition , entryQuat ) ; CraftingStation craftingStation = gameObject . GetComponentInChildren < CraftingStation > ( ) ; if ( craftingStation ) { self . AddKnownStation ( craftingStation ) ; } Piece newpiece = gameObject . GetComponent < Piece > ( ) ; if ( newpiece != null ) { newpiece . SetCreator ( self . GetPlayerID ( ) ) ; } PrivateArea privateArea = gameObject . GetComponent < PrivateArea > ( ) ; if ( privateArea != null ) { privateArea . Setup ( Game . instance . GetPlayerProfile ( ) . GetName ( ) ) ; } WearNTear wearntear = gameObject . GetComponent < WearNTear > ( ) ; if ( wearntear != null ) { wearntear . OnPlaced ( ) ; } TextReceiver textReceiver = gameObject . GetComponent < TextReceiver > ( ) ; if ( textReceiver != null ) { textReceiver . SetText ( entry . additionalInfo ) ; } if ( cntEffects < maxEffects ) { newpiece . m_placeEffect . Create ( gameObject . transform . position , rotation , gameObject . transform , 1f ) ; self . AddNoise ( 50f ) ; cntEffects ++ ; } Game . instance . GetPlayerProfile ( ) . m_playerStats . m_builds ++ ; } Instance . cameraOffsetPlace = 5f ; return false ; } } return orig ( self , piece ) ; }
Incept placing of the meta pieces.
Incept placing of the meta pieces .
// Client only // Capture a new blueprint // Reset Camera offset // Don't place the piece and clutter the world with it // Place a known blueprint // Final position // Final rotation // Get the prefab of the piece or the plan piece // Instantiate a new object with the new prefab // Register special effects // Limited build effects // Count up player builds // Reset Camera offset // Dont set the blueprint piece and clutter the world with it
orig
On.Player.orig_PlacePiece
self
Player
piece
Piece