mirror of
https://github.com/minetest-mods/carpets.git
synced 2024-12-20 20:35:42 +01:00
Simplify checking depend
This commit is contained in:
parent
556008b68f
commit
ffb24d285f
@ -1,3 +1,3 @@
|
|||||||
# minetest-carpets
|
# minetest-carpets
|
||||||
|
|
||||||
see https://forum.minetest.net/viewtopic.php?f=9&t=15459#p232311
|
See https://forum.minetest.net/viewtopic.php?t=15459
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
local config = Settings(minetest.get_modpath("carpets").."/settings.txt")
|
local modname = minetest.get_current_modname()
|
||||||
|
local modpath = minetest.get_modpath(modname)
|
||||||
|
|
||||||
|
local config = Settings(modpath .. "/settings.txt")
|
||||||
|
|
||||||
local carpet_proto = {
|
local carpet_proto = {
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
@ -7,16 +10,14 @@ local carpet_proto = {
|
|||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5}
|
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config:get_bool("WoolFeeling") then
|
if config:get_bool("WoolFeeling") then
|
||||||
local wool = minetest.registered_nodes["wool:white"]
|
carpet_proto.sounds = default.node_sound_defaults()
|
||||||
carpet_proto.sounds = wool.sounds
|
carpet_proto.groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, flammable = 3}
|
||||||
carpet_proto.groups = wool.groups
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function carpets.register(recipe, def)
|
function carpets.register(recipe, def)
|
||||||
local node = {}
|
local node = {}
|
||||||
|
|
||||||
@ -32,14 +33,15 @@ function carpets.register(recipe, def)
|
|||||||
|
|
||||||
local recipe_def = minetest.registered_nodes[recipe]
|
local recipe_def = minetest.registered_nodes[recipe]
|
||||||
|
|
||||||
node.description = node.description or recipe_def.description.." Carpet"
|
node.description = node.description or recipe_def.description .. " Carpet"
|
||||||
node.tiles = node.tiles or recipe_def.tiles
|
node.tiles = node.tiles or recipe_def.tiles
|
||||||
if node.tiles[6] then -- prefer "front" site for carpet
|
|
||||||
|
if node.tiles[6] then -- prefer "front" site for carpet
|
||||||
node.tiles = {node.tiles[6]}
|
node.tiles = {node.tiles[6]}
|
||||||
end
|
end
|
||||||
|
|
||||||
node.sounds = node.sounds or recipe_def.sounds
|
node.sounds = node.sounds or recipe_def.sounds
|
||||||
node.groups = node.groups or recipe_def.groups or {}
|
node.groups = node.groups or recipe_def.groups or {}
|
||||||
|
|
||||||
node.groups.leafdecay = nil
|
node.groups.leafdecay = nil
|
||||||
|
|
||||||
@ -49,30 +51,34 @@ function carpets.register(recipe, def)
|
|||||||
node.groups.falling_node = 0
|
node.groups.falling_node = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local name = "carpet:"..(node.name or recipe:gsub(":", "_"))
|
local name = "carpet:" .. (node.name or recipe:gsub(":", "_"))
|
||||||
node.name = nil
|
node.name = nil
|
||||||
|
|
||||||
if config:get_bool("NoFlyCarpet") then
|
if config:get_bool("NoFlyCarpet") then
|
||||||
local previous_on_place = node.on_place or minetest.item_place
|
local previous_on_place = node.on_place or minetest.item_place
|
||||||
node.on_place = function(itemstack, placer, pointed_thing, ...)
|
node.on_place = function(itemstack, placer, pointed_thing, ...)
|
||||||
if not pointed_thing then return end
|
if not pointed_thing then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local above = pointed_thing.above
|
local above = pointed_thing.above
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
local under_node = minetest.get_node(under)
|
local under_node = minetest.get_node(under)
|
||||||
|
|
||||||
if above.y == under.y + 1 and under_node.name == name then
|
if above.y == (under.y + 1) and under_node.name == name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
return previous_on_place(itemstack, placer, pointed_thing, ...)
|
return previous_on_place(itemstack, placer, pointed_thing, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node(":"..name, node)
|
minetest.register_node(":" .. name, node)
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = name.." 32",
|
output = name .. " 32",
|
||||||
recipe = {{"group:wool", "group:wool", "group:wool"},
|
recipe = {
|
||||||
{"group:wool", recipe, "group:wool"}}
|
{"group:wool", "group:wool", "group:wool"},
|
||||||
|
{"group:wool", recipe, "group:wool"}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
54
init.lua
54
init.lua
@ -1,46 +1,62 @@
|
|||||||
carpets = {}
|
carpets = {}
|
||||||
|
|
||||||
dofile(minetest.get_modpath("carpets").."/carpet_api.lua")
|
local modname = minetest.get_current_modname()
|
||||||
dofile(minetest.get_modpath("carpets").."/modutils.lua")
|
local modpath = minetest.get_modpath(modname)
|
||||||
|
|
||||||
depmod = carpets.modutils.get_depmod("carpets")
|
dofile(modpath .. "/api.lua")
|
||||||
|
|
||||||
|
local depends = (function()
|
||||||
|
local file = io.open(modpath .. "/depends.txt")
|
||||||
|
if not file then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local function enabledfilter(name, def)
|
local depends = {}
|
||||||
-- disable carpets from loaded modules but not defined in dependency
|
for line in file:lines() do
|
||||||
if depmod:check_depmod(name) == false then
|
if line:sub(-1) == "?" then
|
||||||
|
line = line:sub(1, -2)
|
||||||
|
end
|
||||||
|
depends[line] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
return depends
|
||||||
|
end)()
|
||||||
|
|
||||||
|
local function filter(name, def)
|
||||||
|
-- disable carpets from loaded modules but not defined in dependency
|
||||||
|
if not depends[def.mod_origin] then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- disable carpets for blocks without description
|
-- disable carpets for blocks without description
|
||||||
if def.description == nil or def.description == "" then
|
if def.description == nil or def.description == "" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- not supported node types for carpets
|
-- not supported node types for carpets
|
||||||
if def.drawtype == "liquid" or
|
if def.drawtype == "liquid" or
|
||||||
def.drawtype == "firelike" or
|
def.drawtype == "firelike" or
|
||||||
def.drawtype == "airlike" or
|
def.drawtype == "airlike" or
|
||||||
def.drawtype == "plantlike" or
|
def.drawtype == "plantlike" or
|
||||||
def.drawtype == "nodebox" or
|
def.drawtype == "nodebox" or
|
||||||
def.drawtype == "raillike" then
|
def.drawtype == "raillike" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- no carpet for signs, rail, ladder
|
-- no carpet for signs, rail, ladder
|
||||||
if def.paramtype2 == "wallmounted" then
|
if def.paramtype2 == "wallmounted" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- all checks passed
|
-- all checks passed
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
------------------------------------------------
|
|
||||||
-- main execution
|
-- main execution
|
||||||
for name, def in pairs(minetest.registered_nodes) do
|
for name, def in pairs(minetest.registered_nodes) do
|
||||||
if enabledfilter(name, def) then
|
if filter(name, def) then
|
||||||
carpets.register(name)
|
carpets.register(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
70
modutils.lua
70
modutils.lua
@ -1,70 +0,0 @@
|
|||||||
-- not modutils related, will be moved to a framework, if the utils framework will be developed :/
|
|
||||||
-- The envroot is accessable by global variable with module name as name (like if used in "carpets" mod, the modutils are at carpets.modutils available)
|
|
||||||
-- Different per module environment root allow the use of diffent versions of the same tool in different mods
|
|
||||||
|
|
||||||
local currentmod = minetest.get_current_modname()
|
|
||||||
local envroot = nil
|
|
||||||
|
|
||||||
if not currentmod or currentmod == "" then --not minetest or something hacky
|
|
||||||
envroot = _G --fallback for hacky calls, populate global
|
|
||||||
else
|
|
||||||
if not _G[currentmod] then
|
|
||||||
_G[currentmod] = {}
|
|
||||||
end
|
|
||||||
envroot = _G[currentmod]
|
|
||||||
end
|
|
||||||
-- framework stuff done. -- Now the tool
|
|
||||||
----------------------------------------
|
|
||||||
|
|
||||||
envroot.modutils = {}
|
|
||||||
|
|
||||||
-- Definition of returning object methods
|
|
||||||
local _check_depmod = function(this, 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(this.deplist) do
|
|
||||||
if name == checkmodname then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function envroot.modutils.get_depmod(modname)
|
|
||||||
|
|
||||||
-- Definition of returning object attributes
|
|
||||||
local this = { }
|
|
||||||
this.modname = modname
|
|
||||||
this.deplist = {} -- depends.txt parsed
|
|
||||||
this.check_depmod = _check_depmod -- method
|
|
||||||
-- get module path
|
|
||||||
local modpath = minetest.get_modpath(modname)
|
|
||||||
if not modpath then
|
|
||||||
return nil -- module not found
|
|
||||||
end
|
|
||||||
|
|
||||||
-- read the depends file
|
|
||||||
local dependsfile = io.open(modpath.."/depends.txt")
|
|
||||||
if not dependsfile then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- parse the depends file
|
|
||||||
for dependsline in dependsfile:lines() do
|
|
||||||
local depentry = {} -- Entry in deplist
|
|
||||||
local depmodname
|
|
||||||
if string.sub(dependsline, -1) == "?" then
|
|
||||||
depentry.required = false
|
|
||||||
depmodname = string.sub(dependsline, 1, -2)
|
|
||||||
else
|
|
||||||
depentry.required = true
|
|
||||||
depmodname = dependsline
|
|
||||||
end
|
|
||||||
this.deplist[depmodname] = depentry
|
|
||||||
end
|
|
||||||
|
|
||||||
return this
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user