triggers needed

Post Reply
User avatar
theFox
Member
Posts: 192
Joined: Sun Feb 12, 2017 14:08
GitHub: theFox6
In-game: theFox
Location: Germany

triggers needed

by theFox » Post

I would like to have some global triggers:
  • rightclickNode
  • pickupItem
but since I am not a core developer I don't know how to implement them...
Last edited by theFox on Fri Feb 23, 2018 10:34, edited 1 time in total.
my mods and subgames (ง'̀-'́)ง

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: triggers needed

by Linuxdirk » Post

theFox wrote:rightclickNode
This can be done by adding an on_rightclick function to the node in question.

http://dev.minetest.net/minetest.regist ... rightclick

User avatar
theFox
Member
Posts: 192
Joined: Sun Feb 12, 2017 14:08
GitHub: theFox6
In-game: theFox
Location: Germany

Re: triggers needed

by theFox » Post

Linuxdirk wrote:to the node in question
I meant global triggers (like register minetest.register_on_punchnode)
my mods and subgames (ง'̀-'́)ง

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: triggers needed

by Linuxdirk » Post

theFox wrote:
Linuxdirk wrote:to the node in question
I meant global triggers (like register minetest.register_on_punchnode)
When you use a tool for that action you can register it with an on_use function where you can do whatever you want. By just quick skipping to the API documentation I can't find such a register.

What is your use case? Maybe there is a workaround or other/better/different solution.

User avatar
Lejo
Member
Posts: 718
Joined: Mon Oct 19, 2015 16:32
GitHub: Lejo1
In-game: Lejo

Re: triggers needed

by Lejo » Post


User avatar
TechNolaByte
Member
Posts: 465
Joined: Wed May 10, 2017 21:00
GitHub: TechNolaByte

Re: triggers needed

by TechNolaByte » Post

If these features would be implemented it would greatly improve the quest line for my soon to be released skyfactory subgame
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.

User avatar
theFox
Member
Posts: 192
Joined: Sun Feb 12, 2017 14:08
GitHub: theFox6
In-game: theFox
Location: Germany

Re: triggers needed

by theFox » Post

Linuxdirk wrote:What is your use case? Maybe there is a workaround or other/better/different solution.
I am only building a trigger api...
RSLRedstonier is requesting it from my mod, so he's the boss here.
my mods and subgames (ง'̀-'́)ง

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: triggers needed

by Linuxdirk » Post

You could register a tool that looks like and acts like the hand but with changes to the on_use function.

https://github.com/minetest/minetest/bl ... .txt#L2210

User avatar
theFox
Member
Posts: 192
Joined: Sun Feb 12, 2017 14:08
GitHub: theFox6
In-game: theFox
Location: Germany

Re: triggers needed

by theFox » Post

Linuxdirk wrote:You could register a tool that looks like and acts like the hand but with changes to the on_use function.

https://github.com/minetest/minetest/bl ... .txt#L2210
Naw, that won't be useful...
Lejo wrote:Have a look at this mod:https://github.com/Arcelmi/minetest-controls
I guess that leaves only the on_pickup problem.

It's for my journal mod btw.
my mods and subgames (ง'̀-'́)ง

User avatar
Lejo
Member
Posts: 718
Joined: Mon Oct 19, 2015 16:32
GitHub: Lejo1
In-game: Lejo

Re: triggers needed

by Lejo » Post

theFox wrote: I guess that leaves only the on_pickup problem.
Why not use on_drop and minetest.handle_node_drops?
You could override all items with a trigger on drop.

User avatar
TechNolaByte
Member
Posts: 465
Joined: Wed May 10, 2017 21:00
GitHub: TechNolaByte

Re: triggers needed

by TechNolaByte » Post

theFox wrote: I guess that leaves only the on_pickup problem.
hmm i know that mineclone 2 uses a custome item drop mod which does have an on_pickup function
perhaps other item drop mods would have likewise?
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.

User avatar
theFox
Member
Posts: 192
Joined: Sun Feb 12, 2017 14:08
GitHub: theFox6
In-game: theFox
Location: Germany

Re: triggers needed

by theFox » Post

theFox wrote:
Lejo wrote:Have a look at this mod:https://github.com/Arcelmi/minetest-controls
I guess that leaves only the on_pickup problem.
Like this I can't get the target of the player's right click.
RSLRedstonier wrote:hmm i know that mineclone 2 uses a custome item drop mod which does have an on_pickup function
perhaps other item drop mods would have likewise?
The ones I use don't...
If you used your own version in your subgame, you can register a trigger there.
my mods and subgames (ง'̀-'́)ง

User avatar
Lejo
Member
Posts: 718
Joined: Mon Oct 19, 2015 16:32
GitHub: Lejo1
In-game: Lejo

Re: triggers needed

by Lejo » Post

theFox wrote: Like this I can't get the target of the player's right click.
Then just override all nodes with a trigger on_rightclick = func(pos, node, clicker, itemstack, pointed_thing).

User avatar
TechNolaByte
Member
Posts: 465
Joined: Wed May 10, 2017 21:00
GitHub: TechNolaByte

Re: triggers needed

by TechNolaByte » Post

