Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify item metadata with swapItems hook #1593

Open
solareon opened this issue Jan 11, 2024 · 0 comments
Open

modify item metadata with swapItems hook #1593

solareon opened this issue Jan 11, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@solareon
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When utilizing swapItems hook you are unable to modify the item metadata. This prevents some interesting use cases such as modifying an items durability upon placing into a container or performing some other function such as drying materials.

Describe the solution you'd like
The ability to modify metadata as part of the swapItem hook. Currently you can only return true or false to permit/deny the swapItems action. Ideally this would be accomplished by appending a table of metadata to the end of the swapItems return and have this applied to the item once it arrives in the destination inventory.

Describe alternatives you've considered
Modifying the swapItems code directly to add functions for specific items but this is inflexible and error prone.

Additional context
One resource that modifies the swapItems function as part of the installation steps is rep-weed. The code they add into the function looks like below. If it was possible to modify the metadata via hook then this would no longer be required.

                if fromData.name == 'wetbud' then
                    if fromInventory.type == 'stash' then
                        if fromInventory.type == 'stash' then
                            if not fromData.metadata then
                                fromData.metadata = {}
                                fromData.metadata.time = os.time()
                                fromData.metadata.dry = 10
                            else
                                if not fromData.metadata.time then fromData.metadata.time = os.time() end
                                if not fromData.metadata.dry then fromData.metadata.dry = 10 end
                            end
                        end
                    end
                end
            end
            fromInventory.items[data.fromSlot] = fromData
            if toData then
                if toData.name == 'wetbud' then
                    if toInventory.type == 'stash' then
                        print('stash')
                        if not toData.metadata then
                            toData.metadata = {}
                            toData.metadata.time = os.time()
                            toData.metadata.dry = 10
                        else
                            if not toData.metadata.time then toData.metadata.time = os.time() end
                            if not toData.metadata.dry then toData.metadata.dry = 10 end
                        end
                    end
                end
            end
            toInventory.items[data.toSlot] = toData

Yes the above code is terrible and I didn't write it

@solareon solareon added the enhancement New feature or request label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant