Compare commits

...

4 Commits

Author SHA1 Message Date
TheOnlyJoeEnderman 5879e3b0fb add paintbrush 2024-01-05 17:45:19 +00:00
TheOnlyJoeEnderman 0d1cd8d748 add paintbrush 2024-01-05 17:40:52 +00:00
TheOnlyJoeEnderman 8f563c8dfb Fix critical registration bug 2023-06-02 23:40:11 +00:00
TheOnlyJoeEnderman 2bc80c9e49 Upload files to '' 2023-04-03 02:12:03 +00:00
6 changed files with 122 additions and 19 deletions

View File

@ -1,4 +1,4 @@
# Paintings Library
####
Attempts to make it easy to add many paintings of various sizes.
Attempts to make it easy to add many paintings of various sizes. Now a paintbrush is included to cycle all paintings at random. You do not have to make your own painting recipes anymore if you do not want to.

View File

@ -6,3 +6,94 @@ local default_path = minetest.get_modpath("paintings_lib")
dofile(minetest.get_modpath("paintings_lib") .. "/register.lua")
dofile(minetest.get_modpath("paintings_lib") .. "/paintings.lua")
-- Global variable to hold the list of painting nodes
local painting_nodes = {}
-- Function to populate the painting nodes list
local function populate_painting_nodes()
for name, def in pairs(minetest.registered_nodes) do
if def.groups.painting then
table.insert(painting_nodes, name)
end
end
end
-- Register the function to be called after all mods have loaded
minetest.register_on_mods_loaded(populate_painting_nodes)
-- Call the function to populate the list at server start
populate_painting_nodes()
-- Retrieve the number of uses from settings
local paintbrush_uses = tonumber(minetest.settings:get("paintings_lib_paintbrush_uses")) or 32
-- Register the paintbrush tool
minetest.register_tool("paintings_lib:paintbrush", {
description = "Paintbrush",
inventory_image = "paintings_lib_paintbrush.png",
wield_image = "paintings_lib_paintbrush.png^[transformFX"
})
-- Function to swap the node and wear out the paintbrush
local function swap_node(pos, node, clicker)
local wielded_item = clicker:get_wielded_item()
if wielded_item:get_name() ~= "paintings_lib:paintbrush" then
return
end
if #painting_nodes > 0 then
local new_node_name = node.name
local attempts = 0
-- Loop until a different painting is found or after 10 attempts
while new_node_name == node.name and attempts < 10 do
new_node_name = painting_nodes[math.random(#painting_nodes)]
attempts = attempts + 1
end
if new_node_name ~= node.name then
minetest.swap_node(pos, {name = new_node_name})
-- Adding wear to the paintbrush
wielded_item:add_wear(65535 / paintbrush_uses)
clicker:set_wielded_item(wielded_item)
end
end
end
-- Override the on_rightclick for nodes in the "painting" group
minetest.register_on_punchnode(function(pos, node, clicker, pointed_thing)
if minetest.get_item_group(node.name, "painting") > 0 then
swap_node(pos, node, clicker)
end
end)
-- Crafting recipe to 'refill' the paintbrush
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
local paintbrush_found, dye_found = false, false
for _, item in ipairs(old_craft_grid) do
if item:get_name() == "paintings_lib:paintbrush" then
paintbrush_found = true
-- Fully repair the paintbrush
itemstack:add_wear(-65535)
end
if minetest.get_item_group(item:get_name(), "dye") > 0 then
dye_found = true
end
end
if paintbrush_found and dye_found then
return itemstack
end
end)
minetest.register_craft({
type = "shapeless",
output = "paintings_lib:paintbrush",
recipe = {
"paintings_lib:paintbrush",
"group:dye", "group:dye", "group:dye", "group:dye",
"group:dye", "group:dye", "group:dye", "group:dye"
}
})

View File

@ -3,3 +3,4 @@ title = Paintings Library
description = A fast, sleek, modern painting API for Minetest Game, but optional support for other games.
depends = default
min_minetest_version = 5.3
author = JoeEnderman

View File

@ -4,7 +4,7 @@ paintings_texture = {}
-- define the node registration function
function paintings_lib.register1x1(identifier, display_name, texture)
local node_name = ":paintings_lib:1x1_"..display_name:gsub("%s+", "_")
local node_name = ":paintings_lib:1x1_"..identifier:gsub("%s+", "_")
paintings_name[identifier] = paintings_name[identifier] or {}
paintings_name[identifier]["1x1"] = node_name
paintings_texture[node_name] = texture
@ -17,17 +17,18 @@ function paintings_lib.register1x1(identifier, display_name, texture)
selection_box = {type = "fixed", fixed = {-0.5, -0.5, 0.4375, 0.5, 0.5, 0.5}},
collision_box = {type = "fixed", fixed = {-0.5, -0.5, 0.4375, 0.5, 0.5, 0.5}},
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
groups = {choppy = 3, oddly_breakable_by_hand = 3},
groups = {painting = 1, choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
end
-- define the node registration function
function paintings_lib.register1x2(identifier, display_name, texture)
local node_name = ":paintings_lib:1x2_"..display_name:gsub("%s+", "_")
local node_name = ":paintings_lib:1x2_"..identifier:gsub("%s+", "_")
paintings_name[identifier] = paintings_name[identifier] or {}
paintings_name[identifier]["1x2"] = node_name
paintings_texture[node_name] = texture
@ -40,17 +41,18 @@ function paintings_lib.register1x2(identifier, display_name, texture)
selection_box = {type = "fixed", fixed = {-0.5, -1.5, 0.4375, 0.5, 0.5, 0.5}},
collision_box = {type = "fixed", fixed = {-0.5, -1.5, 0.4375, 0.5, 0.5, 0.5}},
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
groups = {choppy = 3, oddly_breakable_by_hand = 3},
groups = {painting = 1, choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
end
-- define the node registration function
function paintings_lib.register2x1(identifier, display_name, texture)
local node_name = ":paintings_lib:2x1_"..display_name:gsub("%s+", "_")
local node_name = ":paintings_lib:2x1_"..identifier:gsub("%s+", "_")
paintings_name[identifier] = paintings_name[identifier] or {}
paintings_name[identifier]["2x1"] = node_name
paintings_texture[node_name] = texture
@ -63,17 +65,18 @@ function paintings_lib.register2x1(identifier, display_name, texture)
selection_box = {type = "fixed", fixed = {-0.5, -0.5, 0.4375, 1.5, 0.5, 0.5}},
collision_box = {type = "fixed", fixed = {-0.5, -0.5, 0.4375, 1.5, 0.5, 0.5}},
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
groups = {choppy = 3, oddly_breakable_by_hand = 3},
groups = {painting = 1, choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
end
-- define the node registration function
function paintings_lib.register2x2(identifier, display_name, texture)
local node_name = ":paintings_lib:2x2_"..display_name:gsub("%s+", "_")
local node_name = ":paintings_lib:2x2_"..identifier:gsub("%s+", "_")
paintings_name[identifier] = paintings_name[identifier] or {}
paintings_name[identifier]["2x2"] = node_name
paintings_texture[node_name] = texture
@ -86,17 +89,18 @@ function paintings_lib.register2x2(identifier, display_name, texture)
selection_box = {type = "fixed", fixed = {-0.5, -1.5, 0.4375, 1.5, 0.5, 0.5}},
collision_box = {type = "fixed", fixed = {-0.5, -1.5, 0.4375, 1.5, 0.5, 0.5}},
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
groups = {choppy = 3, oddly_breakable_by_hand = 3},
groups = {painting = 1, choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
end
-- define the node registration function
function paintings_lib.register3x2(identifier, display_name, texture)
local node_name = ":paintings_lib:3x2_"..display_name:gsub("%s+", "_")
local node_name = ":paintings_lib:3x2_"..identifier:gsub("%s+", "_")
paintings_name[identifier] = paintings_name[identifier] or {}
paintings_name[identifier]["3x2"] = node_name
paintings_texture[node_name] = texture
@ -109,17 +113,18 @@ function paintings_lib.register3x2(identifier, display_name, texture)
selection_box = {type = "fixed", fixed = {-1.5, -1.5, 0.4375, 1.5, 0.5, 0.5}},
collision_box = {type = "fixed", fixed = {-1.5, -1.5, 0.4375, 1.5, 0.5, 0.5}},
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
groups = {choppy = 3, oddly_breakable_by_hand = 3},
groups = {painting = 1, choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
end
-- define the node registration function
function paintings_lib.register3x3(identifier, display_name, texture)
local node_name = ":paintings_lib:3x3_"..display_name:gsub("%s+", "_")
local node_name = ":paintings_lib:3x3_"..identifier:gsub("%s+", "_")
paintings_name[identifier] = paintings_name[identifier] or {}
paintings_name[identifier]["3x3"] = node_name
paintings_texture[node_name] = texture
@ -132,17 +137,18 @@ function paintings_lib.register3x3(identifier, display_name, texture)
selection_box = {type = "fixed", fixed = {-1.5, -1.5, 0.4375, 1.5, 1.5, 0.5}},
collision_box = {type = "fixed", fixed = {-1.5, -1.5, 0.4375, 1.5, 1.5, 0.5}},
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
groups = {choppy = 3, oddly_breakable_by_hand = 3},
groups = {painting = 1, choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
end
-- define the node registration function
function paintings_lib.register4x2(identifier, display_name, texture)
local node_name = ":paintings_lib:4x2_"..display_name:gsub("%s+", "_")
local node_name = ":paintings_lib:4x2_"..identifier:gsub("%s+", "_")
paintings_name[identifier] = paintings_name[identifier] or {}
paintings_name[identifier]["4x2"] = node_name
paintings_texture[node_name] = texture
@ -155,17 +161,18 @@ function paintings_lib.register4x2(identifier, display_name, texture)
selection_box = {type = "fixed", fixed = {-1.5, -1.5, 0.4375, 2.5, 0.5, 0.5}},
collision_box = {type = "fixed", fixed = {-1.5, -1.5, 0.4375, 2.5, 0.5, 0.5}},
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
groups = {choppy = 3, oddly_breakable_by_hand = 3},
groups = {painting = 1, choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
end
-- define the node registration function
function paintings_lib.register4x3(identifier, display_name, texture)
local node_name = ":paintings_lib:4x3_"..display_name:gsub("%s+", "_")
local node_name = ":paintings_lib:4x3_"..identifier:gsub("%s+", "_")
paintings_name[identifier] = paintings_name[identifier] or {}
paintings_name[identifier]["4x3"] = node_name
paintings_texture[node_name] = texture
@ -178,17 +185,18 @@ function paintings_lib.register4x3(identifier, display_name, texture)
selection_box = {type = "fixed", fixed = {-1.5, -1.5, 0.4375, 2.5, 1.5, 0.5}},
collision_box = {type = "fixed", fixed = {-1.5, -1.5, 0.4375, 2.5, 1.5, 0.5}},
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
groups = {choppy = 3, oddly_breakable_by_hand = 3},
groups = {painting = 1, choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
end
-- define the node registration function
function paintings_lib.register4x4(identifier, display_name, texture)
local node_name = ":paintings_lib:4x4_"..display_name:gsub("%s+", "_")
local node_name = ":paintings_lib:4x4_"..identifier:gsub("%s+", "_")
paintings_name[identifier] = paintings_name[identifier] or {}
paintings_name[identifier]["4x4"] = node_name
paintings_texture[node_name] = texture
@ -201,10 +209,11 @@ function paintings_lib.register4x4(identifier, display_name, texture)
selection_box = {type = "fixed", fixed = {-1.5, -2.5, 0.4375, 2.5, 1.5, 0.5}},
collision_box = {type = "fixed", fixed = {-1.5, -2.5, 0.4375, 2.5, 1.5, 0.5}},
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
groups = {choppy = 3, oddly_breakable_by_hand = 3},
groups = {painting = 1, choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
end

2
settingtypes.txt Normal file
View File

@ -0,0 +1,2 @@
# Number of uses for the paintbrush
paintings_lib_paintbrush_uses (Paintbrush uses) int 32 1 1000

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B