From f3580efcedef49a75a6ea60dc48a43b6ae7ebb8c Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Mar 2021 11:32:17 +0100 Subject: [PATCH 1/8] Separate Head / Body rotation (Implement #1189) --- mods/PLAYER/mcl_playerplus/init.lua | 88 ++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 26 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index e376c0f0ac..1f66b344f7 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -33,6 +33,53 @@ local dir_to_pitch = function(dir) return -math.atan2(-dir.y, xz) end +local player_vel_yaws = {} + +function limit_vel_yaw(player_vel_yaw, yaw) + if player_vel_yaw < 0 then + player_vel_yaw = player_vel_yaw + 360 + end + + if yaw < 0 then + yaw = yaw + 360 + end + + if math.abs(player_vel_yaw - yaw) > 40 then + local player_vel_yaw_nm, yaw_nm = player_vel_yaw, yaw + if player_vel_yaw > yaw then + player_vel_yaw_nm = player_vel_yaw - 360 + else + yaw_nm = yaw - 360 + end + if math.abs(player_vel_yaw_nm - yaw_nm) > 40 then + local diff = math.abs(player_vel_yaw - yaw) + if diff > 180 and diff < 185 or diff < 180 and diff > 175 then + player_vel_yaw = yaw + elseif diff < 180 then + if player_vel_yaw < yaw then + player_vel_yaw = yaw - 40 + else + player_vel_yaw = yaw + 40 + end + else + if player_vel_yaw < yaw then + player_vel_yaw = yaw + 40 + else + player_vel_yaw = yaw - 40 + end + end + end + end + + if player_vel_yaw < 0 then + player_vel_yaw = player_vel_yaw + 360 + elseif player_vel_yaw > 360 then + player_vel_yaw = player_vel_yaw - 360 + end + + return player_vel_yaw +end + local pitch, name, node_stand, node_stand_below, node_head, node_feet, pos minetest.register_globalstep(function(dtime) @@ -45,19 +92,20 @@ minetest.register_globalstep(function(dtime) local controls = player:get_player_control() name = player:get_player_name() + local meta = player:get_meta() + local player_velocity = player:get_velocity() or player:get_player_velocity() -- controls head bone - local pitch = degrees(player:get_look_vertical()) * -1 - local yaw = degrees(player:get_look_horizontal()) * -1 + local pitch = - degrees(player:get_look_vertical()) + local yaw = degrees(player:get_look_horizontal()) - local player_vel_yaw = 0 - - if degrees(dir_to_yaw(player_velocity)) == 0 then - yaw = 0 - else - player_vel_yaw = degrees(dir_to_yaw(player_velocity)) + local player_vel_yaw = degrees(dir_to_yaw(player_velocity)) + if player_vel_yaw == 0 then + player_vel_yaw = player_vel_yaws[name] or yaw end + player_vel_yaw = limit_vel_yaw(player_vel_yaw, yaw) + player_vel_yaws[name] = player_vel_yaw -- controls right and left arms pitch when shooting a bow or punching if string.find(player:get_wielded_item():get_name(), "mcl_bows:bow") and controls.RMB and not controls.LMB and not controls.up and not controls.down and not controls.left and not controls.right then @@ -80,42 +128,30 @@ minetest.register_globalstep(function(dtime) player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,0,0)) elseif get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 and player:get_attach() == nil and is_sprinting(name) == true then -- set head pitch and yaw when swimming - player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90-degrees(dir_to_pitch(player_velocity)),yaw - player_vel_yaw * -1,0)) + player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90-degrees(dir_to_pitch(player_velocity)),player_vel_yaw - yaw,0)) -- sets eye height, and nametag color accordingly player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) -- control body bone when swimming - player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,player_vel_yaw * -1 - yaw + 180,0)) + player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0)) elseif player:get_attach() == nil then -- sets eye height, and nametag color accordingly player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.8,0.35}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) - if player_velocity.x > 0.35 or player_velocity.z > 0.35 or player_velocity.x < -0.35 or player_velocity.z < -0.35 then - if player_vel_yaw * -1 - yaw < 90 or player_vel_yaw * -1 - yaw > 270 then - -- controls head and Body_Control bones while moving backwards - player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,yaw - player_vel_yaw * -1,0)) - player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,player_vel_yaw * -1 - yaw,0)) - else - -- controls head and Body_Control bones while moving forwards - player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,yaw - player_vel_yaw * -1 + 180,0)) - player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,player_vel_yaw * -1 - yaw + 180,0)) - end - else - player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,0,0)) - player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,0,0)) - end + player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch, player_vel_yaw - yaw, 0)) + player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0, -player_vel_yaw + yaw, 0)) else local attached = player:get_attach(parent) local attached_yaw = degrees(attached:get_yaw()) player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.8,0.35}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) - player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,degrees(player:get_look_horizontal()) * -1 + attached_yaw,0)) + player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch, -limit_vel_yaw(yaw, attached_yaw) + attached_yaw, 0)) player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,0,0)) end if mcl_playerplus_internal[name].jump_cooldown > 0 then mcl_playerplus_internal[name].jump_cooldown = mcl_playerplus_internal[name].jump_cooldown - dtime end - if player:get_player_control().jump and mcl_playerplus_internal[name].jump_cooldown <= 0 then + if controls.jump and mcl_playerplus_internal[name].jump_cooldown <= 0 then pos = player:get_pos() From f3c37f49b9b8ab67cc1769ab2afb7a756a48687d Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Mar 2021 11:37:12 +0100 Subject: [PATCH 2/8] Only extinguish flame arrow on removal --- mods/ITEMS/mcl_bows/arrow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 61cb26f33e..1b7d63c13d 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -337,8 +337,8 @@ ARROW_ENTITY.on_step = function(self, dtime) minetest.sound_play({name="mcl_bows_hit_other", gain=0.3}, {pos=self.object:get_pos(), max_hear_distance=16}, true) end end - mcl_burning.extinguish(self.object) if not obj:is_player() then + mcl_burning.extinguish(self.object) self.object:remove() end return From 4ff987ccc5705ec69d94c2ad0d07f8ecaaf27e71 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Mar 2021 11:39:04 +0100 Subject: [PATCH 3/8] Remove burning sound for objects --- mods/ENTITIES/mcl_burning/api.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_burning/api.lua b/mods/ENTITIES/mcl_burning/api.lua index 723b29a8bd..cd1dfbd1c2 100644 --- a/mods/ENTITIES/mcl_burning/api.lua +++ b/mods/ENTITIES/mcl_burning/api.lua @@ -145,7 +145,7 @@ function mcl_burning.set_on_fire(obj, burn_time, reason) end if old_burn_time <= burn_time then - local sound_id = mcl_burning.get(obj, "int", "sound_id") + --[[local sound_id = mcl_burning.get(obj, "int", "sound_id") if sound_id == 0 then sound_id = minetest.sound_play("fire_fire", { object = obj, @@ -153,7 +153,7 @@ function mcl_burning.set_on_fire(obj, burn_time, reason) max_hear_distance = 16, loop = true, }) + 1 - end + end]]-- local hud_id if obj:is_player() then @@ -171,7 +171,7 @@ function mcl_burning.set_on_fire(obj, burn_time, reason) mcl_burning.set(obj, "float", "burn_time", burn_time) mcl_burning.set(obj, "string", "reason", reason) mcl_burning.set(obj, "int", "hud_id", hud_id) - mcl_burning.set(obj, "int", "sound_id", sound_id) + --mcl_burning.set(obj, "int", "sound_id", sound_id) local fire_entity = minetest.add_entity(obj:get_pos(), "mcl_burning:fire") local minp, maxp = mcl_burning.get_collisionbox(obj) @@ -194,8 +194,8 @@ end function mcl_burning.extinguish(obj) if mcl_burning.is_burning(obj) then - local sound_id = mcl_burning.get(obj, "int", "sound_id") - 1 - minetest.sound_stop(sound_id) + --local sound_id = mcl_burning.get(obj, "int", "sound_id") - 1 + --minetest.sound_stop(sound_id) if obj:is_player() then local hud_id = mcl_burning.get(obj, "int", "hud_id") - 1 @@ -206,7 +206,7 @@ function mcl_burning.extinguish(obj) mcl_burning.set(obj, "float", "burn_time") mcl_burning.set(obj, "float", "damage_timer") mcl_burning.set(obj, "int", "hud_id") - mcl_burning.set(obj, "int", "sound_id") + --mcl_burning.set(obj, "int", "sound_id") end end From 55df2a57f4cdc5b204684f8ce9cc77ffc9ded719 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Mar 2021 11:40:46 +0100 Subject: [PATCH 4/8] Fix #1336 --- mods/ENTITIES/mcl_burning/api.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mods/ENTITIES/mcl_burning/api.lua b/mods/ENTITIES/mcl_burning/api.lua index cd1dfbd1c2..7f65b3434f 100644 --- a/mods/ENTITIES/mcl_burning/api.lua +++ b/mods/ENTITIES/mcl_burning/api.lua @@ -117,6 +117,10 @@ function mcl_burning.damage(obj) end function mcl_burning.set_on_fire(obj, burn_time, reason) + if obj:get_hp() < 0 then + return + end + local luaentity = obj:get_luaentity() if luaentity and luaentity.fire_resistant then return From ecd27a4cdbbecc85037881368c7a9e4076625807 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Mar 2021 11:41:29 +0100 Subject: [PATCH 5/8] Initialize burning HUD with proper texture --- mods/ENTITIES/mcl_burning/api.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_burning/api.lua b/mods/ENTITIES/mcl_burning/api.lua index 7f65b3434f..4eac333a26 100644 --- a/mods/ENTITIES/mcl_burning/api.lua +++ b/mods/ENTITIES/mcl_burning/api.lua @@ -167,7 +167,7 @@ function mcl_burning.set_on_fire(obj, burn_time, reason) hud_elem_type = "image", position = {x = 0.5, y = 0.5}, scale = {x = -100, y = -100}, - text = "fire_basic_flame.png", + text = "mcl_burning_hud_flame_animated.png", z_index = 1000, }) + 1 end From 906aa3b434e306e7b3c556b4e1cfdd5baad5858b Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Mar 2021 11:46:35 +0100 Subject: [PATCH 6/8] Remove performance settings to see whether it helps --- minetest.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/minetest.conf b/minetest.conf index 7e1ca9cd86..e122db7b3e 100644 --- a/minetest.conf +++ b/minetest.conf @@ -33,10 +33,10 @@ mgvalleys_spflags = noaltitude_chill,noaltitude_dry,nohumid_rivers,vary_river_de keepInventory = false # Performance settings -dedicated_server_step = 0.001 -abm_interval = 0.25 -max_objects_per_block = 4096 -max_packets_per_iteration = 10096 +# dedicated_server_step = 0.001 +# abm_interval = 0.25 +# max_objects_per_block = 4096 +# max_packets_per_iteration = 10096 # Clientmodding to support official client enable_client_modding = true From 327bb68927c1a96c4eb491e36605cb40a969ff1b Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Mar 2021 12:03:32 +0100 Subject: [PATCH 7/8] Fix crystal on_place handler --- mods/ITEMS/mcl_end/end_crystal.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_end/end_crystal.lua b/mods/ITEMS/mcl_end/end_crystal.lua index 8686f1de0c..b6b9fdd6a5 100644 --- a/mods/ITEMS/mcl_end/end_crystal.lua +++ b/mods/ITEMS/mcl_end/end_crystal.lua @@ -85,14 +85,15 @@ minetest.register_craftitem("mcl_end:crystal", { on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type == "node" then local pos = minetest.get_pointed_thing_position(pointed_thing) - local node = minetest.get_node(pos).name + local node = minetest.get_node(pos) + local node_name = node.name if placer and not placer:get_player_control().sneak then - if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then - return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack + if minetest.registered_nodes[node_name] and minetest.registered_nodes[node_name].on_rightclick then + return minetest.registered_nodes[node_name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack end end if find_crystal(pos) then return itemstack end - if node == "mcl_core:obsidian" or node == "mcl_core:bedrock" then + if node_name == "mcl_core:obsidian" or node_name == "mcl_core:bedrock" then if not minetest.is_creative_enabled(placer:get_player_name()) then itemstack:take_item() end From 9391628813e219fd9d591e3f037be2cd80e096eb Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Mar 2021 12:41:03 +0100 Subject: [PATCH 8/8] Fix wielded nodes being upside down --- mods/PLAYER/wieldview/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/wieldview/init.lua b/mods/PLAYER/wieldview/init.lua index a170f78707..6c0f085690 100644 --- a/mods/PLAYER/wieldview/init.lua +++ b/mods/PLAYER/wieldview/init.lua @@ -72,7 +72,7 @@ minetest.register_on_joinplayer(function(player) minetest.after(0, function(player) wieldview:update_wielded_item(player) local itementity = minetest.add_entity(player:get_pos(), "wieldview:wieldnode") - itementity:set_attach(player, "Hand_Right", vector.new(0, 1, 0), vector.new(-90, 0, 45)) + itementity:set_attach(player, "Hand_Right", vector.new(0, 1, 0), vector.new(90, 0, 45)) itementity:get_luaentity().wielder = name end, player) end)