Create API for registration of fence gate.

This commit is contained in:
Rui914 2016-03-18 16:33:14 +09:00 committed by paramat
parent d90a081722
commit a2ecc51fbc
2 changed files with 104 additions and 48 deletions

View File

@ -78,6 +78,12 @@ The doors mod allows modders to register custom doors and trapdoors.
* `name` Name for trapdoor
* `def` See [#Trapdoor definition]
`doors.register_fencegate(name, def)`
* Registers new fence gate
* `name` Name for fence gate
* `def` See [#Fence gate definition]
`doors.get(pos)`
* `pos` A position as a table, e.g `{x = 1, y = 1, z = 1}`
@ -119,6 +125,14 @@ The doors mod allows modders to register custom doors and trapdoors.
sound_close = sound play for close door, -- optional
protected = false, -- If true, only placer can open the door (locked for others)
###Fence gate definition
description = "Wooden Fence Gate",
texture = "default_wood.png",
material = "default:wood",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
sounds = default.node_sound_wood_defaults(), -- optional
Fence API
---------
Allows creation of new fences with "fencelike" drawtype.

View File

@ -658,23 +658,24 @@ minetest.register_craft({
----fence gate----
function doors.register_fencegate(name, def)
local fence = {
description = "Fence Gate",
description = def.description,
drawtype = "mesh",
tiles = {"default_wood.png"},
tiles = { def.texture },
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
drop = "doors:gate_closed",
drop = name .. "_closed",
connect_sides = { "left", "right" },
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2,
flammable = 2, fence = 1},
groups = def.groups,
sounds = def.sounds,
on_rightclick = function(pos, clicker)
local node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
minetest.swap_node(pos, {name = def.gate, param2 = node.param2})
minetest.sound_play(def.sound, {pos = pos, gain = 0.3,
local node_def = minetest.registered_nodes[node.name]
minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,
max_hear_distance = 8})
end,
selection_box = {
@ -683,9 +684,15 @@ local fence = {
},
}
if not fence.sounds then
fence.sounds = default.node_sound_wood_defaults()
end
fence.groups.fence = 1
local fence_closed = table.copy(fence)
fence_closed.mesh = "doors_fencegate_closed.obj"
fence_closed.gate = "doors:gate_open"
fence_closed.gate = name .. "_open"
fence_closed.sound = "doors_fencegate_open"
fence_closed.collision_box = {
type = "fixed",
@ -694,7 +701,7 @@ fence_closed.collision_box = {
local fence_open = table.copy(fence)
fence_open.mesh = "doors_fencegate_open.obj"
fence_open.gate = "doors:gate_closed"
fence_open.gate = name .. "_closed"
fence_open.sound = "doors_fencegate_close"
fence_open.groups.not_in_creative_inventory = 1
fence_open.collision_box = {
@ -703,14 +710,49 @@ fence_open.collision_box = {
{-5/8, -3/8, -14/16, -3/8, 3/8, 0}},
}
minetest.register_node("doors:gate_closed", fence_closed)
minetest.register_node("doors:gate_open", fence_open)
minetest.register_node(":" .. name .. "_closed", fence_closed)
minetest.register_node(":" .. name .. "_open", fence_open)
minetest.register_craft({
output = "doors:gate_closed",
output = name .. "_closed",
recipe = {
{"default:stick", "group:wood", "default:stick"},
{"default:stick", "group:wood", "default:stick"},
},
{"default:stick", def.material, "default:stick"},
{"default:stick", def.material, "default:stick"}
}
})
end
doors.register_fencegate("doors:gate_wood", {
description = "Wooden Fence Gate",
texture = "default_wood.png",
material = "default:wood",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
})
doors.register_fencegate("doors:gate_acacia_wood", {
description = "Acacia Fence Gate",
texture = "default_acacia_wood.png",
material = "default:acacia_wood",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
})
doors.register_fencegate("doors:gate_junglewood", {
description = "Junglewood Fence Gate",
texture = "default_junglewood.png",
material = "default:junglewood",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
})
doors.register_fencegate("doors:gate_pine_wood", {
description = "Pine Fence Gate",
texture = "default_pine_wood.png",
material = "default:pine_wood",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
})
doors.register_fencegate("doors:gate_aspen_wood", {
description = "Aspen Fence Gate",
texture = "default_aspen_wood.png",
material = "default:aspen_wood",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
})