summaryrefslogtreecommitdiff
path: root/coloredwood
diff options
context:
space:
mode:
Diffstat (limited to 'coloredwood')
-rw-r--r--coloredwood/init.lua303
-rw-r--r--coloredwood/textures/coloredwood_base.pngbin0 -> 214 bytes
-rw-r--r--coloredwood/textures/coloredwood_fence_base.pngbin0 -> 224 bytes
3 files changed, 267 insertions, 36 deletions
diff --git a/coloredwood/init.lua b/coloredwood/init.lua
index 23dfa15..c83f236 100644
--- a/coloredwood/init.lua
+++ b/coloredwood/init.lua
@@ -6,38 +6,10 @@
-- This mod provides 89 colors of wood, fences, and sticks, and enough
-- cross-compatible recipes to make everything fit together naturally.
--
--- Colored wood is crafted by putting two regular wood blocks into the
--- grid along with one dye color, in any order and position. The result
--- is two colored wood blocks.
---
--- Colored sticks are crafted from colored wood blocks only - one colored
--- wood block in any position yields 4 colored sticks as usual.
---
--- Uncolored sticks cannot be dyed separately, but they can still be used
--- to build colored wooden fences. These are crafted either by placing six
--- plain, uncolored sticks into the crafting grid in the usual manner, plus
--- one portion of dye in the upper-left corner of the grid
--- (D = dye, S = uncolored stick):
---
--- D - -
--- S S S
--- S S S
---
--- You can also craft a colored fence by using colored sticks derived from
--- colored wood. Just place six of them in the same manner as with plain
--- fences (CS = colored stick):
---
--- -- -- --
--- CS CS CS
--- CS CS CS
---
--- If you find yourself with too many colors of sticks and not enough,
--- ladders, you can use any color (as long as they"re all the same) to
--- create a ladder, but it"ll always result in a plain, uncolored ladder.
--- This practice isn"t recommended of course, since it wastes dye.
---
+-- Colored wood is created by placing a regular wood block on the ground
+-- and then right-clicking on it with some dye.
-- All materials are flammable and can be used as fuel.
-
+--
-- Hues are on a 30 degree spacing starting at red = 0 degrees.
-- "s50" in a file/item name means "saturation: 50%".
-- Texture brightness levels for the colors are 100%, 66% ("medium"),
@@ -45,6 +17,11 @@
coloredwood = {}
+coloredwood.enable_stairsplus = true
+if minetest.setting_getbool("coloredwood_enable_stairsplus") == false or not minetest.get_modpath("moreblocks") then
+ coloredwood.enable_stairsplus = false
+end
+
coloredwood.shades = {
"dark_",
"medium_",
@@ -127,11 +104,265 @@ coloredwood.greys3 = {
"dye:white"
}
--- All of the actual code is contained in separate lua files:
+coloredwood.hues_plus_greys = {}
-dofile(minetest.get_modpath("coloredwood").."/wood.lua")
-dofile(minetest.get_modpath("coloredwood").."/fence.lua")
-dofile(minetest.get_modpath("coloredwood").."/stick.lua")
+for _, hue in ipairs(coloredwood.hues) do
+ table.insert(coloredwood.hues_plus_greys, hue)
+end
-print("[Colored Wood] Loaded!")
+table.insert(coloredwood.hues_plus_greys, "grey")
+
+-- helper functions
+
+local function is_stairsplus(name)
+ local s1, s2
+
+ local a,b = string.find(name, ":stair")
+ if a then s1 = string.sub(name, a+1, b) end
+
+ a,b = string.find(name, ":slab")
+ if a then s1 = string.sub(name, a+1, b) end
+
+ a,b = string.find(name, ":panel")
+ if a then s1 = string.sub(name, a+1, b) end
+
+ a,b = string.find(name, ":micro")
+ if a then s1 = string.sub(name, a+1, b) end
+
+ a,b = string.find(name, ":slope")
+ if a then s1 = string.sub(name, a+1, b) end
+
+ local h, s, v = unifieddyes.get_hsv(name)
+
+ a,b = string.find(name, "_"..h..s)
+ if a then s2 = string.sub(name, b+1)
+ if string.find(s2, "wood") then s2 = string.sub(s2, 5) end
+ end
+ return s1, s2
+end
+
+-- the actual nodes!
+
+for _, color in ipairs(coloredwood.hues_plus_greys) do
+ minetest.register_node("coloredwood:wood_"..color, {
+ description = "Colored wooden planks",
+ tiles = { "coloredwood_base.png" },
+ paramtype = "light",
+ paramtype2 = "colorfacedir",
+ palette = "unifieddyes_palette_"..color.."s.png",
+ walkable = true,
+ sunlight_propagates = false,
+ groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2, not_in_creative_inventory=1},
+ sounds = default.node_sound_wood_defaults(),
+ after_dig_node = unifieddyes.after_dig_node,
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ unifieddyes.on_rightclick(pos, node, clicker,
+ itemstack, pointed_thing, "coloredwood:wood_"..color, true)
+ end,
+ drop = "default:wood"
+ })
+
+ -- moreblocks/stairsplus support
+
+ if coloredwood.enable_stairsplus then
+
+ -- stairsplus:register_all(modname, subname, recipeitem, {fields})
+
+ stairsplus:register_all(
+ "coloredwood",
+ "wood_"..color,
+ "coloredwood:wood_"..color,
+ {
+ description = "Colored wood",
+ tiles = { "coloredwood_base.png" },
+ paramtype = "light",
+ paramtype2 = "colorfacedir",
+ palette = "unifieddyes_palette_"..color.."s.png",
+ groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2, not_in_creative_inventory=1},
+ after_dig_node = unifieddyes.after_dig_node,
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ unifieddyes.on_rightclick(pos, node, clicker,
+ itemstack, pointed_thing, nil, true)
+ end
+ }
+ )
+ end
+end
+
+-- force on_rightclick for stairsplus default wood stair/slab/etc nodes
+ if coloredwood.enable_stairsplus then
+
+ for _, i in pairs(minetest.registered_nodes) do
+ if string.find(i.name, "moreblocks:stair_wood")
+ or string.find(i.name, "moreblocks:slab_wood")
+ or string.find(i.name, "moreblocks:panel_wood")
+ or string.find(i.name, "moreblocks:micro_wood")
+ or string.find(i.name, "moreblocks:slope_wood")
+ then
+
+ minetest.override_item(i.name, {
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ local wield = itemstack:get_name()
+ local newnode = nil
+ if string.find(wield, "dye:") or string.find(wield, "unifieddyes:") then
+ local s1, s2 = is_stairsplus(i.name)
+ local paletteidx, hue = unifieddyes.getpaletteidx(wield, true)
+ if hue ~= 0 then
+ newnode = "coloredwood:"..s1.."_wood_"..coloredwood.hues[hue]..s2
+ else
+ newnode = "coloredwood:"..s1.."_wood_grey"..s2
+ end
+ end
+ unifieddyes.on_rightclick(pos, node, clicker,
+ itemstack, pointed_thing, newnode, true)
+ end,
+ })
+ end
+ end
+
+ -- fix drops for colored versions of stairsplus nodes
+
+ for _, i in pairs(minetest.registered_nodes) do
+ if string.find(i.name, "coloredwood:stair_")
+ or string.find(i.name, "coloredwood:slab_")
+ or string.find(i.name, "coloredwood:panel_")
+ or string.find(i.name, "coloredwood:micro_")
+ or string.find(i.name, "coloredwood:slope_")
+ then
+
+ mname = string.gsub(i.name, "coloredwood:", "moreblocks:")
+ local s1, s2 = is_stairsplus(mname)
+
+ minetest.override_item(i.name, {
+ drop = "moreblocks:"..s1.."_wood"..s2
+ })
+ end
+ end
+end
+
+minetest.override_item("default:wood", {
+ paramtype2 = "colorfacedir",
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ unifieddyes.on_rightclick(pos, node, clicker,
+ itemstack, pointed_thing, "coloredwood:wood_grey", true)
+ end
+})
+
+minetest.register_node("coloredwood:fence", {
+ drawtype = "fencelike",
+ description = "Colored wooden fence",
+ tiles = { "coloredwood_fence_base.png" },
+ paramtype = "light",
+ paramtype2 = "color",
+ palette = "unifieddyes_palette.png",
+ walkable = true,
+ groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
+ sounds = default.node_sound_wood_defaults(),
+ selection_box = {
+ type = "fixed",
+ fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
+ },
+ after_dig_node = unifieddyes.after_dig_node,
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ unifieddyes.on_rightclick(pos, node, clicker,
+ itemstack, pointed_thing, "coloredwood:fence")
+ end,
+ drop = "default:fence_wood"
+})
+
+minetest.override_item("default:fence_wood", {
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ unifieddyes.on_rightclick(pos, node, clicker,
+ itemstack, pointed_thing, "coloredwood:fence")
+ end
+})
+
+-- ============================
+-- convert the old static nodes
+
+coloredwood.old_static_nodes = {}
+
+for _, hue in ipairs(coloredwood.hues) do
+ for _, sat in ipairs({"", "_s50"}) do
+ for _, val in ipairs ({"dark_", "medium_", "light_", ""}) do
+ table.insert(coloredwood.old_static_nodes, "coloredwood:wood_"..val..hue..sat)
+ table.insert(coloredwood.old_static_nodes, "coloredwood:fence_"..val..hue..sat)
+ end
+ end
+end
+
+for _, shade in ipairs(coloredwood.greys) do
+ table.insert(coloredwood.old_static_nodes, "coloredwood:wood_"..shade)
+ table.insert(coloredwood.old_static_nodes, "coloredwood:fence_"..shade)
+end
+
+-- add all of the stairsplus nodes
+
+for _, shape in ipairs(circular_saw.names) do
+ local a = shape[1]
+ local b = shape[2]
+ for _, hue in ipairs(coloredwood.hues) do
+ for _, shade in ipairs(coloredwood.shades) do
+ table.insert(coloredwood.old_static_nodes, "coloredwood:"..a.."_wood_"..shade..hue..b)
+ table.insert(coloredwood.old_static_nodes, "coloredwood:"..a.."_wood_"..shade..hue.."_s50"..b)
+ end
+ table.insert(coloredwood.old_static_nodes, "coloredwood:"..a.."_wood_light_"..hue..b) -- light doesn't have extra shades or s50
+ end
+end
+
+for _, shape in ipairs(circular_saw.names) do
+ local a = shape[1]
+ local b = shape[2]
+ for _, hue in ipairs(coloredwood.greys) do
+ for _, shade in ipairs(coloredwood.shades) do
+ table.insert(coloredwood.old_static_nodes, "coloredwood:"..a.."_wood_"..hue..b)
+ end
+ end
+end
+
+minetest.register_lbm({
+ name = "coloredwood:convert",
+ label = "Convert wood blocks, fences, stairsplus stuff, etc to use param2 color",
+ run_at_every_load = true,
+ nodenames = coloredwood.old_static_nodes,
+ action = function(pos, node)
+ local meta = minetest.get_meta(pos)
+
+ if meta and (meta:get_string("dye") ~= "") then return end -- node has already been converted before.
+
+ local name = node.name
+ local hue, sat, val = unifieddyes.get_hsv(name)
+
+ local color = val..hue..sat
+
+ local s1, s2 = is_stairsplus(name)
+
+ if s1 then
+
+ local paletteidx, _ = unifieddyes.getpaletteidx("unifieddyes:"..color, true)
+ local cfdir = paletteidx + (node.param2 % 32)
+ local newname = "coloredwood:"..s1.."_wood_"..hue..s2
+
+ minetest.set_node(pos, { name = newname, param2 = cfdir })
+ local meta = minetest.get_meta(pos)
+ meta:set_string("dye", "unifieddyes:"..color)
+
+ elseif string.find(name, ":fence") then
+ local paletteidx, hue = unifieddyes.getpaletteidx("unifieddyes:"..color, false)
+ minetest.set_node(pos, { name = "coloredwood:fence", param2 = paletteidx })
+ meta:set_string("dye", "unifieddyes:"..color)
+ else
+ local paletteidx, hue = unifieddyes.getpaletteidx("unifieddyes:"..color, true)
+ if hue ~= 0 and hue ~= nil then
+ minetest.set_node(pos, { name = "coloredwood:wood_"..coloredwood.hues[hue], param2 = paletteidx })
+ meta:set_string("dye", "unifieddyes:"..color)
+ else
+ minetest.set_node(pos, { name = "coloredwood:wood_grey", param2 = paletteidx })
+ meta:set_string("dye", "unifieddyes:"..color)
+ end
+ end
+ end
+})
+
+print("[Colored Wood] Loaded!")
diff --git a/coloredwood/textures/coloredwood_base.png b/coloredwood/textures/coloredwood_base.png
new file mode 100644
index 0000000..18d186e
--- /dev/null
+++ b/coloredwood/textures/coloredwood_base.png
Binary files differ
diff --git a/coloredwood/textures/coloredwood_fence_base.png b/coloredwood/textures/coloredwood_fence_base.png
new file mode 100644
index 0000000..d5946e5
--- /dev/null
+++ b/coloredwood/textures/coloredwood_fence_base.png
Binary files differ