Page 1 of 1

well, i don't know what to call it, but i have a question about it!

PostPosted: Sat Oct 19, 2013 02:24
by leetelate
In my veggies mod you eat stuff and that goes to the food, food hud, etc, but when i eat an apple it doesn't go to the food hud because in the default/nodes it is on_use item_eat.

I need to make it do my on_use function, not the one in the default.

Is there an, um, i don't know what to call it...extensibility?...for the apple definition in default/nodes?

Like can i just redefine the apple with veggies:apple (i tried 'default:apple' and the loader freaked) and will it over-lay the default one?

Thanks,
leetelate

veggies mod download is http://1337318.zymichost.com/veggies.tar.gz

"Minetest is the smarter brother of Minecraft"


edit: nope, veggie:apple redefinition doesn't work - can i mess with the registered node definitions (muhwahhahahaha)?


AHA!!! Oh Minetest, you just make my heart flutter!!! https://github.com/Uberi/MineTest-API/wiki/registry - minetest is definitely the smarter brother of minecraft - people just play minecraft, minetest is indeed exstensible - time to fess with the apple nodedef and make it do my bidding! muhwahhahahaha!

yes! it works!!!
----apple on_use clone hack
local node = {}
for k,v in pairs(minetest.registered_nodes["default:apple"]) do node[k] = v end
node.on_use = function(itemstack, user, pointed_thing)
eatit(user,2)
itemstack:take_item(1)
return itemstack
end, --function
minetest.register_node(":default:apple", node)

SOLVED

PostPosted: Sat Oct 19, 2013 03:43
by LionsDen
Just so you know and others know, you can redefine a node. To do so, register the node like normal but for the name place a colon in front. For example to redefine the default apple, the node name you would use would be :default:apple and I know it works because of a small mod that I made to redefine stone, dirt, desert stone and the other two dirt types. Just remember to have the nodes mod name in the depends.txt or it wont work because it might load before the mod that you are redefining the node for does.

PostPosted: Sat Oct 19, 2013 16:45
by leetelate
AH! THANK YOU!!! - wait - will the loader let me put :default:apple in veggies: and not freak out? - i tried that last night with just default:apple and the loader puked saying it wasn't the right naming convention - and what about for mods that aren't loaded (off), well, that is what the depends is for i guess - ok i'll try it laters!!!! THANK YOU AGAIN - minetest people are so niceu!

PostPosted: Sat Oct 19, 2013 19:52
by kaeza
leetelate wrote:AH! THANK YOU!!! - wait - will the loader let me put :default:apple in veggies: and not freak out? - i tried that last night with just default:apple and the loader puked saying it wasn't the right naming convention - and what about for mods that aren't loaded (off), well, that is what the depends is for i guess - ok i'll try it laters!!!! THANK YOU AGAIN - minetest people are so niceu!

Yes you can by using ":default:apple" as the name.

When a node/item name starts with ":", this tells the engine to ignore the namespace checks and register the node/item anyway.

Edit: This code could help:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local function copytable(t)
  local t2 = { }
  for k, v in pairs(t) do
    if type(v) == "table" then
      t2[k] = copytable(v)
    else
      t2[k] = v
    end
  end
  return t2
end

local my_apple_def = copytable(minetest.registered_nodes["default:apple"])

my_apple_def.on_use = function(itemstack, user, pointed_thing)
  -- Handle other stuff here.
  user:set_hp(user:get_hp() + 4)
  itemstack:take_item(1)
  return itemstack
end

-- Note: Apples are nodes, not items!
minetest.register_node(":default:apple", my_apple_def)

PostPosted: Sun Oct 20, 2013 17:49
by leetelate
yay! the veggies mod now redefines using just the : - apples and coconuts and bread now all call eatit(player,points) and that handles the food hud and when that is full it goes to health!!! yay! and thanks again!!! ++++++++++++++

oh and if a mod isn't used (like the palms mod is off so no coconuts to redefine), a simple switch for it not being found in the table works great to skip that one!