From cb9bbb09895e9a170e07e7ede898c83fc03c20f3 Mon Sep 17 00:00:00 2001 From: tour Date: Sun, 7 Sep 2025 16:10:53 +0200 Subject: [PATCH 1/4] make some globals local --- nodes_doorlike.lua | 4 ++-- nodes_furniture.lua | 2 +- nodes_pitchfork.lua | 2 +- nodes_water.lua | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nodes_doorlike.lua b/nodes_doorlike.lua index d989c05..469361f 100644 --- a/nodes_doorlike.lua +++ b/nodes_doorlike.lua @@ -17,7 +17,7 @@ local S = cottages.S ----------------------------------------------------------------------------------------------------------- -- propagate shutting/closing of window shutters to window shutters below/above this one -cottages_window_sutter_operate = function( pos, old_node_state_name, new_node_state_name ) +local cottages_window_sutter_operate = function( pos, old_node_state_name, new_node_state_name ) local offsets = {-1,1,-2,2,-3,3}; local stop_up = 0; @@ -298,7 +298,7 @@ minetest.register_node("cottages:gate_open", { -- hatches rotate around their axis -- old facedir: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 -new_facedirs = { 10,19, 4,13, 2,18,22,14,20,16, 0,12,11, 3, 7,21, 9,23, 5, 1, 8,15, 6,17}; +local new_facedirs = { 10,19, 4,13, 2,18,22,14,20,16, 0,12,11, 3, 7,21, 9,23, 5, 1, 8,15, 6,17}; cottages.register_hatch = function( nodename, description, texture, receipe_item ) diff --git a/nodes_furniture.lua b/nodes_furniture.lua index 424764c..8d3662a 100644 --- a/nodes_furniture.lua +++ b/nodes_furniture.lua @@ -509,7 +509,7 @@ cottages.sleep_in_bed = function( pos, node, clicker, itemstack, pointed_thing ) -- search for a second mat right next to this one local offset = {{x=0,z=-1}, {x=-1,z=0}, {x=0,z=1}, {x=1,z=0}}; for i,off in ipairs( offset ) do - node2 = minetest.get_node( {x=pos.x+off.x, y=pos.y, z=pos.z+off.z} ); + local node2 = minetest.get_node( {x=pos.x+off.x, y=pos.y, z=pos.z+off.z} ); if( node2.name == 'cottages:sleeping_mat' or node2.name=='cottages:straw_mat' or node.name=='cottages:sleeping_mat_head' ) then -- if a second mat is found, sleeping is possible allow_sleep = true; diff --git a/nodes_pitchfork.lua b/nodes_pitchfork.lua index 8e0cad9..5743ad1 100644 --- a/nodes_pitchfork.lua +++ b/nodes_pitchfork.lua @@ -8,7 +8,7 @@ local S = cottages.S local add_hay_group = {"farming:straw", "dryplants:reed", "darkage:straw_bale"} for i, v in ipairs(add_hay_group) do if( minetest.registered_items[v]) then - new_groups = minetest.registered_items[v].groups + local new_groups = minetest.registered_items[v].groups new_groups.hay = 3 minetest.override_item(v, {groups = new_groups}) end diff --git a/nodes_water.lua b/nodes_water.lua index 1984779..2bf99a8 100644 --- a/nodes_water.lua +++ b/nodes_water.lua @@ -87,7 +87,7 @@ cottages.water_gen_fill_bucket = function(pos) end -- abort if the water has not been running long enough -- (the player may have removed a bucket before it was full) - start = meta:get_string("fillstarttime") + local start = meta:get_string("fillstarttime") if( (minetest.get_us_time()/1000000) - tonumber(start) < cottages.water_fill_time -2) then return end From 280316e4049328db56f57068c618b32833df9842 Mon Sep 17 00:00:00 2001 From: tour Date: Sun, 7 Sep 2025 18:37:51 +0200 Subject: [PATCH 2/4] rewrite sitting/sleeping - makes use of the modern player_api - fixes a crash due to api-change in set_physics_override - fixes eye offset issue --- mod.conf | 2 +- nodes_furniture.lua | 280 ++++++++++++++++++-------------------------- nodes_straw.lua | 2 +- 3 files changed, 113 insertions(+), 171 deletions(-) diff --git a/mod.conf b/mod.conf index ee8bf92..6bd987b 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = cottages description = Contains a lot of blocks that fit to medieval settlements and small cottages. Comes with hammer & anvil to repair tools. Threshing floor and handmill help process grains etc. -optional_depends = default, farming, stairs, homedecor, intllib, trees, wool, moreblocks, unified_inventory, mcl_core +optional_depends = default, farming, stairs, player_api, homedecor, intllib, trees, wool, moreblocks, unified_inventory, mcl_core author = Sokomine title = Blocks for building cottages. diff --git a/nodes_furniture.lua b/nodes_furniture.lua index 8d3662a..5f87691 100644 --- a/nodes_furniture.lua +++ b/nodes_furniture.lua @@ -98,7 +98,7 @@ minetest.register_node("cottages:sleeping_mat", { paramtype = 'light', paramtype2 = "facedir", walkable = false, - groups = { snappy = 3 }, + groups = { snappy = 3, sleeping_mat = 1 }, sounds = cottages.sounds.leaves, selection_box = { type = "wallmounted", @@ -132,7 +132,7 @@ minetest.register_node("cottages:sleeping_mat_head", { sunlight_propagates = true, paramtype = 'light', paramtype2 = "facedir", - groups = { snappy = 3 }, + groups = { snappy = 3, sleeping_mat = 1 }, sounds = cottages.sounds.leaves, node_box = { type = "fixed", @@ -368,203 +368,145 @@ minetest.register_node("cottages:washing", { -- functions for sitting or sleeping --------------------------------------------------------------------------------------- -cottages.allow_sit = function( player ) +cottages.allow_sit = function( player, pos ) -- no check possible - if( not( player.get_player_velocity )) then - return true; - end - local velo = player:get_player_velocity(); - if( not( velo )) then + if not minetest.is_player(player) then return false; end + + local pname = player:get_player_name() + + local p_above = minetest.get_node( {x=pos.x, y=pos.y+1, z=pos.z}); + if( not( p_above) or not( p_above.name ) or p_above.name ~= 'air' ) then + minetest.chat_send_player( pname, "This place is too narrow for sitting. At least for you!") + return + end + + local velo = player:get_player_velocity() local max_velo = 0.0001; - if( math.abs(velo.x) < max_velo - and math.abs(velo.y) < max_velo - and math.abs(velo.z) < max_velo ) then + if vector.length(velo) < max_velo then return true; end return false; end -cottages.sit_on_bench = function( pos, node, clicker, itemstack, pointed_thing ) - if( not( clicker ) or not( default.player_get_animation ) or not( cottages.allow_sit( clicker ))) then - return; +cottages.is_bed = function(pos, node) + if node.name == "cottages:bed_head" then + local second_pos = vector.subtract(pos, minetest.facedir_to_dir(node.param2)) + local second_node = minetest.get_node(second_pos) + return second_node.name == "cottages:bed_foot", second_pos + elseif node.name == "cottages:bed_foot" then + local second_pos = vector.add(pos, minetest.facedir_to_dir(node.param2)) + local second_node = minetest.get_node(second_pos) + return second_node.name == "cottages:bed_head", second_pos + elseif minetest.get_item_group(node.name, "sleeping_mat") ~= 0 then + local search_offsets = { + vector.new(1, 0, 0), + vector.new(-1, 0, 0), + vector.new(0, 0, 1), + vector.new(0, 0, -1) + } + for _, offset in ipairs(search_offsets) do + local second_pos = vector.add(pos, offset) + local second_node = minetest.get_node(second_pos) + if minetest.get_item_group(second_node.name, "sleeping_mat") ~= 0 then + return true, second_pos + end + end end + return false +end - local animation = default.player_get_animation( clicker ); - local pname = clicker:get_player_name(); +cottages.stand = function (player) + local pname = player:get_player_name() + player_api.player_attached[pname] = false + player:set_physics_override({speed = 1, jump = 1, gravity = 1}) + player_api.set_animation(player, "stand", 30) +end - if( animation and animation.animation=="sit") then - default.player_attached[pname] = false +cottages.sit = function (player) + local pname = player:get_player_name() + player_api.set_animation(player, "sit", 30) + player:set_physics_override({speed = 0, jump = 0, gravity = 0}) + player_api.player_attached[pname] = true +end + +cottages.lay = function (player) + local pname = player:get_player_name() + player_api.set_animation(player, "lay", 30) + player:set_physics_override({speed = 0, jump = 0, gravity = 0}) + player_api.player_attached[pname] = true +end + +cottages.sit_on_bench = function( pos, node, clicker, itemstack, pointed_thing ) + if not(player_api and cottages.allow_sit(clicker, pos)) then + return; + end + + local animation = player_api.get_animation(clicker) + + if (animation and animation.animation=="sit") then clicker:set_pos({x=pos.x,y=pos.y-0.5,z=pos.z}) - clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0}) - clicker:set_physics_override(1, 1, 1) - default.player_set_animation(clicker, "stand", 30) + cottages.stand(clicker, pos) else -- the bench is not centered; prevent the player from sitting on air - local p2 = {x=pos.x, y=pos.y, z=pos.z}; - if not( node ) or node.param2 == 0 then - p2.z = p2.z+0.3; - elseif node.param2 == 1 then - p2.x = p2.x+0.3; - elseif node.param2 == 2 then - p2.z = p2.z-0.3; - elseif node.param2 == 3 then - p2.x = p2.x-0.3; - end + local offset = minetest.facedir_to_dir(node.param2) + local p2 = vector.add(pos, vector.multiply(offset, 0.3)) - clicker:set_eye_offset({x=0,y=-7,z=2}, {x=0,y=0,z=0}) clicker:set_pos( p2 ) - default.player_set_animation(clicker, "sit", 30) - clicker:set_physics_override(0, 0, 0) - default.player_attached[pname] = true + cottages.sit(clicker) end end cottages.sleep_in_bed = function( pos, node, clicker, itemstack, pointed_thing ) - if( not( clicker ) or not( node ) or not( node.name ) or not( pos ) or not( cottages.allow_sit( clicker))) then + if not(player_api and cottages.allow_sit(clicker, pos)) then return; end - local animation = default.player_get_animation( clicker ); - local pname = clicker:get_player_name(); + local animation = player_api.get_animation(clicker) + local pname = clicker:get_player_name() - local p_above = minetest.get_node( {x=pos.x, y=pos.y+1, z=pos.z}); - if( not( p_above) or not( p_above.name ) or p_above.name ~= 'air' ) then - minetest.chat_send_player( pname, "This place is too narrow for sleeping. At least for you!"); - return; - end - - local place_name = 'place'; -- if only one node is present, the player can only sit; -- sleeping requires a bed head+foot or two sleeping mats - local allow_sleep = false; - local new_animation = 'sit'; + local is_bed, second_pos = cottages.is_bed(pos, node) - -- let players get back up - if( animation and animation.animation=="lay" ) then - default.player_attached[pname] = false - clicker:set_pos({x=pos.x,y=pos.y-0.5,z=pos.z}) - clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0}) - clicker:set_physics_override(1, 1, 1) - default.player_set_animation(clicker, "stand", 30) - minetest.chat_send_player( pname, 'That was enough sleep for now. You stand up again.'); - return; + local player_pos = vector.copy(pos) + local place_name = "place" + if is_bed then + player_pos = vector.divide(vector.add(pos, second_pos), 2) end - - local second_node_pos = {x=pos.x, y=pos.y, z=pos.z}; - -- the node that will contain the head of the player - local p = {x=pos.x, y=pos.y, z=pos.z}; - -- the player's head is pointing in this direction - local dir = node.param2; - -- it would be odd to sleep in half a bed - if( node.name=='cottages:bed_head' ) then - if( node.param2==0 ) then - second_node_pos.z = pos.z-1; - elseif( node.param2==1) then - second_node_pos.x = pos.x-1; - elseif( node.param2==2) then - second_node_pos.z = pos.z+1; - elseif( node.param2==3) then - second_node_pos.x = pos.x+1; - end - local node2 = minetest.get_node( second_node_pos ); - if( not( node2 ) or not( node2.param2 ) or not( node.param2 ) - or node2.name ~= 'cottages:bed_foot' - or node2.param2 ~= node.param2 ) then - allow_sleep = false; - else - allow_sleep = true; - end - place_name = 'bed'; - - -- if the player clicked on the foot of the bed, locate the head - elseif( node.name=='cottages:bed_foot' ) then - if( node.param2==2 ) then - second_node_pos.z = pos.z-1; - elseif( node.param2==3) then - second_node_pos.x = pos.x-1; - elseif( node.param2==0) then - second_node_pos.z = pos.z+1; - elseif( node.param2==1) then - second_node_pos.x = pos.x+1; - end - local node2 = minetest.get_node( second_node_pos ); - if( not( node2 ) or not( node2.param2 ) or not( node.param2 ) - or node2.name ~= 'cottages:bed_head' - or node2.param2 ~= node.param2 ) then - allow_sleep = false; - else - allow_sleep = true; - end - if( allow_sleep==true ) then - p = {x=second_node_pos.x, y=second_node_pos.y, z=second_node_pos.z}; - end - place_name = 'bed'; - - elseif( node.name=='cottages:sleeping_mat' or node.name=='cottages:straw_mat' or node.name=='cottages:sleeping_mat_head') then - place_name = 'mat'; - dir = node.param2; - allow_sleep = false; - -- search for a second mat right next to this one - local offset = {{x=0,z=-1}, {x=-1,z=0}, {x=0,z=1}, {x=1,z=0}}; - for i,off in ipairs( offset ) do - local node2 = minetest.get_node( {x=pos.x+off.x, y=pos.y, z=pos.z+off.z} ); - if( node2.name == 'cottages:sleeping_mat' or node2.name=='cottages:straw_mat' or node.name=='cottages:sleeping_mat_head' ) then - -- if a second mat is found, sleeping is possible - allow_sleep = true; - dir = i-1; - end - end - end - - -- set the right height for the bed - if( place_name=='bed' ) then - p.y = p.y+0.4; - end - if( allow_sleep==true ) then - -- set the right position (middle of the bed) - if( dir==0 ) then - p.z = p.z-0.5; - elseif( dir==1 ) then - p.x = p.x-0.5; - elseif( dir==2 ) then - p.z = p.z+0.5; - elseif( dir==3 ) then - p.x = p.x+0.5; - end - end - - if( default.player_attached[pname] and animation.animation=="sit") then - -- just changing the animation... - if( allow_sleep==true ) then - default.player_set_animation(clicker, "lay", 30) - clicker:set_eye_offset({x=0,y=-14,z=2}, {x=0,y=0,z=0}) - minetest.chat_send_player( pname, 'You lie down and take a nap. A right-click will wake you up.'); - return; - -- no sleeping on this place - else - default.player_attached[pname] = false - clicker:set_pos({x=pos.x,y=pos.y-0.5,z=pos.z}) - clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0}) - clicker:set_physics_override(1, 1, 1) - default.player_set_animation(clicker, "stand", 30) - minetest.chat_send_player( pname, 'That was enough sitting around for now. You stand up again.'); - return; - end - end - - - clicker:set_eye_offset({x=0,y=-7,z=2}, {x=0,y=0,z=0}) - clicker:set_pos( p ); - default.player_set_animation(clicker, new_animation, 30) - clicker:set_physics_override(0, 0, 0) - default.player_attached[pname] = true - - if( allow_sleep==true) then - minetest.chat_send_player( pname, 'Aaah! What a comftable '..place_name..'. A second right-click will let you sleep.'); + if minetest.get_item_group(node.name, "sleeping_mat") ~= 0 then + player_pos.y = player_pos.y - 0.5 + 1/16 + place_name = "mat" else - minetest.chat_send_player( pname, 'Comftable, but not good enough for a nap. Right-click again if you want to get back up.'); + player_pos.y = player_pos.y + 0.3 + place_name = "bed" + end + + if is_bed then + if (animation and (animation.animation=="lay")) then -- let the player up + clicker:set_pos({x=pos.x,y=pos.y-0.5,z=pos.z}) + cottages.stand(clicker) + minetest.chat_send_player( pname, 'That was enough sleep for now. You stand up again.'); + elseif (animation and animation.animation=="sit") then + clicker:set_pos( player_pos ) + cottages.lay(clicker) + minetest.chat_send_player( pname, 'You lie down and take a nap. A right-click will wake you up.'); + else + clicker:set_pos( player_pos ) + cottages.sit(clicker) + minetest.chat_send_player( pname, 'Aaah! What a comftable '..place_name..'. A second right-click will let you sleep.'); + end + else + if (animation and animation.animation=="sit") then -- let the player up + clicker:set_pos({x=pos.x,y=pos.y-0.5,z=pos.z}) + cottages.stand(clicker) + minetest.chat_send_player( pname, 'That was enough sitting around for now. You stand up again.') + else + clicker:set_pos( player_pos ) + cottages.sit(clicker) + minetest.chat_send_player( pname, 'Comftable, but not good enough for a nap. Right-click again if you want to get back up.'); + end end end diff --git a/nodes_straw.lua b/nodes_straw.lua index f01eb0f..e7ed5ca 100644 --- a/nodes_straw.lua +++ b/nodes_straw.lua @@ -61,7 +61,7 @@ minetest.register_node("cottages:straw_mat", { paramtype = 'light', paramtype2 = "facedir", walkable = false, - groups = { hay = 3, snappy = 2, oddly_breakable_by_hand = 2, flammable=3 }, + groups = { hay = 3, snappy = 2, oddly_breakable_by_hand = 2, flammable=3 , sleeping_mat=1, }, sounds = cottages.sounds.leaves, node_box = { type = "fixed", From f93097c944099a9690127d712657fb68adf88d2a Mon Sep 17 00:00:00 2001 From: tour Date: Sun, 7 Sep 2025 22:19:02 +0200 Subject: [PATCH 3/4] fix player animations when they leave sit/sleep furniture in unintended ways --- nodes_furniture.lua | 52 ++++++++++++++++++++++++++++++++++++++++----- nodes_straw.lua | 2 +- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/nodes_furniture.lua b/nodes_furniture.lua index 5f87691..7339a53 100644 --- a/nodes_furniture.lua +++ b/nodes_furniture.lua @@ -22,7 +22,7 @@ minetest.register_node("cottages:bed_foot", { tiles = {"cottages_beds_bed_top_bottom.png", cottages.texture_furniture, "cottages_beds_bed_side.png", "cottages_beds_bed_side.png", "cottages_beds_bed_side.png", "cottages_beds_bed_side.png"}, paramtype = "light", paramtype2 = "facedir", - groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,animates_player=1}, sounds = cottages.sounds.wood, node_box = { type = "fixed", @@ -57,7 +57,7 @@ minetest.register_node("cottages:bed_head", { tiles = {"cottages_beds_bed_top_top.png", cottages.texture_furniture, "cottages_beds_bed_side_top_r.png", "cottages_beds_bed_side_top_l.png", cottages.texture_furniture, "cottages_beds_bed_side.png"}, paramtype = "light", paramtype2 = "facedir", - groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,animates_player=1}, sounds = cottages.sounds.wood, node_box = { type = "fixed", @@ -98,7 +98,7 @@ minetest.register_node("cottages:sleeping_mat", { paramtype = 'light', paramtype2 = "facedir", walkable = false, - groups = { snappy = 3, sleeping_mat = 1 }, + groups = { snappy = 3, sleeping_mat = 1, animates_player = 1}, sounds = cottages.sounds.leaves, selection_box = { type = "wallmounted", @@ -132,7 +132,7 @@ minetest.register_node("cottages:sleeping_mat_head", { sunlight_propagates = true, paramtype = 'light', paramtype2 = "facedir", - groups = { snappy = 3, sleeping_mat = 1 }, + groups = { snappy = 3, sleeping_mat = 1, animates_player = 1 }, sounds = cottages.sounds.leaves, node_box = { type = "fixed", @@ -161,7 +161,7 @@ minetest.register_node("cottages:bench", { tiles = {"cottages_minimal_wood.png", "cottages_minimal_wood.png", "cottages_minimal_wood.png", "cottages_minimal_wood.png", "cottages_minimal_wood.png", "cottages_minimal_wood.png"}, paramtype = "light", paramtype2 = "facedir", - groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,animates_player=1}, sounds = cottages.sounds.wood, node_box = { type = "fixed", @@ -417,11 +417,49 @@ cottages.is_bed = function(pos, node) return false end + +-- players might leave beds/benches in unintended ways (or other mods mess up with the logic) +-- we need to make sure they won't be stuck with their last animation +local attached_players = {} +local fix_player_animation_job + +local function fix_player_animations(active_loop) + if fix_player_animation_job and not active_loop then -- we already have a loop running + return + end + local continue_looping = false + for playername, last_pos in pairs(attached_players) do + -- is the player still at the position where we expect him to be + local player = minetest.get_player_by_name(playername) + local player_pos = player and vector.round(player:get_pos()) + local same_position = player_pos and vector.equals(player_pos, last_pos) + + -- is the node still around (might be dug/whatever) + local nodename = minetest.get_node(last_pos).name + local node_animates_player = minetest.get_item_group(nodename, "animates_player") ~= 0 + + if same_position and node_animates_player then + continue_looping = true + else + if player then + cottages.stand(player) + end + attached_players[playername] = nil + end + end + if continue_looping then + fix_player_animation_job = minetest.after(1, fix_player_animations, true) + else + fix_player_animation_job = nil + end +end + cottages.stand = function (player) local pname = player:get_player_name() player_api.player_attached[pname] = false player:set_physics_override({speed = 1, jump = 1, gravity = 1}) player_api.set_animation(player, "stand", 30) + attached_players[pname] = nil end cottages.sit = function (player) @@ -429,6 +467,8 @@ cottages.sit = function (player) player_api.set_animation(player, "sit", 30) player:set_physics_override({speed = 0, jump = 0, gravity = 0}) player_api.player_attached[pname] = true + attached_players[pname] = vector.round(player:get_pos()) + fix_player_animations() end cottages.lay = function (player) @@ -436,6 +476,8 @@ cottages.lay = function (player) player_api.set_animation(player, "lay", 30) player:set_physics_override({speed = 0, jump = 0, gravity = 0}) player_api.player_attached[pname] = true + attached_players[pname] = vector.round(player:get_pos()) + fix_player_animations() end cottages.sit_on_bench = function( pos, node, clicker, itemstack, pointed_thing ) diff --git a/nodes_straw.lua b/nodes_straw.lua index e7ed5ca..1d30a9b 100644 --- a/nodes_straw.lua +++ b/nodes_straw.lua @@ -61,7 +61,7 @@ minetest.register_node("cottages:straw_mat", { paramtype = 'light', paramtype2 = "facedir", walkable = false, - groups = { hay = 3, snappy = 2, oddly_breakable_by_hand = 2, flammable=3 , sleeping_mat=1, }, + groups = { hay = 3, snappy = 2, oddly_breakable_by_hand = 2, flammable=3 , sleeping_mat=1, animates_player=1 }, sounds = cottages.sounds.leaves, node_box = { type = "fixed", From e2fb23b79efc69a791d545e44b7c61a2d8af552f Mon Sep 17 00:00:00 2001 From: tour Date: Wed, 12 Nov 2025 19:09:44 +0100 Subject: [PATCH 4/4] fix possible mod conflicts - adds player_monoids support - reset physics_overrides when another mod removes us from player_api.player_attached --- mod.conf | 2 +- nodes_furniture.lua | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/mod.conf b/mod.conf index 6bd987b..842a87c 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = cottages description = Contains a lot of blocks that fit to medieval settlements and small cottages. Comes with hammer & anvil to repair tools. Threshing floor and handmill help process grains etc. -optional_depends = default, farming, stairs, player_api, homedecor, intllib, trees, wool, moreblocks, unified_inventory, mcl_core +optional_depends = default, farming, stairs, player_api, homedecor, intllib, trees, wool, moreblocks, unified_inventory, mcl_core, player_monoids author = Sokomine title = Blocks for building cottages. diff --git a/nodes_furniture.lua b/nodes_furniture.lua index 7339a53..2175e99 100644 --- a/nodes_furniture.lua +++ b/nodes_furniture.lua @@ -14,6 +14,7 @@ -- TODO: change the textures of the bed (make the clothing white, foot path not entirely covered with cloth) local S = cottages.S +local has_player_monoids = minetest.get_modpath("player_monoids") -- a bed without functionality - just decoration minetest.register_node("cottages:bed_foot", { @@ -375,6 +376,10 @@ cottages.allow_sit = function( player, pos ) end local pname = player:get_player_name() + if player_api.player_attached[pname] then + -- another mod controls the player, we might break it's logic + return false + end local p_above = minetest.get_node( {x=pos.x, y=pos.y+1, z=pos.z}); if( not( p_above) or not( p_above.name ) or p_above.name ~= 'air' ) then @@ -438,7 +443,11 @@ local function fix_player_animations(active_loop) local nodename = minetest.get_node(last_pos).name local node_animates_player = minetest.get_item_group(nodename, "animates_player") ~= 0 - if same_position and node_animates_player then + -- check for + -- teleport (p.ex. /spawn) + -- node destruction + -- other mods detaching the player + if same_position and node_animates_player and player_api.player_attached[playername] then continue_looping = true else if player then @@ -457,7 +466,13 @@ end cottages.stand = function (player) local pname = player:get_player_name() player_api.player_attached[pname] = false - player:set_physics_override({speed = 1, jump = 1, gravity = 1}) + if has_player_monoids then + player_monoids.speed:del_change(player, "cottages:furniture") + player_monoids.jump:del_change(player, "cottages:furniture") + player_monoids.gravity:del_change(player, "cottages:furniture") + else + player:set_physics_override({speed = 1, jump = 1, gravity = 1}) + end player_api.set_animation(player, "stand", 30) attached_players[pname] = nil end @@ -465,7 +480,13 @@ end cottages.sit = function (player) local pname = player:get_player_name() player_api.set_animation(player, "sit", 30) - player:set_physics_override({speed = 0, jump = 0, gravity = 0}) + if has_player_monoids then + player_monoids.speed:add_change(player, 0, "cottages:furniture") + player_monoids.jump:add_change(player, 0, "cottages:furniture") + player_monoids.gravity:add_change(player, 0, "cottages:furniture") + else + player:set_physics_override({speed = 0, jump = 0, gravity = 0}) + end player_api.player_attached[pname] = true attached_players[pname] = vector.round(player:get_pos()) fix_player_animations() @@ -474,7 +495,13 @@ end cottages.lay = function (player) local pname = player:get_player_name() player_api.set_animation(player, "lay", 30) - player:set_physics_override({speed = 0, jump = 0, gravity = 0}) + if has_player_monoids then + player_monoids.speed:add_change(player, 0, "cottages:furniture") + player_monoids.jump:add_change(player, 0, "cottages:furniture") + player_monoids.gravity:add_change(player, 0, "cottages:furniture") + else + player:set_physics_override({speed = 0, jump = 0, gravity = 0}) + end player_api.player_attached[pname] = true attached_players[pname] = vector.round(player:get_pos()) fix_player_animations()