moreblocks looks good, now stairsplus...

This commit is contained in:
flux 2022-06-12 11:49:41 -07:00
parent b2936054eb
commit da7d0f94dc
31 changed files with 172 additions and 210 deletions

View File

@ -25,6 +25,7 @@ stds.moreblocks = {
},
read_globals = {
"default",
"stairs",
"stairsplus",
},
}

View File

@ -4,29 +4,41 @@ More Blocks: alias definitions
Copyright © 2011-2020 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information.
--]]
local cm = moreblocks.resources.craft_materials
-- More Blocks aliases:
minetest.register_alias("sweeper", "moreblocks:sweeper")
minetest.register_alias("circular_saw", "moreblocks:circular_saw")
minetest.register_alias("jungle_stick", "moreblocks:jungle_stick")
if cm.stick then
minetest.register_alias("jungle_stick", cm.stick)
minetest.register_alias("moreblocks:jungle_stick", cm.stick)
end
-- Old block/item replacement:
minetest.register_alias("moreblocks:oerkkiblock", "default:mossycobble")
minetest.register_alias("moreblocks:screwdriver", "screwdriver:screwdriver")
if cm.mossycobble then
minetest.register_alias("moreblocks:oerkkiblock", cm.mossycobble)
end
if cm.screwdriver then
minetest.register_alias("moreblocks:screwdriver", cm.screwdriver)
end
-- Node and item renaming:
minetest.register_alias("moreblocks:stone_bricks", "default:stonebrick")
minetest.register_alias("moreblocks:stonebrick", "default:stonebrick")
minetest.register_alias("moreblocks:junglewood", "default:junglewood")
minetest.register_alias("moreblocks:jungle_wood", "default:junglewood")
minetest.register_alias("moreblocks:fence_junglewood", "default:fence_junglewood")
minetest.register_alias("moreblocks:fence_jungle_wood", "default:fence_junglewood")
minetest.register_alias("moreblocks:jungle_stick", "default:stick")
for _, t in pairs(circular_saw.names) do
minetest.register_alias("moreblocks:" .. t[1] .. "_jungle_wood" .. t[2],
"moreblocks:" .. t[1] .. "_junglewood" .. t[2])
if cm.stone_brick then
minetest.register_alias("moreblocks:stone_bricks", cm.stone_brick)
minetest.register_alias("moreblocks:stonebrick", cm.stone_brick)
end
if cm.jungle_wood then
minetest.register_alias("moreblocks:junglewood", cm.jungle_wood)
minetest.register_alias("moreblocks:jungle_wood", cm.jungle_wood)
end
if cm.fence_jungle_wood then
minetest.register_alias("moreblocks:fence_junglewood", cm.fence_jungle_wood)
minetest.register_alias("moreblocks:fence_jungle_wood", cm.fence_jungle_wood)
end
minetest.register_alias("moreblocks:horizontaltree", "moreblocks:horizontal_tree")
minetest.register_alias("moreblocks:horizontaljungletree", "moreblocks:horizontal_jungle_tree")
minetest.register_alias("moreblocks:stonesquare", "moreblocks:stone_tile")
@ -59,31 +71,6 @@ minetest.register_alias("moreblocks:splitstonesquare", "moreblocks:split_stone_t
minetest.register_alias("moreblocks:allfacestree", "moreblocks:all_faces_tree")
minetest.register_alias("moreblocks:empty_bookshelf", "moreblocks:empty_shelf")
minetest.register_alias("moreblocks:split_stone_tile_alt", "moreblocks:checker_stone_tile")
minetest.register_alias("moreblocks:wood_tile_flipped", "moreblocks:wood_tile")
minetest.register_alias("moreblocks:wood_tile_down", "moreblocks:wood_tile_offset")
minetest.register_alias("moreblocks:wood_tile_left", "moreblocks:wood_tile_offset")
minetest.register_alias("moreblocks:wood_tile_right", "moreblocks:wood_tile_offset")
-- ABM for horizontal trees (fix facedir):
local horizontal_tree_convert_facedir = {7, 12, 9, 18}
minetest.register_abm({
nodenames = {"moreblocks:horizontal_tree", "moreblocks:horizontal_jungle_tree"},
interval = 1,
chance = 1,
action = function(pos, node)
if node.name == "moreblocks:horizontal_tree" then
node.name = "default:tree"
else
node.name = "default:jungletree"
end
node.param2 = node.param2 < 3 and node.param2 or 0
minetest.set_node(pos, {
name = node.name,
param2 = horizontal_tree_convert_facedir[node.param2 + 1]
})
end,
})
minetest.register_lbm({
name = "moreblocks:reduce_wood_tile_redundancy",
@ -94,17 +81,53 @@ minetest.register_lbm({
"moreblocks:wood_tile_flipped",
},
action = function(pos, node)
if node.name:find("left") then
if node.name == "moreblocks:wood_tile_left" then
minetest.set_node(pos, {name = "moreblocks:wood_tile_offset", param2 = 1})
elseif node.name:find("down") then
elseif node.name == "moreblocks:wood_tile_down" then
minetest.set_node(pos, {name = "moreblocks:wood_tile_offset", param2 = 2})
elseif node.name:find("right") then
elseif node.name == "moreblocks:wood_tile_right" then
minetest.set_node(pos, {name = "moreblocks:wood_tile_offset", param2 = 3})
else
-- wood_tile_flipped
minetest.set_node(pos, {name = "moreblocks:wood_tile", param2 = 1})
end
minetest.log('action', "LBM replaced " .. node.name ..
" at " .. minetest.pos_to_string(pos))
moreblocks.log("action", "LBM replaced %s at %s", node.name, minetest.pos_to_string(pos))
end,
})
local horizontal_tree_convert_facedir = {7, 12, 9, 18}
if cm.tree then
minetest.register_lbm({
name = "moreblocks:reduce_horizontal_tree_redundancy",
nodenames = {
"moreblocks:horizontal_tree",
},
action = function(pos, node)
node.name = cm.tree
node.param2 = node.param2 < 3 and node.param2 or 0
minetest.set_node(pos, {
name = node.name,
param2 = horizontal_tree_convert_facedir[node.param2 + 1]
})
moreblocks.log("action", "LBM replaced %s at %s", node.name, minetest.pos_to_string(pos))
end,
})
end
if cm.jungle_tree then
minetest.register_lbm({
name = "moreblocks:reduce_horizontal_jungle_tree_redundancy",
nodenames = {
"moreblocks:horizontal_jungle_tree",
},
action = function(pos, node)
node.name = cm.jungle_tree
node.param2 = node.param2 < 3 and node.param2 or 0
minetest.set_node(pos, {
name = node.name,
param2 = horizontal_tree_convert_facedir[node.param2 + 1]
})
moreblocks.log("action", "LBM replaced %s at %s", node.name, minetest.pos_to_string(pos))
end,
})
end

View File

@ -1,6 +1,6 @@
local S = moreblocks.S
function moreblocks.api.register_all_faces(mod, name, base, redef)
function moreblocks.api.register_all_faces(itemstring, base, redef)
local def = table.copy(minetest.registered_nodes[base])
def.tiles = {def.tiles[1]}
@ -15,8 +15,8 @@ function moreblocks.api.register_all_faces(mod, name, base, redef)
def[k] = v
end
local itemstring = ("%s:%s"):format(mod, name)
moreblocks.api.register_node_with_stairs(mod, name, def)
minetest.register_node(itemstring, def)
minetest.register_craft({
output = itemstring .. " 8",
recipe = {

View File

@ -1,7 +1,7 @@
local S = moreblocks.S
local cm = moreblocks.resources.craft_materials
function moreblocks.api.register_trap(mod, name, base, redef)
function moreblocks.api.register_trap(itemstring, base, redef)
local def = table.copy(minetest.registered_nodes[base])
def.description = S("Trap @1", def.description)
@ -27,7 +27,6 @@ function moreblocks.api.register_trap(mod, name, base, redef)
def[k] = v
end
local itemstring = ("%s:%s"):format(mod, name)
minetest.register_node(itemstring, def)
if cm.trap_material then

View File

@ -23,6 +23,9 @@ moreblocks = {
has = {
bucket = minetest.get_modpath("bucket"),
default = minetest.get_modpath("default"),
rhotator = minetest.get_modpath("rhotator"),
screwdriver = minetest.get_modpath("screwdriver"),
stairs = minetest.get_modpath("stairs"),
stairsplus = minetest.get_modpath("stairsplus"),
vessels = minetest.get_modpath("vessels"),
},
@ -37,11 +40,11 @@ moreblocks = {
}
moreblocks.dofile("settings")
moreblocks.dofile("util")
moreblocks.dofile("resources", "init")
moreblocks.dofile("api", "init")
moreblocks.dofile("items")
moreblocks.dofile("nodes")
moreblocks.dofile("redefinitions") -- FLUX TODO what is this doing and why
moreblocks.dofile("crafting")
moreblocks.dofile("aliases")

View File

@ -1,5 +1,5 @@
name = moreblocks
title = More Blocks
description = Adds various blocks to the game.
optional_depends = bucket, default, stairsplus, vessels
optional_depends = bucket, default, rhotator, screwdriver, stairs, stairsplus, vessels
min_minetest_version = 5.5.0

View File

@ -10,6 +10,8 @@ local S = moreblocks.S
local cm = moreblocks.resources.craft_materials
local t = moreblocks.resources.textures
local modname = moreblocks.modname
local sound_dirt = moreblocks.resources.sounds.dirt
local sound_wood = moreblocks.resources.sounds.wood
local sound_stone = moreblocks.resources.sounds.stone
@ -17,36 +19,79 @@ local sound_glass = moreblocks.resources.sounds.glass
local sound_leaves = moreblocks.resources.sounds.leaves
local sound_metal = moreblocks.resources.sounds.metal
local function is_glasslike(def)
return #def.tiles > 1 and (
def.drawtype == "glasslike_framed" or
def.drawtype == "glasslike_framed_optional"
)
end
local function register_stairs(name, def)
local itemstring = ("%s:%s"):format(modname, name)
-- Use the primary tile for all sides of cut glasslike nodes.
-- This makes them easier to see
if is_glasslike(def) then
def = table.copy(def)
def.tiles = {def.tiles[1]}
end
if moreblocks.has.stairsplus then
stairsplus:register_all(modname, name, itemstring, {
description = def.description,
groups = def.groups,
tiles = def.tiles,
sunlight_propagates = def.sunlight_propagates,
light_source = def.light_source,
sounds = def.sounds,
})
elseif moreblocks.has.stairs then
stairs.register_stair_and_slab(
("%s_%s"):format(modname, name),
itemstring,
def.groups,
def.tiles,
S("@1 Stair", def.description),
S("@1 Slab", def.description),
def.sounds,
true
)
end
end
local function tile_tiles(tex)
return {tex, tex, tex, tex, tex .. "^[transformR90", tex .. "^[transformR90"}
end
local function register_with_stairs(name, def)
local itemstring = "moreblocks:" .. name
def.tiles = def.tiles or {"moreblocks_" .. name .. ".png"}
moreblocks.api.register_node_with_stairs("moreblocks", name, def)
local itemstring = ("%s:%s"):format(modname, name)
def.tiles = def.tiles or {("%s_%s.png"):format(modname, name)}
minetest.register_node(itemstring, def)
minetest.register_alias(name, itemstring)
register_stairs(name, def)
end
local function register_no_stairs(name, def)
local itemstring = "moreblocks:" .. name
def.tiles = def.tiles or {"moreblocks_" .. name .. ".png"}
local itemstring = ("%s:%s"):format(modname, name)
def.tiles = def.tiles or {("%s_%s.png"):format(modname, name)}
minetest.register_node(itemstring, def)
minetest.register_alias(name, itemstring)
end
local function register_all_faces(name, base)
name = "all_faces_" .. name
local itemstring = "moreblocks:" .. name
moreblocks.api.register_all_faces("moreblocks", name, base)
local itemstring = ("%s:%s"):format(modname, name)
moreblocks.api.register_all_faces(itemstring, base)
register_stairs(name, minetest.registered_nodes[itemstring])
minetest.register_alias(name, itemstring)
end
local function register_trap(name, base)
name = "trap_" .. name
local itemstring = "moreblocks:" .. name
moreblocks.api.register_trap("moreblocks", name, base)
local itemstring = ("%s:%s"):format(modname, name)
moreblocks.api.register_trap(itemstring, base)
minetest.register_alias(name, itemstring)
end

View File

@ -1,106 +0,0 @@
--[[
More Blocks: redefinitions of default stuff
Copyright © 2011-2020 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information.
--]]
local modname = minetest.get_current_modname()
-- Redefine some of the default crafting recipes to be more productive
-- Auxiliary function: take a recipe as returned by get_all_craft_recipes
-- and turn it into a table that can be used to clear a craft or declare a new one
local reconstruct_internal_craft = function(recipe)
local recp = {
{"", "", ""},
{"", "", ""},
{"", "", ""},
}
local width = recipe.width
for idx, item in pairs(recipe.items) do
local row = math.ceil(idx / width)
local col = idx - (row - 1) * width
recp[row][col] = item
end
return recp
end
-- Change the amount produced by recipe by apply func to the old amount
local change_recipe_amount = function(product, recipe, func)
-- if width == 0, this is a shapeless recipe, for which the
-- internal and Lua API recipe table is the same.
-- Otherwise we need to reconstruct the table for the shaped recipe.
local shapeless = (recipe.width == 0)
local recp = shapeless and recipe.items or reconstruct_internal_craft(recipe)
local oldamount = tonumber(recipe.output:match(" [0-9]+$") or "1")
local newamount = func(oldamount)
-- remove old crafting recipe
local redo = {recipe = recp}
-- preserve shapelessness
if shapeless then
redo.type = "shapeless"
end
minetest.clear_craft(redo)
-- new output
redo.output = ("%s %d"):format(product, newamount)
minetest.register_craft(redo)
minetest.log("action", ("[MOD]%s: recipe for %s production: %d => %d"):format(modname, product, oldamount, newamount))
end
local increase_craft_production = function(product, func)
local recipes = minetest.get_all_craft_recipes(product)
for _, r in pairs(recipes) do
if r.type == "normal" or r.method == "normal" then
change_recipe_amount(product, r, func)
end
end
end
-- Increase the crafting production according to the rules from the table, which is in the form:
-- {
-- { detector, amount changing function }
-- { detector, amount changing function }
-- }
-- TODO: consider exporting this function to other mods
local increase_craft_production_table = function(map_table)
for product, _ in pairs(minetest.registered_items) do
for _, tab in pairs(map_table) do
local detector = tab[1]
local func = tab[2]
if detector(product) then
increase_craft_production(product, func)
-- only apply one boost
break
end
end
end
end
increase_craft_production_table({
{function(n)
return n:match('^default:sign_wall')
end, function(old)
return old + 1
end},
{function(n)
return n == 'default:paper'
end, function(old)
return old * 4
end},
{function(n)
return n:match('^carts:.*rail$') or n:match('^default:.*rail$')
end, function(old)
return old + old / 2
end},
})
minetest.register_craft({
type = "toolrepair",
additional_wear = -0.10, -- Tool repair buff (10% bonus instead of 2%).
})

View File

@ -1,13 +1,15 @@
local table_set_all = moreblocks.util.table_set_all
moreblocks.resources.craft_materials = {}
if moreblocks.has.bucket then
table.insert_all(moreblocks.resources.craft_materials, {
table_set_all(moreblocks.resources.craft_materials, {
bucket_empty = "bucket:bucket_empty",
})
end
if moreblocks.has.default then
table.insert_all(moreblocks.resources.craft_materials, {
table_set_all(moreblocks.resources.craft_materials, {
acacia_tree = "default:acacia_tree",
aspen_tree = "default:aspen_tree",
book = "default:book",
@ -26,10 +28,12 @@ if moreblocks.has.default then
dirt = "default:dirt",
dirt_with_grass = "default:dirt_with_grass",
dry_shrub = "default:dry_shrub",
fence_jungle_wood = "default:fence_junglewood",
glass = "default:glass",
gold_ingot = "default:gold_ingot",
jungle_grass = "default:junglegrass",
jungle_tree = "default:jungletree",
jungle_wood = "default:junglewood",
mossy_cobble = "default:mossycobble",
obsidian = "default:obsidian",
obsidian_glass = "default:obsidian_glass",
@ -46,8 +50,18 @@ if moreblocks.has.default then
})
end
if moreblocks.has.screwdriver then
table_set_all(moreblocks.resources.craft_materials, {
screwdriver = "screwdriver:screwdriver",
})
elseif moreblocks.has.rhotator then
table_set_all(moreblocks.resources.craft_materials, {
screwdriver = "rhotator:screwdriver_multi",
})
end
if moreblocks.has.vessels then
table.insert_all(moreblocks.resources.craft_materials, {
table_set_all(moreblocks.resources.craft_materials, {
glass_bottle = "vessels:glass_bottle",
vessels_shelf = "vessels:shelf",
})

View File

@ -1,14 +1,9 @@
--[[
More Blocks: sound definitions
Copyright © 2011-2021 Hugo Locurcio and contributors.
Licensed under the zlib license. See LICENSE.md for more information.
--]]
local table_set_all = moreblocks.util.table_set_all
moreblocks.resources.sounds = {}
if moreblocks.has.default then
table.insert_all(moreblocks.resources.sounds, {
table_set_all(moreblocks.resources.sounds, {
dirt = default.node_sound_dirt_defaults(),
glass = default.node_sound_glass_defaults(),
leaves = default.node_sound_leaves_defaults(),

View File

@ -1,16 +1,17 @@
local table_set_all = moreblocks.util.table_set_all
moreblocks.resources.textures = {}
if moreblocks.has.default then
table.insert_all(moreblocks.resources.textures, {
wood = "default_wood.png",
table_set_all(moreblocks.resources.textures, {
desert_stone = "default_desert_stone.png",
glass = "default_glass.png",
glass_detail = "default_glass_detail.png",
stone = "default_stone.png",
desert_stone = "default_desert_stone.png",
obsidian = "default_obsidian.png",
obsidian_glass = "default_obsidian_glass.png",
obsidian_glass_detail = "default_obsidian_glass_detail.png",
obsidian = "default_obsidian.png",
sandstone = "default_sandstone.png",
stone = "default_stone.png",
wood = "default_wood.png",
})
end

8
moreblocks/util.lua Normal file
View File

@ -0,0 +1,8 @@
moreblocks.util = {
table_set_all = function(t, other_table)
for key, value in pairs(other_table) do
t[key] = value
end
return t
end
}

View File

@ -1,2 +1,8 @@
minetest.register_alias("circular_saw", "stairsplus:circular_saw")
minetest.register_alias("moreblocks:circular_saw", "stairsplus:circular_saw")
for _, t in pairs(stairsplus.circular_saw.names) do
minetest.register_alias("moreblocks:" .. t[1] .. "_jungle_wood" .. t[2],
"stairsplus:" .. t[1] .. "_junglewood" .. t[2])
end

View File

@ -1,27 +0,0 @@
local function is_glasslike(def)
return #def.tiles > 1 and (
def.drawtype == "glasslike_framed" or
def.drawtype == "glasslike_framed_optional"
)
end
function moreblocks.api.register_node_and_stairs(mod, name, def)
local itemstring = ("%s:%s"):format(mod, name)
minetest.register_node(itemstring, def)
-- Use the primary tile for all sides of cut glasslike nodes.
-- This makes them easier to see
if is_glasslike(def) then
def = table.copy(def)
def.tiles = {def.tiles[1]}
end
stairsplus:register_all(mod, name, itemstring, {
description = def.description,
groups = def.groups,
tiles = def.tiles,
sunlight_propagates = def.sunlight_propagates,
light_source = def.light_source,
sounds = def.sounds,
})
end