From b2e1eea202ccf2b0959837aa2c92ba5873d4f7c1 Mon Sep 17 00:00:00 2001 From: rudzik8 Date: Fri, 25 Feb 2022 15:09:33 +0700 Subject: [PATCH] Add ability to sit on the chairs from ts_furniture mod also, delete these comments from register.lua about nodeboxes for Gravel Path. currently the sitting feature works a bit weird, i'll try to fix it (BUT SITTING WORKS FINALLY YAAAYYY) --- api.lua | 61 +++++++++++++++++++++++++++++++++++++++++++--------- register.lua | 14 ++++++------ 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/api.lua b/api.lua index b504056..f41c805 100644 --- a/api.lua +++ b/api.lua @@ -1,5 +1,55 @@ -- mcl_decor/api.lua +-- 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(), 'You can only sit down when you are not moving.') + 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 + + + function mcl_decor:register_chair(name, def) minetest.register_node(name, { description = def.description, @@ -35,16 +85,7 @@ function mcl_decor:register_chair(name, def) _mcl_hardness = def._mcl_hardness, _mcl_blast_resistance = def._mcl_blast_resistance, sounds = def.sounds, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - if not clicker:is_player() then - return itemstack - end - mcl_player.player_set_animation(clicker, "sit_mount", 30) - pos.y = pos.y-0.5 - clicker:setpos(pos) - clicker:set_hp(20) - return itemstack - end + on_rightclick = mcl_decor.sit }) end diff --git a/register.lua b/register.lua index ffe6ee2..b8ab8fd 100644 --- a/register.lua +++ b/register.lua @@ -44,13 +44,13 @@ minetest.register_node("mcl_decor:gravel_path", { node_box = { type = "fixed", fixed = { - {-0.4375, -0.5, -0.4375, -0.125, -0.4375, -0.125}, -- NodeBox1 - {-0.125, -0.5, -0.0625, 0.0625, -0.4375, 0.125}, -- NodeBox2 - {-0.3125, -0.5, 0.1875, -0.0625, -0.4375, 0.4375}, -- NodeBox3 - {0.0625, -0.5, -0.375, 0.25, -0.4375, -0.1875}, -- NodeBox4 - {0.125, -0.5, 0.125, 0.375, -0.4375, 0.375}, -- NodeBox5 - {0.25, -0.5, -0.125, 0.375, -0.4375, 0}, -- NodeBox6 - {-0.4375, -0.5, 0, -0.3125, -0.4375, 0.125}, -- NodeBox7 + {-0.4375, -0.5, -0.4375, -0.125, -0.4375, -0.125}, + {-0.125, -0.5, -0.0625, 0.0625, -0.4375, 0.125}, + {-0.3125, -0.5, 0.1875, -0.0625, -0.4375, 0.4375}, + {0.0625, -0.5, -0.375, 0.25, -0.4375, -0.1875}, + {0.125, -0.5, 0.125, 0.375, -0.4375, 0.375}, + {0.25, -0.5, -0.125, 0.375, -0.4375, 0}, + {-0.4375, -0.5, 0, -0.3125, -0.4375, 0.125}, } }, selection_box = {