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

tools and better fake_player emulation in general #50

Open
lmaddox opened this issue Dec 3, 2023 · 3 comments
Open

tools and better fake_player emulation in general #50

lmaddox opened this issue Dec 3, 2023 · 3 comments

Comments

@lmaddox
Copy link

lmaddox commented Dec 3, 2023

I've added some PoCs (gardener and wizard) who use items as the player would. I want to extend this feature so that other bots (woodcutter, miner, landscaper, and snow clearer) use their wield items to :dig(). Since tool use will be cross-cutting, affecting multiple AIs, the logic should probably go in async_functions.lua, and should handle cycling worn items before breakage (see #24)

Screenshot_2023-12-02_19_54_19

Better fake_player emulation should make it easier and more seamless/transparent to integrate with various tools, appliances, etc., as well as laying the groundwork for us to support hb mods like mana, hunger, a pooper redo, etc. We may be able to get hbhunger poison effects automatically if we can fix :is_player()

@lmaddox lmaddox changed the title tools tools and better fake_player emulation in general Dec 6, 2023
@theFox6
Copy link
Owner

theFox6 commented Dec 9, 2023

This is quite ambitious and I like the sentiment, the difficult part here is probably that minetest as well as other mods do sometimes not support lua-entities as easily.
A lot of integration and compatibility will have to be created on this mods side, but I think it is important to not interfere too much with other mods code and some issues may have to be solved on the mods side that we want to integrate with.

@lmaddox
Copy link
Author

lmaddox commented Dec 11, 2023

A 100% solution won't be possible, but I think we're already supporting common APIs such as hopper, etc. A lot of appliances and tools are already usable. I forget which mod I was having trouble integrating with--probably one the the hb mods or calling on_use in my composter bot. The particular problem I'm having is that pointed_thing.ref:is_player() is returning false.

The big TODO remaining for this ticket is going to be hb support. mana, for example, creates a data structure on_joinplayer, etc., and this function is not exposed via its API. This will probably have to be simulated on the creation of the villager.

lmaddox added a commit to InnovAnon-Inc/working_villages that referenced this issue Dec 11, 2023
@lmaddox
Copy link
Author

lmaddox commented Jan 14, 2024

This can be closed, at least for my branch. The remaining TODO is a separate issue that I'll be addressing in tandem with the central village registry.

function working_villages.use_item(self, stack, target)
        -- invokes the argument stack's on_use()
        -- return Tuple[whether successful, new stack]
        assert(self   ~= nil)
        assert(stack  ~= nil)
        assert(target ~= nil)

        local def = stack:get_definition()
        if def == nil then return false, nil end

        local on_use = def.on_use
        if on_use == nil then return false, nil end

        local user          = self
        local pointed_thing = {under=target, above=target, type="node",}
        local new_stack     = on_use(stack, user, pointed_thing)

        -- TODO register position failure ?
        
        for _=0,10 do coroutine.yield() end --wait 10 steps
        return true, new_stack
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants