carpets/api.lua

87 lines
2.1 KiB
Lua
Raw Normal View History

2016-11-05 07:17:08 +01:00
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local config = Settings(modpath .. "/settings.txt")
2016-09-04 17:09:25 +02:00
local carpet_proto = {
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5}
},
groups = {
snappy = 2,
flammable = 3,
oddly_breakable_by_hand = 3,
choppy = 2,
carpet = 1,
2016-11-05 07:17:08 +01:00
}
2016-09-04 17:09:25 +02:00
}
if config:get_bool("WoolFeeling") then
2016-11-05 07:17:08 +01:00
carpet_proto.sounds = default.node_sound_defaults()
carpet_proto.groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, flammable = 3}
2016-09-04 17:09:25 +02:00
end
function carpets.register(recipe, def)
local node = table.copy(carpet_proto)
if def then
for k,v in pairs(def) do
node.k = v
end
else
def = {}
2016-09-04 17:09:25 +02:00
end
local recipe_def = minetest.registered_nodes[recipe]
node.description = def.description or recipe_def.description.." Carpet"
node.tiles = table.copy(def.tiles or recipe_def.tiles or {})
node.sounds = table.copy(def.sounds or recipe_def.sounds or {})
if def.groups then
node.groups = table.copy(def.groups)
end
2016-11-05 07:17:08 +01:00
if node.tiles[6] then
node.tiles = {node.tiles[6]}
end
2016-09-04 17:09:25 +02:00
if config:get_bool("FallingCarpet") and node.groups.falling_node == nil then
node.groups.falling_node = 1
elseif node.groups.falling_node == 1 then
node.groups.falling_node = 0
end
2016-11-05 07:17:08 +01:00
local name = "carpet:" .. (node.name or recipe:gsub(":", "_"))
2016-09-04 17:09:25 +02:00
node.name = nil
if config:get_bool("NoFlyCarpet") then
local previous_on_place = node.on_place or minetest.item_place
node.on_place = function(itemstack, placer, pointed_thing, ...)
2016-11-05 07:17:08 +01:00
if not pointed_thing then
return
end
2016-09-04 17:09:25 +02:00
local above = pointed_thing.above
local under = pointed_thing.under
local under_node = minetest.get_node(under)
2016-11-05 07:17:08 +01:00
if above.y == (under.y + 1) and under_node.name == name then
2016-09-04 17:09:25 +02:00
return
end
return previous_on_place(itemstack, placer, pointed_thing, ...)
end
end
2016-11-05 07:17:08 +01:00
minetest.register_node(":" .. name, node)
2016-09-04 17:09:25 +02:00
minetest.register_craft({
2016-11-05 07:17:08 +01:00
output = name .. " 32",
recipe = {
{"group:wool", "group:wool", "group:wool"},
{"group:wool", recipe, "group:wool"}
}
2016-09-04 17:09:25 +02:00
})
end