instead of crafting, use place-and-dye to colorize
That is, place a piece of obsidian framed glass on the ground, then right-click it with dye to set a color (by default, it is clear/empty). Dig the colored one to get back the uncolored one and dye. You can change the color by dyeing it again, in which case you get back the old dye. If the color you wield is not supported by the mod, or if the target node is already that color, a warning message is thrown.
This commit is contained in:
parent
67c7336a32
commit
3114feac07
123
init.lua
123
init.lua
@ -66,6 +66,110 @@ minetest.register_node("framedglass:wooden_framed_obsidian_glass", {
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
})
|
||||
|
||||
-- helper functions copied partly from Unified Dyes
|
||||
|
||||
local creative_mode = minetest.setting_getbool("creative_mode")
|
||||
|
||||
local function select_node(pointed_thing)
|
||||
local pos = pointed_thing.under
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
local def = node and minetest.registered_nodes[node.name]
|
||||
|
||||
if not def or not def.buildable_to then
|
||||
pos = pointed_thing.above
|
||||
node = minetest.get_node_or_nil(pos)
|
||||
def = node and minetest.registered_nodes[node.name]
|
||||
end
|
||||
return def and pos, def
|
||||
end
|
||||
|
||||
local function is_buildable_to(placer_name, ...)
|
||||
for _, pos in ipairs({...}) do
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
local def = node and minetest.registered_nodes[node.name]
|
||||
if not (def and def.buildable_to) or minetest.is_protected(pos, placer_name) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local color_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
local itemname = itemstack:get_name()
|
||||
|
||||
if not string.find(itemname, "dye:") then
|
||||
if minetest.registered_nodes[node.name] then
|
||||
local pos2 = select_node(pointed_thing)
|
||||
if pos2 and is_buildable_to(clicker, pos2) then
|
||||
minetest.set_node(pos2, { name = itemname })
|
||||
if not creative_mode then
|
||||
itemstack:take_item()
|
||||
end
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local a,b = string.find(node.name, "_glass")
|
||||
local oldcolor = string.sub(node.name, b + 1)
|
||||
local newcolor = string.sub(itemname, string.find(itemname, ":") + 1)
|
||||
|
||||
local oldcolor2 = string.gsub(oldcolor, "darkgreen", "dark_green")
|
||||
local oldcolor2 = string.gsub(oldcolor2, "darkgrey", "dark_grey")
|
||||
|
||||
local newcolor2 = string.gsub(newcolor, "dark_green", "darkgreen")
|
||||
local newcolor2 = string.gsub(newcolor2, "dark_grey", "darkgrey")
|
||||
|
||||
if oldcolor == newcolor2 then
|
||||
minetest.chat_send_player(clicker:get_player_name(), "That node is already "..newcolor.."." )
|
||||
return itemstack
|
||||
end
|
||||
|
||||
if not (newcolor == "dark_grey"
|
||||
or newcolor == "dark_green"
|
||||
or minetest.registered_nodes["framedglass:steel_framed_obsidian_glass"..newcolor]) then
|
||||
minetest.chat_send_player(clicker:get_player_name(), "Framed glass doesn't support "..newcolor.."." )
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local inv = clicker:get_inventory()
|
||||
local prevdye = "dye:"..oldcolor2
|
||||
|
||||
print(oldcolor, oldcolor2, newcolor, newcolor2, prevdye)
|
||||
|
||||
if not (inv:contains_item("main", prevdye) and creative_mode) and minetest.registered_items[prevdye] then
|
||||
if inv:room_for_item("main", prevdye) then
|
||||
inv:add_item("main", prevdye)
|
||||
else
|
||||
minetest.add_item(pos, prevdye)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.set_node(pos, { name = "framedglass:steel_framed_obsidian_glass"..newcolor2 })
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local return_dye_after_dig = function(pos, oldnode, oldmetadata, digger)
|
||||
|
||||
local a,b = string.find(oldnode.name, "_glass")
|
||||
local oldcolor = string.sub(oldnode.name, b + 1)
|
||||
local oldcolor2 = string.gsub(oldcolor, "darkgreen", "dark_green")
|
||||
local oldcolor2 = string.gsub(oldcolor2, "darkgrey", "dark_grey")
|
||||
|
||||
local prevdye = "dye:"..oldcolor2
|
||||
|
||||
local inv = digger:get_inventory()
|
||||
|
||||
if prevdye and not (inv:contains_item("main", prevdye) and creative_mode) and minetest.registered_items[prevdye] then
|
||||
if inv:room_for_item("main", prevdye) then
|
||||
inv:add_item("main", prevdye)
|
||||
else
|
||||
minetest.add_item(pos, prevdye)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("framedglass:steel_framed_obsidian_glass", {
|
||||
description = "Steel-framed Obsidian Glass",
|
||||
drawtype = "glasslike_framed",
|
||||
@ -74,6 +178,8 @@ minetest.register_node("framedglass:steel_framed_obsidian_glass", {
|
||||
sunlight_propagates = true,
|
||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
on_rightclick = color_on_rightclick,
|
||||
after_dig_node = return_dye_after_dig
|
||||
})
|
||||
|
||||
function add_coloured_framedglass(name, desc, dye, texture)
|
||||
@ -85,20 +191,12 @@ function add_coloured_framedglass(name, desc, dye, texture)
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = true,
|
||||
use_texture_alpha = true,
|
||||
groups = {cracky=3},
|
||||
groups = {cracky=3, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
on_rightclick = color_on_rightclick,
|
||||
after_dig_node = return_dye_after_dig,
|
||||
drop = "framedglass:steel_framed_obsidian_glass"
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "framedglass:steel_framed_obsidian_glass"..name,
|
||||
recipe = {
|
||||
"framedglass:steel_framed_glass",
|
||||
"group:basecolor_white",
|
||||
dye
|
||||
}
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
add_coloured_framedglass ("red","Red","group:basecolor_red","framedglass_redglass.png")
|
||||
@ -115,4 +213,3 @@ add_coloured_framedglass ("white","White","group:basecolor_white","framedglass_w
|
||||
add_coloured_framedglass ("grey","Grey","group:basecolor_grey","framedglass_greyglass.png")
|
||||
add_coloured_framedglass ("darkgrey","Dark Grey","group:excolor_darkgrey","framedglass_darkgreyglass.png")
|
||||
add_coloured_framedglass ("black","Black","group:basecolor_black","framedglass_blackglass.png")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user