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

leetelate
Member
 
Posts: 205
Joined: Thu Aug 29, 2013 18:07

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

by leetelate » Sat Oct 19, 2013 02:24

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
Last edited by leetelate on Sat Oct 19, 2013 02:52, edited 1 time in total.
MT IS MC'S SMARTER BROTHER
minetest 0.4.8 compiled from latest git on linux mint 15 with qjoypad and wired 360 controller
freeminer, pilztest, buildcraft and next are the idea factories
my minetest page is http://1337318.zymichost.com if zymic isn't down - meh, it is free...
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Sat Oct 19, 2013 03:43

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.
 

leetelate
Member
 
Posts: 205
Joined: Thu Aug 29, 2013 18:07

by leetelate » Sat Oct 19, 2013 16:45

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!
MT IS MC'S SMARTER BROTHER
minetest 0.4.8 compiled from latest git on linux mint 15 with qjoypad and wired 360 controller
freeminer, pilztest, buildcraft and next are the idea factories
my minetest page is http://1337318.zymichost.com if zymic isn't down - meh, it is free...
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Sat Oct 19, 2013 19:52

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)
Last edited by kaeza on Sat Oct 19, 2013 19:58, edited 1 time in total.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

leetelate
Member
 
Posts: 205
Joined: Thu Aug 29, 2013 18:07

by leetelate » Sun Oct 20, 2013 17:49

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!
Last edited by leetelate on Sun Oct 20, 2013 17:54, edited 1 time in total.
MT IS MC'S SMARTER BROTHER
minetest 0.4.8 compiled from latest git on linux mint 15 with qjoypad and wired 360 controller
freeminer, pilztest, buildcraft and next are the idea factories
my minetest page is http://1337318.zymichost.com if zymic isn't down - meh, it is free...
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 4 guests

cron