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 * `name` Name for trapdoor
* `def` See [#Trapdoor definition] * `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)` `doors.get(pos)`
* `pos` A position as a table, e.g `{x = 1, y = 1, z = 1}` * `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 sound_close = sound play for close door, -- optional
protected = false, -- If true, only placer can open the door (locked for others) 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 Fence API
--------- ---------
Allows creation of new fences with "fencelike" drawtype. Allows creation of new fences with "fencelike" drawtype.

View File

@ -658,59 +658,101 @@ minetest.register_craft({
----fence gate---- ----fence gate----
local fence = { function doors.register_fencegate(name, def)
description = "Fence Gate", local fence = {
drawtype = "mesh", description = def.description,
tiles = {"default_wood.png"}, drawtype = "mesh",
paramtype = "light", tiles = { def.texture },
paramtype2 = "facedir", paramtype = "light",
sunlight_propagates = true, paramtype2 = "facedir",
is_ground_content = false, sunlight_propagates = true,
drop = "doors:gate_closed", is_ground_content = false,
connect_sides = { "left", "right" }, drop = name .. "_closed",
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, connect_sides = { "left", "right" },
flammable = 2, fence = 1}, groups = def.groups,
on_rightclick = function(pos, clicker) sounds = def.sounds,
local node = minetest.get_node(pos) on_rightclick = function(pos, clicker)
local def = minetest.registered_nodes[node.name] local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = def.gate, param2 = node.param2}) local node_def = minetest.registered_nodes[node.name]
minetest.sound_play(def.sound, {pos = pos, gain = 0.3, minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
max_hear_distance = 8}) minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,
end, max_hear_distance = 8})
selection_box = { end,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4},
},
}
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 = name .. "_open"
fence_closed.sound = "doors_fencegate_open"
fence_closed.collision_box = {
type = "fixed", type = "fixed",
fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4}, fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4},
}, }
}
local fence_closed = table.copy(fence) local fence_open = table.copy(fence)
fence_closed.mesh = "doors_fencegate_closed.obj" fence_open.mesh = "doors_fencegate_open.obj"
fence_closed.gate = "doors:gate_open" fence_open.gate = name .. "_closed"
fence_closed.sound = "doors_fencegate_open" fence_open.sound = "doors_fencegate_close"
fence_closed.collision_box = { fence_open.groups.not_in_creative_inventory = 1
type = "fixed", fence_open.collision_box = {
fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4}, type = "fixed",
} fixed = {{-1/2, -1/2, -1/4, -3/8, 1/2, 1/4},
{-5/8, -3/8, -14/16, -3/8, 3/8, 0}},
}
local fence_open = table.copy(fence) minetest.register_node(":" .. name .. "_closed", fence_closed)
fence_open.mesh = "doors_fencegate_open.obj" minetest.register_node(":" .. name .. "_open", fence_open)
fence_open.gate = "doors:gate_closed"
fence_open.sound = "doors_fencegate_close"
fence_open.groups.not_in_creative_inventory = 1
fence_open.collision_box = {
type = "fixed",
fixed = {{-1/2, -1/2, -1/4, -3/8, 1/2, 1/4},
{-5/8, -3/8, -14/16, -3/8, 3/8, 0}},
}
minetest.register_node("doors:gate_closed", fence_closed) minetest.register_craft({
minetest.register_node("doors:gate_open", fence_open) output = name .. "_closed",
recipe = {
{"default:stick", def.material, "default:stick"},
{"default:stick", def.material, "default:stick"}
}
})
end
minetest.register_craft({ doors.register_fencegate("doors:gate_wood", {
output = "doors:gate_closed", description = "Wooden Fence Gate",
recipe = { texture = "default_wood.png",
{"default:stick", "group:wood", "default:stick"}, material = "default:wood",
{"default:stick", "group:wood", "default:stick"}, 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}
})