Skip to content

Commit 2f39cad

Browse files
sofarparamat
authored andcommittedFeb 3, 2016
Create API for fence.register, and use it.
This converts the call to minetest.register() for the default fence node, so it can be called by other mods to quickly setup other fences. Since this creates an API, insert it into the game_api.txt. The api looks like minetest.register(name, {def}), and has two uncommon fields: "texture" and "material". Any normal nodedef property can be passed through, except "drawtype". The "fence" group will always be added. The default fence recipe is modified to be as follows: wood, stick, wood wood, stick, wood This recipe yields 4 fence nodes. This allows us to create according recipes for acacia, pine, aspen, and junglewood fences without adding new stick types: pine wood, stick, pine wood pine wood, stick, pine wood This is a from-scratch implementation, written by heart but inspired by (#665 - Add many wooden fences). Stick and fences nodes are named in a consistent way.
1 parent a4e144e commit 2f39cad

File tree

4 files changed

+102
-24
lines changed

4 files changed

+102
-24
lines changed
 

‎game_api.txt

+18
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ doors.register_trapdoor(name, def)
110110
will be overwritten by the trapdoor registration function
111111
}
112112

113+
Fence API
114+
---------
115+
Allows creation of new fences with "fencelike" drawtype.
116+
117+
default.register_fence(name, item definition)
118+
^ Registers a new fence. Custom fields texture and material are required, as
119+
^ are name and description. The rest is optional. You can pass most normal
120+
^ nodedef fields here except drawtype. The fence group will always be added
121+
^ for this node.
122+
123+
#fence definition
124+
name = "default:fence_wood",
125+
description = "Wooden Fence",
126+
texture = "default_wood.png",
127+
material = "default:wood",
128+
groups = {choppy=2, oddly_breakable_by_hand = 2, flammable = 2},
129+
sounds = default.node_sound_wood_defaults(),
130+
113131
Farming API
114132
-----------
115133
The farming API allows you to easily register plants and hoes.

‎mods/default/crafting.lua

-8
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ minetest.register_craft({
4242
}
4343
})
4444

45-
minetest.register_craft({
46-
output = 'default:fence_wood 2',
47-
recipe = {
48-
{'group:stick', 'group:stick', 'group:stick'},
49-
{'group:stick', 'group:stick', 'group:stick'},
50-
}
51-
})
52-
5345
minetest.register_craft({
5446
output = 'default:sign_wall',
5547
recipe = {

‎mods/default/functions.lua

+45
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,51 @@ function default.dig_up(pos, node, digger)
209209
end
210210

211211

212+
--
213+
-- Fence registration helper
214+
--
215+
function default.register_fence(name, def)
216+
minetest.register_craft({
217+
output = name .. " 4",
218+
recipe = {
219+
{ def.material, 'group:stick', def.material },
220+
{ def.material, 'group:stick', def.material },
221+
}
222+
})
223+
224+
local fence_texture = "default_fence_overlay.png^" .. def.texture ..
225+
"^default_fence_overlay.png^[makealpha:255,126,126"
226+
-- Allow almost everything to be overridden
227+
local default_fields = {
228+
paramtype = "light",
229+
drawtype = "fencelike",
230+
inventory_image = fence_texture,
231+
wield_image = fence_texture,
232+
tiles = { def.texture },
233+
sunlight_propagates = true,
234+
is_ground_content = false,
235+
selection_box = {
236+
type = "fixed",
237+
fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
238+
},
239+
groups = {},
240+
}
241+
for k, v in pairs(default_fields) do
242+
if not def[k] then
243+
def[k] = v
244+
end
245+
end
246+
247+
-- Always add to the fence group, even if no group provided
248+
def.groups.fence = 1
249+
250+
def.texture = nil
251+
def.material = nil
252+
253+
minetest.register_node(name, def)
254+
end
255+
256+
212257
--
213258
-- Leafdecay
214259
--

‎mods/default/nodes.lua

+39-16
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ default:sign_wall
151151
default:ladder
152152
153153
default:fence_wood
154+
default:fence_acacia_wood
155+
default:fence_junglewood
156+
default:fence_pine_wood
157+
default:fence_aspen_wood
154158
155159
default:glass
156160
default:obsidian_glass
@@ -1674,26 +1678,45 @@ minetest.register_node("default:ladder", {
16741678
sounds = default.node_sound_wood_defaults(),
16751679
})
16761680

1677-
1678-
local fence_texture =
1679-
"default_fence_overlay.png^default_wood.png^default_fence_overlay.png^[makealpha:255,126,126"
1680-
minetest.register_node("default:fence_wood", {
1681+
default.register_fence("default:fence_wood", {
16811682
description = "Wooden Fence",
1682-
drawtype = "fencelike",
1683-
tiles = {"default_wood.png"},
1684-
inventory_image = fence_texture,
1685-
wield_image = fence_texture,
1686-
paramtype = "light",
1687-
sunlight_propagates = true,
1688-
is_ground_content = false,
1689-
selection_box = {
1690-
type = "fixed",
1691-
fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
1692-
},
1683+
texture = "default_wood.png",
1684+
material = "default:wood",
16931685
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
1694-
sounds = default.node_sound_wood_defaults(),
1686+
sounds = default.node_sound_wood_defaults()
1687+
})
1688+
1689+
default.register_fence("default:fence_acacia_wood", {
1690+
description = "Acacia Fence",
1691+
texture = "default_acacia_wood.png",
1692+
material = "default:acacia_wood",
1693+
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
1694+
sounds = default.node_sound_wood_defaults()
1695+
})
1696+
1697+
default.register_fence("default:fence_junglewood", {
1698+
description = "Junglewood Fence",
1699+
texture = "default_junglewood.png",
1700+
material = "default:junglewood",
1701+
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
1702+
sounds = default.node_sound_wood_defaults()
16951703
})
16961704

1705+
default.register_fence("default:fence_pine_wood", {
1706+
description = "Pine Fence",
1707+
texture = "default_pine_wood.png",
1708+
material = "default:pine_wood",
1709+
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
1710+
sounds = default.node_sound_wood_defaults()
1711+
})
1712+
1713+
default.register_fence("default:fence_aspen_wood", {
1714+
description = "Aspen Fence",
1715+
texture = "default_aspen_wood.png",
1716+
material = "default:aspen_wood",
1717+
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
1718+
sounds = default.node_sound_wood_defaults()
1719+
})
16971720

16981721
minetest.register_node("default:glass", {
16991722
description = "Glass",

0 commit comments

Comments
 (0)
Please sign in to comment.