Help with my Mod Code to place Furniture

Discussion in 'Mods' started by ImGuts, May 17, 2024.

  1. ImGuts

    ImGuts Space Hobo

    Hello Community,
    i did mod for Max Payne 2 in the past, but im new with Stardew Valley.
    i tought i might use ChatGPT to write me a quick code for the beginning :D
    but unfortunaly i run into some Errors, and i cant find a Documentation anywhere about all the Functions etc and how to use em.
    I wanted to make a small Mod that lets me place a Chair with a Keypress and then be able to recover Energy while sitting, and removing the Chair when i stand up afterwards.
    Maybe someone can guide me into the correct Direction on how to fix, and maybe find a good Documentation about all the Functions.

    Code:
    using System;
    using System.Collections.Generic;
    using StardewModdingAPI;
    using StardewModdingAPI.Events;
    using StardewValley;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using StardewValley.Objects;
    using Rectangle = Microsoft.Xna.Framework.Rectangle;
    namespace ChairMod
    {
        internal sealed class ModEntry : Mod
        {
            private bool chairPlaced = false;
            private Vector2 chairPosition;
            private Furniture chair;
    
            public override void Entry(IModHelper helper)
            {
                helper.Events.Input.ButtonPressed += OnButtonPressed;
                helper.Events.GameLoop.UpdateTicking += OnUpdateTicking;
                helper.Events.GameLoop.DayStarted += OnDayStarted;
            }
    
            private void OnButtonPressed(object? sender, ButtonPressedEventArgs e)
            {
                if (!Context.IsPlayerFree || Game1.activeClickableMenu != null) return;
    
                if (e.Button == SButton.C) // Ändere diese Taste nach Bedarf
                {
                    PlaceChair();
                }
            }
    
            private void PlaceChair()
            {
                if (!chairPlaced)
                {
                    chairPosition = Game1.player.getStandingPosition();
                    Vector2 vector2 = chairPosition * Game1.tileSize;
                    chair = new Furniture(Furniture.chair, 1467); // 1467 ist die ID des Stuhls (kannst du anpassen)
                    Game1.currentLocation.Objects.Add(chairPosition, chair);
                    chairPlaced = true;
                }
            }
    
            private void OnUpdateTicking(object? sender, UpdateTickingEventArgs e)
            {
                if (!Context.IsPlayerFree || Game1.activeClickableMenu != null) return;
    
                if (chairPlaced && Game1.player.GetBoundingBox().Intersects(new Rectangle((int)chairPosition.X, (int)chairPosition.Y, Game1.tileSize, Game1.tileSize)))
                {
                    Game1.player.Stamina = Math.Min(Game1.player.MaxStamina, Game1.player.Stamina + 5); // Ändere diesen Wert, um die Energieaufladerate anzupassen
                }
            }
    
            private void OnDayStarted(object? sender, DayStartedEventArgs e)
            {
                if (chairPlaced)
                {
                    Game1.currentLocation.Objects.Remove(chairPosition);
                    chairPlaced = false;
                }
            }
        }
    }
     

    Share This Page