Version 1.0.0
[minetest_cups.git] / init.lua
blobac2cfc6b5369f413e4a6490daae7a2a75d204325
1 local S = minetest.get_translator("cups")
2 local has_default = minetest.get_modpath("default") ~= nil
3 local has_moreores = minetest.get_modpath("moreores") ~= nil
4 local cups = {}
6 -- Nodeboxes
7 local cupnodebox = {
8 type = "fixed",
9 fixed = {
10 {-0.3,-0.5,-0.3,0.3,-0.4,0.3}, -- stand
11 {-0.1,-0.4,-0.1,0.1,0,0.1}, -- handle
12 {-0.3,0,-0.3,0.3,0.1,0.3}, -- cup (lower part)
13 -- the 4 sides of the upper part
14 {-0.2,0.1,-0.3,0.2,0.5,-0.2},
15 {-0.2,0.1,0.2,0.2,0.5,0.3},
16 {-0.3,0.1,-0.3,-0.2,0.5,0.3},
17 {0.2,0.1,-0.3,0.3,0.5,0.3},
21 local cupselbox = {
22 type = "fixed",
23 fixed = {
24 {-0.3,-0.5,-0.3,0.3,-0.4,0.3}, -- stand
25 {-0.1,-0.4,-0.1,0.1,0,0.1}, -- handle
26 {-0.3,0,-0.3,0.3,0.5,0.3}, -- upper part
30 -- API
31 cups.register_cup = function(subname, description, tiles, craftitem, craft_count, extra_groups, extra_sounds)
32 local groups = { dig_immediate=3, falling_node=1, }
33 if extra_groups then
34 for k,v in pairs(extra_groups) do
35 groups[k] = v
36 end
37 end
38 local sounds
39 if has_default then
40 if default.node_sound_metal_defaults then
41 sounds = default.node_sound_defaults({
42 footstep = { name = "default_metal_footstep", gain = 0.3 },
44 else
45 sounds = default.node_sound_defaults({
46 footstep = { name = "default_hard_footstep", gain = 0.3 },
48 end
49 end
50 if extra_sounds then
51 for k,v in pairs(extra_sounds) do
52 sounds[k] = v
53 end
54 end
55 local itemstring = "cups:cup_"..subname
56 minetest.register_node(itemstring, {
57 description = description,
58 _doc_items_longdesc = S("A decorative item which can be placed."),
59 tiles = tiles,
60 paramtype = "light",
61 drawtype = "nodebox",
62 node_box = cupnodebox,
63 is_ground_content = false,
64 selection_box = cupselbox,
65 groups = groups,
66 sounds = sounds,
69 if craftitem ~= nil then
70 if craft_count == nil then craft_count = 1 end
72 if has_default then
73 minetest.register_craft({
74 output = "cups:cup_"..subname.." "..craft_count,
75 recipe = {
76 {craftitem, "", craftitem},
77 {"", craftitem, ""},
78 {"", craftitem, ""},
81 end
82 end
83 end
85 -- Register cups
86 local sound_hard
87 if has_default then
88 sound_hard = default.node_sound_defaults({ footstep = { name = "default_hard_footstep", gain = 0.3 }})
89 end
90 cups.register_cup("bronze", S("Bronze Cup"), { "cups_bronze.png" }, "default:bronze_ingot", 2)
91 cups.register_cup("gold", S("Golden Cup"), { "cups_gold.png" }, "default:gold_ingot", 2)
92 cups.register_cup("diamond", S("Diamond Cup"), { "cups_diamond.png" }, "default:diamond", 1, nil, sound_hard)
93 if has_moreores then
94 cups.register_cup("silver", S("Silver Cup"), { "cups_silver.png" }, "moreores:silver_ingot", 2)
95 end
97 -- Legacy aliases
98 minetest.register_alias("mtg_plus:cup_bronze", "cups:cup_bronze")
99 minetest.register_alias("mtg_plus:cup_gold", "cups:cup_gold")
100 minetest.register_alias("mtg_plus:cup_diamond", "cups:cup_diamond")