Lejo wrote:
theFox wrote: Like this I can't get the target of the player's right click.
Then just override all nodes with a trigger on_rightclick = func(pos, node, clicker, itemstack, pointed_thing).
but what if they already have their own on_rightclick function?
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.

User avatar
Lejo
Member
Posts: 718
Joined: Mon Oct 19, 2015 16:32
GitHub: Lejo1
In-game: Lejo

Re: triggers needed

by Lejo » Post

RSLRedstonier wrote:
Lejo wrote:
theFox wrote: Like this I can't get the target of the player's right click.
Then just override all nodes with a trigger on_rightclick = func(pos, node, clicker, itemstack, pointed_thing).
but what if they already have their own on_rightclick function?
I have done the same with on_drop it works with a trick.
You have to store their own on_rightclick in a extra value.

User avatar
Lejo
Member
Posts: 718
Joined: Mon Oct 19, 2015 16:32
GitHub: Lejo1
In-game: Lejo

Re: triggers needed

by Lejo » Post

Here is the register code for it, just put it to your code.

Code: Select all

minetest.registered_on_rightclick = {}
function minetest.register_on_rightclick(func)
  table.insert(minetest.registered_on_rightclick, func)
end
local rightclickfuncs = {}

function minetest.handle_rightclick(pos, node, clicker, itemstack, pointed_thing)
  if clicker and clicker:is_player() then
    local name = clicker:get_player_name()
    if rightclickfuncs[node.name] then
      return rightclickfuncs[node.name](pos, node, clicker, itemstack, pointed_thing)
    end
    local todo
    for _,value in pairs(minetest.registered_on_rightclick) do
      local result = value(pos, node, clicker, itemstack, pointed_thing)
      if result then
        todo = result
      end
    end
    return todo
  end
end

minetest.after(3, function()
  for name, def in pairs(minetest.registered_items) do
    if def.on_rightclick then
      rightclickfuncs[name] = def.on_rightclick
    end
    minetest.override_item(name, {on_rightclick=minetest.handle_rightclick})
  end
end)
It should work with
minetest.register_on_rightclick(function(pos, node, clicker, itemstack, pointed_thing)
-- Your Code
end)

User avatar
theFox
Member
Posts: 192
Joined: Sun Feb 12, 2017 14:08
GitHub: theFox6
In-game: theFox
Location: Germany

Re: triggers needed

by theFox » Post

And if you want to use it together with my journal...
Look into the api.md and lower part of triggers.lua there you can learn how to register new triggers for the journal mod.
my mods and subgames (ง'̀-'́)ง

User avatar
Lejo
Member
Posts: 718
Joined: Mon Oct 19, 2015 16:32
GitHub: Lejo1
In-game: Lejo

Re: triggers needed

by Lejo » Post

theFox wrote:And if you want to use it together with my journal...
Look into the api.md and lower part of triggers.lua there you can learn how to register new triggers for the journal mod.
Do it like so:

Code: Select all

triggers.register_trigger("rightclick")
local rightclickfuncs = {}

function triggers.handle_rightclick(pos, node, clicker, itemstack, pointed_thing)
  if clicker and clicker:is_player() then
    local name = clicker:get_player_name()
    if rightclickfuncs[node.name] then
      rightclickfuncs[node.name](pos, node, clicker, itemstack, pointed_thing)
    end
    local data ={
     target = node.name,
     playerName = name,
     tool = clicker:get_wielded_item():get_name(),
    }
    triggers.run_callbacks("rightclick", data)
  end
end

minetest.after(3, function()
  for name, def in pairs(minetest.registered_items) do
    if def.on_rightclick then
      rightclickfuncs[name] = def.on_rightclick
    end
    minetest.override_item(name, {on_rightclick=triggers.handle_rightclick})
  end
end)
It should work :)
But not tested.

User avatar
TechNolaByte
Member
Posts: 465
Joined: Wed May 10, 2017 21:00
GitHub: TechNolaByte

Re: triggers needed

by TechNolaByte » Post

ty!
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.

User avatar
Lejo
Member
Posts: 718
Joined: Mon Oct 19, 2015 16:32
GitHub: Lejo1
In-game: Lejo

Re: triggers needed

by Lejo » Post

np

User avatar
theFox
Member
Posts: 192
Joined: Sun Feb 12, 2017 14:08
GitHub: theFox6
In-game: theFox
Location: Germany

Re: triggers needed

by theFox » Post

Edit: never mind, didn't read the code quite right.
Last edited by theFox on Sun Feb 25, 2018 20:05, edited 1 time in total.
my mods and subgames (ง'̀-'́)ง

User avatar
Lejo
Member
Posts: 718
Joined: Mon Oct 19, 2015 16:32
GitHub: Lejo1
In-game: Lejo

Re: triggers needed

by Lejo » Post

theFox wrote:You can cut out the rightclickfuncs stuff, it's not needed here...
The rightclickfuncs is important it does that, if a block has a function on_rightclick that this function is not ignored.

User avatar
theFox
Member
Posts: 192
Joined: Sun Feb 12, 2017 14:08
GitHub: theFox6
In-game: theFox
Location: Germany

Re: triggers needed

by theFox » Post

The triggers are now avalible in the extra_triggers mod inside the journal modpack!
my mods and subgames (ง'̀-'́)ง

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests