space-wizards / space-station-14

A multiplayer game about paranoia and chaos on a space station. Remake of the cult-classic Space Station 13.
https://spacestation14.io
MIT License
2.62k stars 3.27k forks source link

Eating stackable food doesn't leave multiple trash items #25332

Open Lukasz825700516 opened 7 months ago

Lukasz825700516 commented 7 months ago

Eating from bananium stack doesn't leave on the ground multiple nananium peels.

          Does this cause 10 bananium stack to leave 10 peels too?

Originally posted by @thebadman4662 in https://github.com/space-wizards/space-station-14/issues/25308#issuecomment-1949580337

thebadman4662 commented 7 months ago

Welp, ill take that as a no then...

You also eat whole bananium stack at once to delete it all rather 10 separately, I think pancakes work just fine though?

Lukasz825700516 commented 7 months ago

Eating pancakes works as they don't leave any leftovers. The issue is that when eating from stack we are executing this branch https://github.com/space-wizards/space-station-14/blob/74b5b72d81bde06052f61e9d7c42b5e45218f2e2/Content.Server/Nutrition/EntitySystems/FoodSystem.cs#L294 that is not creating any leftovers - leftovers are only created upon full item entity consumption https://github.com/space-wizards/space-station-14/blob/74b5b72d81bde06052f61e9d7c42b5e45218f2e2/Content.Server/Nutrition/EntitySystems/FoodSystem.cs#L311

rroig7 commented 7 months ago

Not sure if this is the right way to fix this but I essentially copied the DeleteAndSpawnTrash function and made it only spawn trash and not delete the stack. It will also place the trash in the user's empty hand if they have an available hand.

 public void SpawnTrash(FoodComponent component, EntityUid food, EntityUid user)
    {
        var ev = new BeforeFullyEatenEvent
        {
            User = user
        };
        RaiseLocalEvent(food, ev);
        if (ev.Cancelled)
            return;

        if (string.IsNullOrEmpty(component.Trash))
        {
            return;
        }

        // We've been eaten. Become trash.
        var position = Transform(food).MapPosition;
        var finisher = Spawn(component.Trash, position);

        // If the user is holding the stack and has an empty hand.
        if (_hands.IsHolding(user, food, out _) && _hands.TryGetEmptyHand(user, out var emptyHand))
        {
            // Put the trash in the user's empty hand.
            _hands.TryPickup(user, finisher, emptyHand);
        }
    }

Called this after the stack.count > 1 if statement and its working so far.