Added initial code and media

master
Andrey2470T 2022-01-10 01:35:44 +03:00
parent 31d0d74c00
commit 8679ebb86d
43 changed files with 484 additions and 0 deletions

7
decor_api/init.lua Normal file
View File

@ -0,0 +1,7 @@
multidecor = {}
local modpath = minetest.get_modpath("decor_api")
dofile(modpath .. "/register.lua")
dofile(modpath .. "/sitting.lua")
dofile(modpath .. "/seat.lua")

3
decor_api/mod.conf Normal file
View File

@ -0,0 +1,3 @@
name = decor_api
description = Set of API functions for various furniture stuff
author = Andrey01

182
decor_api/register.lua Normal file
View File

@ -0,0 +1,182 @@
-- Registration API
multidecor.register = {}
register = multidecor.register
-- Default furniture types
register.supported_types = {
"seat",
"table",
"shelf",
"bed"
}
-- Default furniture styles
register.supported_styles = {
"baroque",
"classic",
"high_tech",
"mixed",
"modern",
"royal"
}
-- Default furniture materials
register.supported_materials = {
"wood",
"glass",
"metal",
"plastic",
"stone"
}
-- Registers a new furniture type
function register.register_type(type_name)
table.insert(register.supported_types, type_name)
end
-- Checks whether type with 'type_name' name is registered
function register.check_for_type(type_name)
for _, type in ipairs(register.supported_types) do
if type == type_name then
return true
end
end
return false
end
-- Checks whether style with 'style_name' name is registered
function register.check_for_style(style_name)
minetest.debug("style_name: " .. style_name)
for _, style in ipairs(register.supported_styles) do
if style == style_name then
return true
end
end
return false
end
--[[def:
{
type = <seat, shelf, bed, table, >
style = <baroque, classic, high_tech, mixed, modern, royal>,
material = <wood, glass, metal and etc>,
description = <description>,
drawtype = <nodebox, mesh>,
mesh = <filename>,
tiles = {<textures>},
paramtype2 = <paramtype2>,
bounding_boxes = {
Box1: {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
Box2: {0.5, 1.5, 0.1, 0.5, 1.0, 0.5},
...
},
wield_scale = {x=<float>, y=<float>, z=<float>} (Optional),
visual_scale = <float> (Optional),
drop = <drop name> (Optional),
groups = {snappy=<int>, choppy=<int>, crumbly=<int>...} (Optional),
sounds = {
footstep = <SimpleSoundSpec>,
dig = <SimpleSoundSpec>,
dug = <SimpleSoundSpec>,
place = <SimpleSoundSpec>,
place_failed = <SimpleSoundSpec>,
fall = <SimpleSoundSpec>
} (Optional),
callbacks = {
on_construct = <function>,
on_destruct = <function>,
on_rightclick = <function>,
on_timer = <function>
}
}
]]
-- Registers some furniture component (chair, stool, table, sofa, cupboard and etc).
function register.register_furniture_unit(name, def, craft_def)
local f_def = {}
assert(register.check_for_type(def.type), "The type with a name \"" .. def.type .. "\" is not registered!")
assert(register.check_for_style(def.style), "The type with a name \"" .. def.style .. "\" is not registered!")
f_def.description = def.description
f_def.visual_scale = def.visual_scale
f_def.wield_scale = def.wield_scale
f_def.drawtype = def.drawtype or "mesh"
f_def.paramtype2 = def.paramtype2 or "facedir"
f_def.use_texture_alpha = "clip"
if f_def.drawtype == "mesh" then
f_def.mesh = def.mesh
end
f_def.tiles = def.tiles
f_def.inventory_image = def.inventory_image
f_def.wield_image = def.wield_image
f_def.groups = def.groups or {}
f_def.groups[def.type] = 1
f_def.groups[def.style] = 1
if def.material then
f_def.groups[def.material] = 1
end
if def.bounding_boxes then
if f_def.drawtype == "nodebox" then
f_def.node_box = {
type = "fixed",
fixed = def.bounding_boxes
}
f_def.selection_box = f_def.node_box
elseif f_def.drawtype == "mesh" then
f_def.collision_box = {
type = "fixed",
fixed = def.bounding_boxes
}
f_def.selection_box = f_def.collision_box
minetest.debug("f_def.collision_box: " .. dump(f_def.collision_box))
end
end
if def.sounds then
f_def.sounds = def.sounds
else
if f_def.material == "wood" then
f_def.sounds = default.node_sound_wood_defaults()
elseif f_def.material == "glass" then
f_def.sounds = default.node_sound_glass_defaults()
elseif f_def.material == "metal" then
f_def.sounds = default.node_sound_metal_defaults()
elseif f_def.material == "plastic" then
f_def.sounds = default.node_sound_leaves_defaults()
elseif f_def.material == "stone" then
f_def.sounds = default.node_sound_stone_defaults()
end
end
f_def.on_construct = def.callbacks.on_construct
f_def.on_destruct = def.callbacks.on_destruct
f_def.on_rightclick = def.callbacks.on_rightclick
f_def.on_timer = def.callbacks.on_timer
f_def.add_properties = def.add_properties
local f_name = def.style .. ":" .. name
minetest.register_node(f_name, f_def)
if craft_def then
minetest.register_craft({
output = f_name,
recipe = craft_def.recipe,
replacements = craft_def.replacements
})
end
end
-- Registers a set of furniture components of certain type: "kitchen", "bathroom", "bedroom", "living_room" and etc.
function register.register_garniture()
end

46
decor_api/seat.lua Normal file
View File

@ -0,0 +1,46 @@
--[[
'seat_def' is table:
{
pos = <attach position>
rot = <attach rotation>
models = {
[1] = {
mesh = <filename>,
anim = {range = <table>, speed = <float>, blend = <bool>, loop = <bool>}
}
...
}
}
]]
function register.register_seat(name, base_def, seat_def, craft_def)
local def = table.copy(base_def)
def.type = "seat"
def.paramtype2 = "facedir"
def.add_properties = {
seat_data = seat_def
}
if not def.callbacks then
def.callbacks = {}
def.callbacks.on_construct = function(pos)
minetest.get_meta(pos):set_string("is_busy", "")
end
def.callbacks.on_destruct = function(pos)
sitting.standup_player(minetest.get_player_by_name(minetest.get_meta(pos):get_string("is_busy")), pos)
end
def.callbacks.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local bool = sitting.sit_player(clicker, pos)
if not bool then
sitting.standup_player(clicker, pos)
end
end
end
register.register_furniture_unit(name, def, craft_def)
end

116
decor_api/sitting.lua Normal file
View File

@ -0,0 +1,116 @@
-- Sitting API
--[[Node that can be sat on should contain 'is_busy' metadata field with playername string.
Player that is currently sitting should contain 'previous_mesh_data' metadata field to return his previous mesh after detaching.
It is presented in such form:
{
mesh = <current mesh name>,
anim = {range=float, speed=float, blend=bool, loop=bool},
physics = {speed=float, jump=float}
}
]]
multidecor.sitting = {}
sitting = multidecor.sitting
function sitting.attach_player_to_node(attacher, seat_data)
attacher:set_pos(seat_data.pos)
attacher:set_look_vertical(seat_data.rot.x)
attacher:set_look_horizontal(seat_data.rot.y)
attacher:set_physics_override({speed=0, jump=0})
if seat_data.model then
attacher:set_properties({mesh = seat_data.model.mesh})
attacher:set_animation(seat_data.model.anim.range, seat_data.model.anim.speed, seat_data.model.anim.blend, seat_data.model.anim.loop)
end
end
function sitting.detach_player_from_node(detacher, prev_pdata)
if not prev_pdata then
minetest.debug("3")
return
end
minetest.debug("prev_pdata.physics: " .. dump(prev_pdata.physics))
detacher:set_physics_override(prev_pdata.physics)
if prev_pdata.mesh and prev_pdata.anim then
detacher:set_properties({mesh = prev_pdata.mesh})
detacher:set_animation(prev_pdata.anim.range, prev_pdata.anim.speed, prev_pdata.anim.blend, prev_pdata.anim.loop)
end
end
function sitting.is_player_attached_to_anything(player)
local prev_pdata = player:get_meta():get_string("previous_player_data")
return prev_pdata ~= ""
end
function sitting.is_seat_busy(node_pos)
local is_busy = minetest.get_meta(node_pos):get_string("is_busy")
return is_busy ~= ""
end
function sitting.sit_player(player, node_pos)
if not player then
return
end
if sitting.is_player_attached_to_anything(player) then
return false
end
local playername = player:get_player_name()
if sitting.is_seat_busy(node_pos) then
minetest.chat_send_player(playername, "This seat is busy!")
return false
end
local physics = player:get_physics_override()
local prev_pdata = {
physics = {speed = physics.speed, jump = physics.jump}
}
local node = minetest.get_node(node_pos)
local seat_data = minetest.registered_nodes[node.name].add_properties.seat_data
local rand_model
if seat_data.models then
local range, speed, blend, loop = player:get_animation()
prev_pdata.mesh = player:get_properties().mesh
prev_pdata.anim = {range = range, speed = speed, blend = blend, loop = loop}
rand_model = seat_data.models[math.random(1, #seat_data.models)]
end
player:get_meta():set_string("previous_player_data", minetest.serialize(prev_pdata))
local dir_rot = vector.dir_to_rotation(minetest.facedir_to_dir(node.param2))
sitting.attach_player_to_node(player, {pos = vector.add(node_pos, seat_data.pos), rot = vector.add(dir_rot, seat_data.rot), model = rand_model})
minetest.get_meta(node_pos):set_string("is_busy", playername)
return true
end
function sitting.standup_player(player, node_pos)
if not player then
minetest.debug("1")
return
end
local meta = minetest.get_meta(node_pos)
if player:get_player_name() ~= meta:get_string("is_busy") then
minetest.debug("2")
return false
end
local player_meta = player:get_meta()
sitting.detach_player_from_node(player, minetest.deserialize(player_meta:get_string("previous_player_data")))
player_meta:set_string("previous_player_data", "")
meta:set_string("is_busy", "")
return true
end

123
modern/init.lua Normal file
View File

@ -0,0 +1,123 @@
register.register_seat("kitchen_modern_wooden_chair", {
type = "seat",
style = "modern",
material = "wood",
visual_scale = 0.4,
description = "Kitchen Modern Wooden Chair",
mesh = "multidecor_kitchen_modern_wooden_chair.b3d",
tiles = {"multidecor_wooden_material.png"},
bounding_boxes = {
{-0.36, -0.5, -0.36, 0.36, 0.3, 0.26},
{-0.36, -0.5, 0.26, 0.36, 1.3, 0.36}
},
groups = {choppy=1.5}
},
{
pos = {x=0.0, y=0.35, z=0.0},
rot = {x=0, y=0, z=0},
models = {
{
mesh = "multidecor_character_sitting.b3d",
anim = {range = {x=1, y=80}, speed = 15}
}
}
})
register.register_seat("soft_kitchen_modern_wooden_chair", {
type = "seat",
style = "modern",
material = "wood",
visual_scale = 0.4,
description = "Soft Kitchen Modern Wooden Chair",
mesh = "multidecor_soft_kitchen_modern_wooden_chair.b3d",
tiles = {"multidecor_wooden_material.png", "multidecor_wool_material.png"},
bounding_boxes = {
{-0.36, -0.5, -0.36, 0.36, 0.35, 0.26},
{-0.36, -0.5, 0.26, 0.36, 1.3, 0.36}
},
groups = {choppy=1.5}
},
{
pos = {x=0.0, y=0.4, z=0.0},
rot = {x=0, y=0, z=0},
models = {
{
mesh = "multidecor_character_sitting.b3d",
anim = {range = {x=1, y=80}, speed = 15}
}
}
})
register.register_seat("soft_modern_jungle_chair", {
type = "seat",
style = "modern",
material = "wood",
visual_scale = 0.4,
description = "Soft Modern Jungle Chair",
mesh = "multidecor_soft_modern_jungle_chair.b3d",
tiles = {"multidecor_modern_jungle_chair.png"},
bounding_boxes = {
{-0.35, -0.5, -0.35, 0.35, 0.25, 0.25},
{-0.35, -0.5, 0.25, 0.35, 1.2, 0.35}
},
groups = {choppy=1.5}
},
{
pos = {x=0.0, y=0.3, z=0.0},
rot = {x=0, y=0, z=0},
models = {
{
mesh = "multidecor_character_sitting.b3d",
anim = {range = {x=1, y=80}, speed = 15}
}
}
})
register.register_seat("soft_round_modern_metallic_chair", {
type = "seat",
style = "modern",
material = "metal",
visual_scale = 0.4,
description = "Soft Round Modern Metallic Chair",
mesh = "multidecor_round_soft_metallic_chair.b3d",
tiles = {"multidecor_round_soft_metallic_chair.png"},
bounding_boxes = {
{-0.5, -0.5, -0.5, 0.5, 0.25, 0.25},
{-0.5, -0.5, 0.25, 0.5, 0.95, 0.5}
},
groups = {choppy=1.5}
},
{
pos = {x=0.0, y=0.3, z=0.0},
rot = {x=0, y=0, z=0},
models = {
{
mesh = "multidecor_character_sitting.b3d",
anim = {range = {x=1, y=80}, speed = 15}
}
}
})
register.register_seat("round_modern_metallic_stool", {
type = "seat",
style = "modern",
material = "metal",
visual_scale = 0.4,
description = "Round Modern Jungle Stool",
mesh = "multidecor_modern_round_metallic_stool.b3d",
tiles = {"multidecor_modern_round_metallic_stool.png"},
bounding_boxes = {
{-0.4, -0.5, -0.4, 0.4, 0.35, 0.4}
},
groups = {choppy=1.5}
},
{
pos = {x=0.0, y=0.4, z=0.0},
rot = {x=0, y=0, z=0},
models = {
{
mesh = "multidecor_character_sitting.b3d",
anim = {range = {x=1, y=80}, speed = 15}
}
}
})

4
modern/mod.conf Normal file
View File

@ -0,0 +1,4 @@
name = modern
description = Modern-style furniture
depends = decor_api
author = Andrey01

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

3
modpack.conf Normal file
View File

@ -0,0 +1,3 @@
name = multidecor
description = Adds a huge amount of detailed furniture components, decorations and exterior stuff with various designs and styles of each epoch.
author = Andrey01