From b25477b3151bce34dfa66607843c14862cabbf90 Mon Sep 17 00:00:00 2001 From: LNJplus Date: Thu, 29 Oct 2015 19:42:55 +0100 Subject: [PATCH] Added Fence API and fences in all wood types --- game_api.txt | 26 ++++++++++++++- mods/default/nodes.lua | 2 +- mods/default/nodes/fence.lua | 18 ----------- mods/default/nodes/fences.lua | 61 +++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 20 deletions(-) delete mode 100644 mods/default/nodes/fence.lua create mode 100644 mods/default/nodes/fences.lua diff --git a/game_api.txt b/game_api.txt index 3f447e1..a1042c0 100644 --- a/game_api.txt +++ b/game_api.txt @@ -230,7 +230,7 @@ stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, Xpanes API ---------- -Creates panes that automatically connect to each other +Creates panes that automatically connect to each other. xpanes.register_pane(subname, def) -> subname: used for nodename. Result: "xpanes:subname" and "xpanes:subname_{2..15}" @@ -249,6 +249,30 @@ xpanes.register_pane(subname, def) ^ Recipe field only } +Fence API +--------- +Creates fences of given material. + +default.register_fence(itemstring, def) + -> itemstring: used for nodename and crafting recipes. + -> def: See [#Fence deinition] + +#Fence definition +----------------- +{ + description = "Wooden Fence", + ^ The name / description of the fence + texture = "default_wood.png", + ^ The texture for the node. It is used to create the inventory texture too. + material = "default:wood", + ^ The material which you need to craft the fence. + groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, fuel = 4}, + ^ The groups of the fence. If it isn't defined it equals {choppy = 2, + oddly_breakable_by_hand = 2, flammable = 2, fuel = 4}. + sounds = default.node_sound_wood_defaults() + ^ The sounds of the fence. If it isn't defined it equals default.node_sound_wood_defaults(). +} + Raillike definitions -------------------- The following nodes use the group `connect_to_raillike` and will only connect to diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 54d0e87..c62b468 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -49,7 +49,7 @@ dofile(modpath .. "/nodes/food.lua") dofile(modpath .. "/nodes/latter.lua") dofile(modpath .. "/nodes/rails.lua") dofile(modpath .. "/nodes/signs.lua") -dofile(modpath .. "/nodes/fence.lua") +dofile(modpath .. "/nodes/fences.lua") dofile(modpath .. "/nodes/nyancat.lua") diff --git a/mods/default/nodes/fence.lua b/mods/default/nodes/fence.lua deleted file mode 100644 index e1aa135..0000000 --- a/mods/default/nodes/fence.lua +++ /dev/null @@ -1,18 +0,0 @@ -local fence_texture = - "default_fence_overlay.png^default_wood.png^default_fence_overlay.png^[makealpha:255,126,126" -minetest.register_node("default:fence_wood", { - description = "Wooden Fence", - drawtype = "fencelike", - tiles = {"default_wood.png"}, - inventory_image = fence_texture, - wield_image = fence_texture, - paramtype = "light", - sunlight_propagates = true, - is_ground_content = false, - selection_box = { - type = "fixed", - fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, - }, - groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, fuel = 4}, - sounds = default.node_sound_wood_defaults(), -}) diff --git a/mods/default/nodes/fences.lua b/mods/default/nodes/fences.lua new file mode 100644 index 0000000..6a7a1cb --- /dev/null +++ b/mods/default/nodes/fences.lua @@ -0,0 +1,61 @@ +function default.register_fence(itemstring, def) + local fence_texture_1 = "default_fence_overlay.png^" + local fence_texture_2 = "^default_fence_overlay.png^[makealpha:255,126,126" + + if not def.groups then + def.groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, fuel = 4} + end + if not def.sounds then + def.sounds = default.node_sound_wood_defaults() + end + + minetest.register_node(itemstring, { + description = def.description, + drawtype = "fencelike", + tiles = {def.texture}, + inventory_image = fence_texture_1 .. def.texture .. fence_texture_2, + wield_image = fence_texture_1 .. def.texture .. fence_texture_2, + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + selection_box = { + type = "fixed", + fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, + }, + groups = def.groups, + sounds = def.sounds, + }) + + + minetest.register_craft({ + output = itemstring .. ' 4', + recipe = { + {'group:stick', def.material, 'group:stick'}, + {'group:stick', def.material, 'group:stick'}, + } + }) +end + +default.register_fence("default:fence_wood", { + description = "Wooden Fence", + texture = "default_wood.png", + material = "default:wood" +}) + +default.register_fence("default:fence_junglewood", { + description = "Junglewood Fence", + texture = "default_junglewood.png", + material = "default:junglewood" +}) + +default.register_fence("default:fence_pinewood", { + description = "Pine Wood Fence", + texture = "default_pine_wood.png", + material = "default:pinewood" +}) + +default.register_fence("default:fence_acaciawood", { + description = "Acacia Wood Fence", + texture = "default_acacia_wood.png", + material = "default:acacia_wood" +})