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.
This commit is contained in:
parent
a4e144e4c8
commit
2f39cad09b
18
game_api.txt
18
game_api.txt
@ -110,6 +110,24 @@ doors.register_trapdoor(name, def)
|
|||||||
will be overwritten by the trapdoor registration function
|
will be overwritten by the trapdoor registration function
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Fence API
|
||||||
|
---------
|
||||||
|
Allows creation of new fences with "fencelike" drawtype.
|
||||||
|
|
||||||
|
default.register_fence(name, item definition)
|
||||||
|
^ Registers a new fence. Custom fields texture and material are required, as
|
||||||
|
^ are name and description. The rest is optional. You can pass most normal
|
||||||
|
^ nodedef fields here except drawtype. The fence group will always be added
|
||||||
|
^ for this node.
|
||||||
|
|
||||||
|
#fence definition
|
||||||
|
name = "default:fence_wood",
|
||||||
|
description = "Wooden Fence",
|
||||||
|
texture = "default_wood.png",
|
||||||
|
material = "default:wood",
|
||||||
|
groups = {choppy=2, oddly_breakable_by_hand = 2, flammable = 2},
|
||||||
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
|
||||||
Farming API
|
Farming API
|
||||||
-----------
|
-----------
|
||||||
The farming API allows you to easily register plants and hoes.
|
The farming API allows you to easily register plants and hoes.
|
||||||
|
@ -42,14 +42,6 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
|
||||||
output = 'default:fence_wood 2',
|
|
||||||
recipe = {
|
|
||||||
{'group:stick', 'group:stick', 'group:stick'},
|
|
||||||
{'group:stick', 'group:stick', 'group:stick'},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'default:sign_wall',
|
output = 'default:sign_wall',
|
||||||
recipe = {
|
recipe = {
|
||||||
|
@ -209,6 +209,51 @@ function default.dig_up(pos, node, digger)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Fence registration helper
|
||||||
|
--
|
||||||
|
function default.register_fence(name, def)
|
||||||
|
minetest.register_craft({
|
||||||
|
output = name .. " 4",
|
||||||
|
recipe = {
|
||||||
|
{ def.material, 'group:stick', def.material },
|
||||||
|
{ def.material, 'group:stick', def.material },
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
local fence_texture = "default_fence_overlay.png^" .. def.texture ..
|
||||||
|
"^default_fence_overlay.png^[makealpha:255,126,126"
|
||||||
|
-- Allow almost everything to be overridden
|
||||||
|
local default_fields = {
|
||||||
|
paramtype = "light",
|
||||||
|
drawtype = "fencelike",
|
||||||
|
inventory_image = fence_texture,
|
||||||
|
wield_image = fence_texture,
|
||||||
|
tiles = { def.texture },
|
||||||
|
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 = {},
|
||||||
|
}
|
||||||
|
for k, v in pairs(default_fields) do
|
||||||
|
if not def[k] then
|
||||||
|
def[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Always add to the fence group, even if no group provided
|
||||||
|
def.groups.fence = 1
|
||||||
|
|
||||||
|
def.texture = nil
|
||||||
|
def.material = nil
|
||||||
|
|
||||||
|
minetest.register_node(name, def)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Leafdecay
|
-- Leafdecay
|
||||||
--
|
--
|
||||||
|
@ -151,6 +151,10 @@ default:sign_wall
|
|||||||
default:ladder
|
default:ladder
|
||||||
|
|
||||||
default:fence_wood
|
default:fence_wood
|
||||||
|
default:fence_acacia_wood
|
||||||
|
default:fence_junglewood
|
||||||
|
default:fence_pine_wood
|
||||||
|
default:fence_aspen_wood
|
||||||
|
|
||||||
default:glass
|
default:glass
|
||||||
default:obsidian_glass
|
default:obsidian_glass
|
||||||
@ -1674,26 +1678,45 @@ minetest.register_node("default:ladder", {
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
default.register_fence("default:fence_wood", {
|
||||||
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",
|
description = "Wooden Fence",
|
||||||
drawtype = "fencelike",
|
texture = "default_wood.png",
|
||||||
tiles = {"default_wood.png"},
|
material = "default:wood",
|
||||||
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},
|
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
default.register_fence("default:fence_acacia_wood", {
|
||||||
|
description = "Acacia Fence",
|
||||||
|
texture = "default_acacia_wood.png",
|
||||||
|
material = "default:acacia_wood",
|
||||||
|
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
||||||
|
sounds = default.node_sound_wood_defaults()
|
||||||
|
})
|
||||||
|
|
||||||
|
default.register_fence("default:fence_junglewood", {
|
||||||
|
description = "Junglewood Fence",
|
||||||
|
texture = "default_junglewood.png",
|
||||||
|
material = "default:junglewood",
|
||||||
|
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
||||||
|
sounds = default.node_sound_wood_defaults()
|
||||||
|
})
|
||||||
|
|
||||||
|
default.register_fence("default:fence_pine_wood", {
|
||||||
|
description = "Pine Fence",
|
||||||
|
texture = "default_pine_wood.png",
|
||||||
|
material = "default:pine_wood",
|
||||||
|
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
||||||
|
sounds = default.node_sound_wood_defaults()
|
||||||
|
})
|
||||||
|
|
||||||
|
default.register_fence("default:fence_aspen_wood", {
|
||||||
|
description = "Aspen Fence",
|
||||||
|
texture = "default_aspen_wood.png",
|
||||||
|
material = "default:aspen_wood",
|
||||||
|
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
|
||||||
|
sounds = default.node_sound_wood_defaults()
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_node("default:glass", {
|
minetest.register_node("default:glass", {
|
||||||
description = "Glass",
|
description = "Glass",
|
||||||
|
Loading…
Reference in New Issue
Block a user