mirror of
https://github.com/minetest-mods/carpets.git
synced 2024-12-20 20:35:42 +01:00
first commit
This commit is contained in:
commit
41f5bd957c
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
||||
# minetest-carpets
|
76
carpet_api.lua
Normal file
76
carpet_api.lua
Normal file
@ -0,0 +1,76 @@
|
||||
carpet = {}
|
||||
|
||||
local config = Settings(minetest.get_modpath("carpets").."/settings.txt")
|
||||
|
||||
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}
|
||||
},
|
||||
}
|
||||
|
||||
if config:get_bool("WoolFeeling") then
|
||||
local wool = minetest.registered_nodes["wool:white"]
|
||||
carpet_proto.sounds = wool.sounds
|
||||
carpet_proto.groups = wool.groups
|
||||
end
|
||||
|
||||
|
||||
function carpet.register(recipe, def)
|
||||
local node = {}
|
||||
|
||||
if def then
|
||||
for k, v in pairs(def) do
|
||||
node[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs(carpet_proto) do
|
||||
node[k] = v
|
||||
end
|
||||
|
||||
local recipe_def = minetest.registered_nodes[recipe]
|
||||
|
||||
node.description = node.description or recipe_def.description.." Carpet"
|
||||
node.tiles = node.tiles or recipe_def.tiles
|
||||
node.sounds = node.sounds or recipe_def.sounds
|
||||
node.groups = node.groups or recipe_def.groups or {}
|
||||
|
||||
node.groups.leafdecay = nil
|
||||
|
||||
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
|
||||
|
||||
local name = "carpet:"..(node.name or recipe:gsub(":", "_"))
|
||||
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, ...)
|
||||
if not pointed_thing then return end
|
||||
|
||||
local above = pointed_thing.above
|
||||
local under = pointed_thing.under
|
||||
local under_node = minetest.get_node(under)
|
||||
|
||||
if above.y == under.y + 1 and under_node.name == name then
|
||||
return
|
||||
end
|
||||
return previous_on_place(itemstack, placer, pointed_thing, ...)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node(":"..name, node)
|
||||
|
||||
minetest.register_craft({
|
||||
output = name.." 32",
|
||||
recipe = {{"group:wool", "group:wool", "group:wool"},
|
||||
{"group:wool", recipe, "group:wool"}}
|
||||
})
|
||||
end
|
10
depends.txt
Normal file
10
depends.txt
Normal file
@ -0,0 +1,10 @@
|
||||
wool
|
||||
default?
|
||||
farming?
|
||||
bones?
|
||||
castle?
|
||||
darkage?
|
||||
moreblocks?
|
||||
plasticbox?
|
||||
princess?
|
||||
moretrees?
|
43
init.lua
Normal file
43
init.lua
Normal file
@ -0,0 +1,43 @@
|
||||
dofile(minetest.get_modpath("carpets").."/carpet_api.lua")
|
||||
dofile(minetest.get_modpath("carpets").."/modutils.lua")
|
||||
|
||||
depmod = modutils.get_depmod("carpets")
|
||||
|
||||
|
||||
function carpet.enabledfilter(name, def)
|
||||
-- disable carpets from loaded modules but not defined in dependency
|
||||
if depmod.check_depmod(name) == false then
|
||||
return false
|
||||
end
|
||||
|
||||
-- disable carpets for blocks without description
|
||||
if def.description == nil or def.description == "" then
|
||||
return false
|
||||
end
|
||||
|
||||
-- not supported node types for carpets
|
||||
if def.drawtype == "liquid" or
|
||||
def.drawtype == "firelike" or
|
||||
def.drawtype == "airlike" or
|
||||
def.drawtype == "plantlike" or
|
||||
def.drawtype == "raillike" then
|
||||
return false
|
||||
end
|
||||
|
||||
-- no carpet for signs, rail, ladder
|
||||
if def.paramtype2 == "wallmounted" then
|
||||
return false
|
||||
end
|
||||
|
||||
-- all checks passed
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------
|
||||
-- main execution
|
||||
for name, def in pairs(minetest.registered_nodes) do
|
||||
if carpet.enabledfilter(name, def) == true then
|
||||
carpet.register(name)
|
||||
end
|
||||
end
|
1
mod.conf
Normal file
1
mod.conf
Normal file
@ -0,0 +1 @@
|
||||
name = carpets
|
49
modutils.lua
Normal file
49
modutils.lua
Normal file
@ -0,0 +1,49 @@
|
||||
modutils = {}
|
||||
|
||||
function modutils.get_depmod(modname)
|
||||
-- Get dependency object (depmod)
|
||||
|
||||
-- Definition of returning object attributes
|
||||
local depmod = {
|
||||
modname, -- module name from get_depmod
|
||||
deplist = {}, -- depends.txt parsed
|
||||
}
|
||||
|
||||
|
||||
-- Definition of returning object methods
|
||||
function depmod.check_depmod(checknode)
|
||||
-- check if the node (checknode) is from dependent module
|
||||
local delimpos = string.find(checknode, ":")
|
||||
if delimpos then
|
||||
local checkmodname = string.sub(checknode, 1, delimpos - 1)
|
||||
for name, ref in pairs(depmod.deplist) do
|
||||
if name == checkmodname then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Full returning object attributes
|
||||
depmod.modname = modname
|
||||
|
||||
-- local variable definition
|
||||
local depentry = {} -- Entry in deplist
|
||||
local depmodname -- temp value
|
||||
local dependsfile = io.open(minetest.get_modpath(modname).."/depends.txt")
|
||||
if dependsfile then
|
||||
for dependsline in dependsfile:lines() do
|
||||
if string.sub(dependsline, -1) == "?" then
|
||||
depentry.required = false
|
||||
depmodname = string.sub(dependsline, 1, -2)
|
||||
else
|
||||
depentry.required = true
|
||||
depmodname = dependsline
|
||||
end
|
||||
depmod.deplist[depmodname] = depentry
|
||||
end
|
||||
end
|
||||
|
||||
return depmod
|
||||
end
|
3
settings.txt
Normal file
3
settings.txt
Normal file
@ -0,0 +1,3 @@
|
||||
NoFlyCarpet = true
|
||||
FallingCarpet = false
|
||||
WoolFeeling = false
|
Loading…
Reference in New Issue
Block a user