This repository has been archived on 2023-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
mcl_decor/api.lua

124 lines
3.7 KiB
Lua
Raw Normal View History

2022-02-22 10:30:42 +01:00
-- mcl_decor/api.lua
local S = minetest.get_translator(minetest.get_current_modname())
-- originally from the ts_furniture mod (which is from cozy) by Thomas--S // https://github.com/minetest-mods/ts_furniture/
mcl_decor.sit = function(pos, _, player)
local name = player:get_player_name()
if not mcl_player.player_attached[name] then
if vector.length(player:get_player_velocity()) > 0 then
minetest.chat_send_player(player:get_player_name(), S("You have to stop moving before sitting down!"))
return
end
player:move_to(pos)
player:set_eye_offset({x = 0, y = -7, z = 2}, {x = 0, y = 0, z = 0})
player:set_physics_override(0, 0, 0)
mcl_player.player_attached[name] = true
minetest.after(0.1, function()
if player then
mcl_player.player_set_animation(player, "sit" , 30)
end
end)
else
mcl_decor.stand(player, name)
end
end
mcl_decor.up = function(_, _, player)
local name = player:get_player_name()
if mcl_player.player_attached[name] then
mcl_decor.stand(player, name)
end
end
mcl_decor.stand = function(player, name)
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
player:set_physics_override(1, 1, 1)
mcl_player.player_attached[name] = false
mcl_player.player_set_animation(player, "stand", 30)
end
if not minetest.get_modpath("mcl_cozy") then
minetest.register_globalstep(function(dtime)
local players = minetest.get_connected_players()
for i = 1, #players do
local player = players[i]
local name = player:get_player_name()
local ctrl = player:get_player_control()
if mcl_player.player_attached[name] and not player:get_attach() and
(ctrl.up or ctrl.down or ctrl.left or ctrl.right or ctrl.jump or ctrl.sneak) then
mcl_decor.up(nil, nil, player)
end
end
end)
end
2022-02-22 10:30:42 +01:00
function mcl_decor:register_chair(name, def)
minetest.register_node(name, {
description = def.description,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.25, 0, 0.125, 0.25, 0.5, 0.25}, -- back
{-0.25, -0.125, -0.25, 0.25, 0, 0.25}, -- seat
{-0.25, -0.5, 0.125, -0.125, -0.125, 0.25}, -- 1st leg
{0.125, -0.5, -0.25, 0.25, -0.125, -0.125}, -- 2nd leg
{0.125, -0.5, 0.125, 0.25, -0.125, 0.25}, -- 3rd leg
{-0.25, -0.5, -0.25, -0.125, -0.125, -0.125}, -- 4th leg
}
},
tiles = def.tiles,
is_ground_content = false,
paramtype = "light",
paramtype2 = "facedir",
stack_max = 64,
sunlight_propagates = true,
selection_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0.5, 0.25 },
},
--[[
2022-02-22 10:30:42 +01:00
collision_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0.5, 0.25 },
},
]]
2022-02-22 10:30:42 +01:00
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
on_rightclick = mcl_decor.sit
2022-02-22 10:30:42 +01:00
})
end
function mcl_decor:register_table(name, def)
minetest.register_node(name, {
description = def.description,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -0.5, 0.375, -0.5, 0.5, 0.5, 0.5 }, -- top
{ -0.4375, -0.5, -0.4375, -0.3125, 0.375, -0.3125 }, -- 1st leg
{ 0.3125, -0.5, -0.4375, 0.4375, 0.375, -0.3125 }, -- 2nd leg
{ 0.3125, -0.5, 0.3125, 0.4375, 0.375, 0.4375 }, -- 3rd leg
{ -0.4375, -0.5, 0.3125, -0.3125, 0.375, 0.4375 }, -- 4th leg
}
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }, -- default 1x1 selection box (to override that weird selection of just the nodebox itself)
},
tiles = def.tiles,
is_ground_content = false,
paramtype = "light",
stack_max = 64,
sunlight_propagates = true,
groups = def.groups,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
-- TODO: make tables connect with each other???
})
end