minetest mod 初步学习

来源:互联网 发布:聚宝盆是什么软件 编辑:程序博客网 时间:2024/06/05 06:25


minetest mod 初步学习

MInetest一般有3种类型的对象

  • Node (minetest.register_node): A block from the world.
  • Tool (minetest.register_tool): A tool/weapon that can dig and damage things according to tool_capabilities.
  • Craftitem (minetest.register_craftitem): A miscellaneous item.



创建node


1.Minetest mods的文件夹中创建一个文件夹tutorial

2.tutorial文件夹中创建一个一个文件init.lua,写入如下


minetest.register_node("tutorial:decowood",{

tiles ={"tutorial_decowood.png"},

groups ={snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},

})


3.tutorial文件夹中创建textures文件夹,将tutorial_decowood.png放入textures中。


4.测试:按t进入聊天窗口

/giveme tutorial:decowood 99


加新的node

minetest.register_node(name,table)


注意事项:


1.上面加入的node没有加入到库存中,需要在table中加入如下属性,才能在库存中显示出来。


description = "decowood",


2.minetest.register_node这个API的第一个参数name是由固定格式的。

modname:itemname

modnamemod的文件夹名字,itemname可以是任意定义的名字。

3.纹理图片放在mod文件夹下的textures文件夹下。通常大小是16*16;支持JPEG格式,暂不支持透明图片。如这里的tutorial_decowood.png就直接放入到textures文件夹下。




重写node

item之前加一个:。譬如:default:dirt代表重写default mod中的default:dirt项。




Define an ABM

ABMs 给块加一些actions

init.lua中加入如下代码:

minetest.register_abm({

nodenames = {"tutorial:decowood"},

interval =30,

chance =1,

action =function(pos)

minetest.add_node(pos,{name="default:wood"})

end,

})




注册Craftitem

       Craftitem不能直接放置在世界中,在recipes中使用它创建其它items,或者可播放器也可以使用它。

minetest.register_craftitem("mymod:diamond_fragments", {

description = "Alien Diamond Fragments",

inventory_image = "mymod_diamond_fragments.png"

})

craftitem:合成槽中要放入的资源。



注册Crafting,定义一个合成表

minetest.register_craft({

output ="mymod:diamond_chair 99",

recipe = {

{"mymod:diamond_fragments","",""},

{"mymod:diamond_fragments","mymod:diamond_fragments",""},

{"mymod:diamond_fragments","mymod:diamond_fragments"""}

}

})


output:设置配方合成品的输出结果

recipe:合成槽里要放的资源,需要是同一种类型的。可以是register_node注册的node,也可以是register_craftitem注册的合成资源。

type:合成的类型,类型的不同需要的辅助资源不同,如:需要燃料等,也可以设置合成时间等 。



参考资料

http://dev.minetest.net/Intro

https://rubenwardy.com/minetest_modding_book/chapters/nodes_items_crafting.html