forked from mad-star-studio/Voxelis
Last night's work
This commit is contained in:
parent
a260c4a33a
commit
1708e2d461
45 changed files with 1359 additions and 1347 deletions
35
mods/ITEMS/vox_fabric/fabric_dying_bench.lua
Normal file
35
mods/ITEMS/vox_fabric/fabric_dying_bench.lua
Normal file
|
@ -0,0 +1,35 @@
|
|||
-- Fabric Dying Bench
|
||||
|
||||
minetest.register_node("vox_fabric:fabric_dying_bench", {
|
||||
description = "Fabric Dying Bench",
|
||||
tiles = {"fabric_dying_bench_top.png", "fabric_dying_bench_side.png"},
|
||||
groups = {cracky = 2},
|
||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
-- Show the UI for pattern creation
|
||||
local formspec = "size[8,9]" ..
|
||||
"label[0.5,0.5;Fabric Dying Bench]" ..
|
||||
"dropdown[1,1;3;grid_size;16x16,32x32,64x64;2]" ..
|
||||
"button[4,1;2,1;save;Save Pattern]"
|
||||
minetest.show_formspec(clicker:get_player_name(), "vox_fabric:dying_bench", formspec)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "vox_fabric:dying_bench" then
|
||||
if fields.save then
|
||||
-- Save the pattern
|
||||
local player_name = player:get_player_name()
|
||||
local pattern_id = player_name .. "_pattern_" .. os.time()
|
||||
local pattern_file = minetest.get_worldpath() .. "/vox_fabric_generated/" .. pattern_id .. ".json"
|
||||
|
||||
local pattern_data = {
|
||||
size = fields.grid_size,
|
||||
colors = {}, -- This would be populated based on the player's interactions
|
||||
}
|
||||
|
||||
minetest.safe_file_write(pattern_file, minetest.serialize(pattern_data))
|
||||
player:get_inventory():add_item("main", "vox_fabric:pattern_template")
|
||||
minetest.chat_send_player(player_name, "Pattern saved as: " .. pattern_id)
|
||||
end
|
||||
end
|
||||
end)
|
39
mods/ITEMS/vox_fabric/fabric_patterns.lua
Normal file
39
mods/ITEMS/vox_fabric/fabric_patterns.lua
Normal file
|
@ -0,0 +1,39 @@
|
|||
-- Fabric Patterns Management
|
||||
|
||||
local modpath = minetest.get_modpath("vox_fabric")
|
||||
local patterns_file = modpath .. "/textures/patterns.json"
|
||||
local patterns = {}
|
||||
|
||||
-- Load predefined patterns
|
||||
local file = io.open(patterns_file, "r")
|
||||
if file then
|
||||
local content = file:read("*a")
|
||||
file:close()
|
||||
patterns = minetest.parse_json(content) or {}
|
||||
end
|
||||
|
||||
-- Register predefined patterns as Pattern Template items
|
||||
for _, pattern in ipairs(patterns.patterns or {}) do
|
||||
minetest.register_craftitem("vox_fabric:pattern_" .. pattern.id, {
|
||||
description = "Pattern: " .. (pattern.title or pattern.id),
|
||||
inventory_image = "patterns/" .. pattern.id .. ".png",
|
||||
groups = {pattern = 1},
|
||||
})
|
||||
end
|
||||
|
||||
-- Pattern Template Item
|
||||
minetest.register_craftitem("vox_fabric:pattern_template", {
|
||||
description = "Pattern Template",
|
||||
inventory_image = "pattern_template.png",
|
||||
groups = {template = 1},
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
-- Interaction with Pattern Template
|
||||
local meta = itemstack:get_meta()
|
||||
local pattern_id = meta:get_string("pattern_id")
|
||||
if pattern_id and pattern_id ~= "" then
|
||||
minetest.chat_send_player(user:get_player_name(), "Pattern ID: " .. pattern_id)
|
||||
else
|
||||
minetest.chat_send_player(user:get_player_name(), "This template has no pattern.")
|
||||
end
|
||||
end,
|
||||
})
|
|
@ -0,0 +1,37 @@
|
|||
-- Voxelis: vox_fabric
|
||||
-- Dynamic fabric and pattern system for Minetest
|
||||
|
||||
-- Initialize the global table for the mod
|
||||
vox_fabric = {}
|
||||
|
||||
-- Dependencies
|
||||
local modpath = minetest.get_modpath("vox_fabric")
|
||||
dofile(modpath .. "/fabric_dying_bench.lua")
|
||||
dofile(modpath .. "/fabric_patterns.lua")
|
||||
|
||||
-- Fabric Registry
|
||||
local fabric_registry = {}
|
||||
|
||||
-- Register a fabric application
|
||||
function vox_fabric.register_application(modname, base_item, description, base_texture)
|
||||
fabric_registry[modname] = fabric_registry[modname] or {}
|
||||
table.insert(fabric_registry[modname], base_item)
|
||||
|
||||
minetest.register_node(modname .. ":" .. base_item, {
|
||||
description = description,
|
||||
tiles = {base_texture},
|
||||
groups = {fabric = 1},
|
||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
-- Interaction logic for applying patterns
|
||||
local meta = itemstack:get_meta()
|
||||
local pattern_id = meta:get_string("pattern_id")
|
||||
if pattern_id and pattern_id ~= "" then
|
||||
local new_texture = "generated_patterns/" .. pattern_id .. ".png"
|
||||
minetest.swap_node(pos, {name = modname .. ":" .. base_item, tiles = {new_texture}})
|
||||
minetest.chat_send_player(clicker:get_player_name(), "Applied pattern: " .. pattern_id)
|
||||
else
|
||||
minetest.chat_send_player(clicker:get_player_name(), "No pattern found on the template.")
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
|
@ -1,2 +1,3 @@
|
|||
name = vox_fabric
|
||||
description = Voxelis - Fabric. Allow players to use premade patterns (which can be dyed with vox_coloring), or allow them to make their own.
|
||||
description = Voxelis - Fabric. Allow players to use premade patterns (which can be dyed with vox_coloring), or allow them to make their own.
|
||||
depends = vox_colors
|
6
mods/ITEMS/vox_fabric/textures/patterns/patterns.json
Normal file
6
mods/ITEMS/vox_fabric/textures/patterns/patterns.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"patterns": [
|
||||
{"id": "pattern_1", "title": "Floral Design"},
|
||||
{"id": "pattern_2", "title": "Geometric Shapes"}
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue