From f8b54db3929206b4c826533aad035f1c71cc7b89 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sat, 17 Apr 2021 18:55:56 +0200 Subject: [PATCH 1/9] Fix controls.register_on_press being called for every player in a globalstep --- mods/PLAYER/mcl_playerplus/init.lua | 51 +++++++++++++---------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index b14d34824..65c585f52 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -199,22 +199,7 @@ minetest.register_globalstep(function(dtime) end end - - controls.register_on_press(function(player, key) - if key~="jump" and key~="RMB" then return end - if key=="jump" then - if player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" and player_velocity.y < -6 and elytra[player] ~= true then - elytra[player] = true - elseif key=="RMB" then - if wielded:get_name() == "mcl_tools:rocket" then - wielded:take_item() - player:set_wielded_item(wielded) - end - end - end - end) - - if elytra[player] == true and node_stand_return ~= "air" or elytra[player] == true and player:get_inventory():get_stack("armor", 3):get_name() ~= "mcl_armor:elytra" or player:get_attach() ~= nil then + if elytra[player] == true and ~= nil then elytra[player] = false end --[[ @@ -224,21 +209,29 @@ minetest.register_globalstep(function(dtime) elytra[player] = false end]] - if elytra[player] == true then - mcl_player.player_set_animation(player, "fly") - playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) - if player_velocity.y < -1.5 then - player:add_velocity({x=0, y=0.17, z=0}) - end - if math.abs(player_velocity.x) + math.abs(player_velocity.z) < 20 then - local dir = minetest.yaw_to_dir(player:get_look_horizontal()) - if degrees(player:get_look_vertical()) * -.01 < .1 then - look_pitch = degrees(player:get_look_vertical()) * -.01 - else - look_pitch = .1 + local wearing_elytra = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" + + if elytra[player] then + if node_stand_return ~= "air" or not wearing_elytra or player:get_attach() then + elytra[player] = false + else + mcl_player.player_set_animation(player, "fly") + playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) + if player_velocity.y < -1.5 then + player:add_velocity({x=0, y=0.17, z=0}) + end + if math.abs(player_velocity.x) + math.abs(player_velocity.z) < 20 then + local dir = minetest.yaw_to_dir(player:get_look_horizontal()) + if degrees(player:get_look_vertical()) * -.01 < .1 then + look_pitch = degrees(player:get_look_vertical()) * -.01 + else + look_pitch = .1 + end + player:add_velocity({x=dir.x, y=look_pitch, z=dir.z}) end - player:add_velocity({x=dir.x, y=look_pitch, z=dir.z}) end + elseif wearing_elytra and player_velocity.y < -6 and controls.jump then + elytra[player] = true else playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra") end From 205572cc693cde98fc7f3bed890d61f449627ee5 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sat, 17 Apr 2021 19:34:23 +0200 Subject: [PATCH 2/9] Fix elytra code style --- mods/ITEMS/mcl_fireworks/register.lua | 85 +++++++-------------------- mods/PLAYER/mcl_playerplus/init.lua | 83 +++++++++++--------------- 2 files changed, 57 insertions(+), 111 deletions(-) diff --git a/mods/ITEMS/mcl_fireworks/register.lua b/mods/ITEMS/mcl_fireworks/register.lua index cce36042a..08f07c5cb 100644 --- a/mods/ITEMS/mcl_fireworks/register.lua +++ b/mods/ITEMS/mcl_fireworks/register.lua @@ -1,69 +1,28 @@ local S = minetest.get_translator("mcl_fireworks") -player_rocketing = {} +local player_rocketing = {} -local help = S("Flight Duration:") +local tt_help = S("Flight Duration:") local description = S("Firework Rocket") -local rocket_sound = function() - minetest.sound_play("mcl_fireworks_rocket") + +local function register_rocket(n, duration, force) + minetest.register_craftitem("mcl_fireworks:rocket_" .. n, { + description = description, + _tt_help = tt_help .. " " .. duration, + inventory_image = "mcl_fireworks_rocket.png", + stack_max = 64, + on_use = function(itemstack, user, pointed_thing) + local elytra = mcl_playerplus.elytra[user] + if elytra.active and elytra.rocketing <= 0 then + elytra.rocketing = duration + itemstack:take_item() + minetest.sound_play("mcl_fireworks_rocket", {pos = user:get_pos()}) + end + return itemstack + end, + }) end -minetest.register_craftitem("mcl_fireworks:rocket_1", { - description = description, - _tt_help = help.." 1", - inventory_image = "mcl_fireworks_rocket.png", - stack_max = 64, - on_use = function(itemstack, user, pointed_thing) - local torso = user:get_inventory():get_stack("armor", 3) - if torso and torso:get_name() == "mcl_armor:elytra" and player_rocketing[user] ~= true then - player_rocketing[user] = true - minetest.after(2.2, function() - player_rocketing[user] = false - end) - itemstack:take_item() - --user:add_player_velocity(vector.multiply(user:get_look_dir(), 20)) - rocket_sound() - end - return itemstack - end, -}) - -minetest.register_craftitem("mcl_fireworks:rocket_2", { - description = description, - _tt_help = help.." 2", - inventory_image = "mcl_fireworks_rocket.png", - stack_max = 64, - on_use = function(itemstack, user, pointed_thing) - local torso = user:get_inventory():get_stack("armor", 3) - if torso and torso:get_name() == "mcl_armor:elytra" and player_rocketing[user] ~= true then - player_rocketing[user] = true - minetest.after(4.5, function() - player_rocketing[user] = false - end) - itemstack:take_item() - --user:add_player_velocity(vector.multiply(user:get_look_dir(), 20)) - rocket_sound() - end - return itemstack - end, -}) - -minetest.register_craftitem("mcl_fireworks:rocket_3", { - description = description, - _tt_help = help.." 3", - inventory_image = "mcl_fireworks_rocket.png", - stack_max = 64, - on_use = function(itemstack, user, pointed_thing) - local torso = user:get_inventory():get_stack("armor", 3) - if torso and torso:get_name() == "mcl_armor:elytra" and player_rocketing[user] ~= true then - player_rocketing[user] = true - minetest.after(6, function() - player_rocketing[user] = false - end) - itemstack:take_item() - --user:add_player_velocity(vector.multiply(user:get_look_dir(), 20)) - rocket_sound() - end - return itemstack - end, -}) +register_rocket(1, 2.2, 10) +register_rocket(2, 4.5, 20) +register_rocket(3, 6, 30) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 65c585f52..38844a1e1 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -1,8 +1,9 @@ local S = minetest.get_translator("mcl_playerplus") -elytra = {} +mcl_playerplus = { + elytra = {}, +} -local node_stand_return = ":air" local get_connected_players = minetest.get_connected_players local dir_to_yaw = minetest.dir_to_yaw local get_item_group = minetest.get_item_group @@ -183,56 +184,40 @@ minetest.register_globalstep(function(dtime) player_vel_yaw = limit_vel_yaw(player_vel_yaw, yaw) player_vel_yaws[name] = player_vel_yaw - local pos = player:get_pos() - local node = minetest.get_node_or_nil({x = pos.x, y = pos.y - 0.5, z = pos.z}) + local fly_pos = player:get_pos() + local fly_node = minetest.get_node({x = fly_pos.x, y = fly_pos.y - 0.5, z = fly_pos.z}).name + local elytra = mcl_playerplus.elytra[player] - if node then - node_stand_return = node.name - end + elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" + and not player:get_attach() + and (elytra.active or control.jump and player_velocity.y < -6) + and (fly_node == "air" or fly_node == "ignore") - local chestplate = player:get_inventory():get_stack("armor", 3) - - if player_rocketing[player] and player_rocketing[player] == true and chestplate:get_name() == "mcl_armor:elytra" then - if math.abs(player_velocity.x) + math.abs(player_velocity.y) + math.abs(player_velocity.z) < 40 then - player:add_player_velocity(vector.multiply(player:get_look_dir(), 4)) - elytra[player] = true + if elytra.active then + mcl_player.player_set_animation(player, "fly") + if player_velocity.y < -1.5 then + player:add_velocity({x=0, y=0.17, z=0}) end - end - - if elytra[player] == true and ~= nil then - elytra[player] = false - end ---[[ - if player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" and player_velocity.y < -6 and elytra[player] ~= true and is_sprinting(name) then - elytra[player] = true - elseif elytra[player] == true and node_stand_return ~= "air" or elytra[player] == true and player:get_inventory():get_stack("armor", 3):get_name() ~= "mcl_armor:elytra" or player:get_attach() ~= nil then - elytra[player] = false - end]] - - local wearing_elytra = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" - - if elytra[player] then - if node_stand_return ~= "air" or not wearing_elytra or player:get_attach() then - elytra[player] = false - else - mcl_player.player_set_animation(player, "fly") - playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) - if player_velocity.y < -1.5 then - player:add_velocity({x=0, y=0.17, z=0}) + if math.abs(player_velocity.x) + math.abs(player_velocity.z) < 20 then + local dir = minetest.yaw_to_dir(player:get_look_horizontal()) + if degrees(player:get_look_vertical()) * -.01 < .1 then + look_pitch = degrees(player:get_look_vertical()) * -.01 + else + look_pitch = .1 end - if math.abs(player_velocity.x) + math.abs(player_velocity.z) < 20 then - local dir = minetest.yaw_to_dir(player:get_look_horizontal()) - if degrees(player:get_look_vertical()) * -.01 < .1 then - look_pitch = degrees(player:get_look_vertical()) * -.01 - else - look_pitch = .1 - end - player:add_velocity({x=dir.x, y=look_pitch, z=dir.z}) + player:add_velocity({x=dir.x, y=look_pitch, z=dir.z}) + end + playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) + + if elytra.rocketing > 0 then + elytra.rocketing = elytra.rocketing - dtime + if vector.length(player_velocity) < 40 then + local add_velocity = player.add_velocity or player.add_player_velocity + add_velocity(player, vector.multiply(player:get_look_dir(), 4)) end end - elseif wearing_elytra and player_velocity.y < -6 and controls.jump then - elytra[player] = true else + elytra.rocketing = 0 playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra") end @@ -254,12 +239,12 @@ minetest.register_globalstep(function(dtime) player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(0,0,0)) end - if elytra[player] == true then - -- set head pitch and yaw when swimming + if elytra.active then + -- set head pitch and yaw when flying 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 = 0, g = 225 }}) - -- control body bone when swimming + -- control body bone when flying 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 parent then local parent_yaw = degrees(parent:get_yaw()) @@ -523,6 +508,7 @@ minetest.register_on_joinplayer(function(player) swimDistance = 0, jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly } + mcl_playerplus.elytra[player] = {active = false, rocketing = 0} end) -- clear when player leaves @@ -530,4 +516,5 @@ minetest.register_on_leaveplayer(function(player) local name = player:get_player_name() mcl_playerplus_internal[name] = nil + mcl_playerplus.elytra[player] = nil end) From baebe3c2d2b80122ff4c413711213d7c3d19b5c9 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sat, 17 Apr 2021 20:55:08 +0200 Subject: [PATCH 3/9] Fix namtags being invisible --- mods/PLAYER/mcl_playerplus/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 38844a1e1..360f4fe5d 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -243,12 +243,12 @@ minetest.register_globalstep(function(dtime) -- set head pitch and yaw when flying 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 = 0, g = 225 }}) + 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 flying 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 parent then local parent_yaw = degrees(parent:get_yaw()) - player:set_properties({collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 0, g = 225 }}) + player:set_properties({collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, 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, -limit_vel_yaw(yaw, parent_yaw) + parent_yaw, 0)) player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,0,0)) elseif control.sneak then @@ -262,12 +262,12 @@ minetest.register_globalstep(function(dtime) -- 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)),player_vel_yaw - yaw,0)) -- sets eye height, and nametag color accordingly - player:set_properties({collisionbox = {-0.312,0,-0.312,0.312,0.8,0.312}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 0, g = 225 }}) + player:set_properties({collisionbox = {-0.312,0,-0.312,0.312,0.8,0.312}, 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 + yaw + 180,0)) else -- sets eye height, and nametag color accordingly - player:set_properties({collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 0, g = 225 }}) + player:set_properties({collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, 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, 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)) From bcd058feb1c1cd4bd24086a99838d3aa8cce8526 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sat, 17 Apr 2021 21:00:32 +0200 Subject: [PATCH 4/9] Fix get_light crash --- mods/ENTITIES/mcl_mobs/api.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 9182b11c6..1b5715b2a 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1029,6 +1029,14 @@ local node_ok = function(pos, fallback) return minetest.registered_nodes[fallback] end +local function get_light(pos) + if math.abs(pos.x) < 31000 and math.abs(pos.y) < 31000 and math.abs(pos.z) < 31000 then + local lightfunc = minetest.get_natural_light or minetest.get_node_light + return lightfunc(pos) + else + return 0 + end +end -- environmental damage (water, lava, fire, light etc.) local do_env_damage = function(self) @@ -1074,7 +1082,6 @@ local do_env_damage = function(self) -- Use get_node_light for Minetest version 5.3 where get_natural_light -- does not exist yet. - local get_light = minetest.get_natural_light or minetest.get_node_light local sunlight = get_light(pos, self.time_of_day) -- bright light harms mob From a7e102426a49bf1c60381621e65cdaa9e87bb6d5 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sat, 17 Apr 2021 21:01:09 +0200 Subject: [PATCH 5/9] Add time_of_day to get_light crash fix --- mods/ENTITIES/mcl_mobs/api.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 1b5715b2a..8aed37288 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1029,10 +1029,10 @@ local node_ok = function(pos, fallback) return minetest.registered_nodes[fallback] end -local function get_light(pos) +local function get_light(pos, tod) if math.abs(pos.x) < 31000 and math.abs(pos.y) < 31000 and math.abs(pos.z) < 31000 then local lightfunc = minetest.get_natural_light or minetest.get_node_light - return lightfunc(pos) + return lightfunc(pos, tod) else return 0 end From 11b66e83a26fa22ceb580d33ddfc5285faaa5dd3 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 18 Apr 2021 04:28:14 +0400 Subject: [PATCH 6/9] [mcl_portals] Better NP search, no more teleports on the roof, fix https://git.minetest.land/MineClone2/MineClone2/issues/1560 --- mods/ITEMS/mcl_portals/portal_nether.lua | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index 1d9fe2efb..a121f719c 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -27,9 +27,8 @@ local DELAY = 3 -- seconds before teleporting in Nether portal in Survival mo local DISTANCE_MAX = 128 local PORTAL = "mcl_portals:portal" local OBSIDIAN = "mcl_core:obsidian" -local O_Y_MIN, O_Y_MAX = max(mcl_vars.mg_overworld_min, -31), min(mcl_vars.mg_overworld_max_official, 2048) -local N_Y_MIN, N_Y_MAX = mcl_vars.mg_bedrock_nether_bottom_min, mcl_vars.mg_bedrock_nether_top_max - H_MIN -local O_DY, N_DY = O_Y_MAX - O_Y_MIN + 1, N_Y_MAX - N_Y_MIN + 1 +local O_Y_MIN, O_Y_MAX = max(mcl_vars.mg_overworld_min, -31), min(mcl_vars.mg_overworld_max, 2048) +local N_Y_MIN, N_Y_MAX = mcl_vars.mg_bedrock_nether_bottom_min, mcl_vars.mg_bedrock_nether_top_min - H_MIN -- Alpha and particles local node_particles_allowed = minetest.settings:get("mcl_node_particles") or "none" @@ -78,6 +77,8 @@ local pos_to_string = minetest.pos_to_string local is_area_protected = minetest.is_area_protected local get_us_time = minetest.get_us_time +local dimension_to_teleport = { nether = "overworld", overworld = "nether" } + local limits = { nether = { pmin = {x=LIM_MIN, y = N_Y_MIN, z = LIM_MIN}, @@ -181,10 +182,10 @@ local function get_target(p) x, o1 = ping_pong(x, TRAVEL_X, LIM_MIN, LIM_MAX) z, o2 = ping_pong(z, TRAVEL_Z, LIM_MIN, LIM_MAX) y = floor(y * TRAVEL_Y + (o1+o2) / 16 * LIM_MAX) - y = min(max(y + mcl_vars.mg_overworld_min, mcl_vars.mg_overworld_min), mcl_vars.mg_overworld_max) + y = min(max(y + O_Y_MIN, O_Y_MIN), O_Y_MAX) elseif d=="overworld" then x, y, z = floor(x / TRAVEL_X + 0.5), floor(y / TRAVEL_Y + 0.5), floor(z / TRAVEL_Z + 0.5) - y = min(max(y + mcl_vars.mg_nether_min, mcl_vars.mg_nether_min), mcl_vars.mg_nether_max) + y = min(max(y + N_Y_MIN, N_Y_MIN), N_Y_MAX) end return {x=x, y=y, z=z}, d end @@ -457,8 +458,8 @@ local function ecb_scan_area_2(blockpos, action, calls_remaining, param) local nodes = find_nodes_in_area_under_air(pos1, pos2, {"group:building_block"}) if nodes then local nc = #nodes + log("action", "[mcl_portals] Area for destination Nether portal emerged! Found " .. tostring(nc) .. " nodes under the air around "..pos_to_string(pos)) if nc > 0 then - log("action", "[mcl_portals] Area for destination Nether portal emerged! Found " .. tostring(nc) .. " nodes under the air around "..pos_to_string(pos)) for i=1,nc do local node = nodes[i] local node1 = {x=node.x, y=node.y+1, z=node.z } @@ -474,7 +475,7 @@ local function ecb_scan_area_2(blockpos, action, calls_remaining, param) return end if not distance or (distance0 < distance) or (distance0 < distance-1 and node.y > lava and pos0.y < lava) then - log("action", "[mcl_portals] found distance "..tostring(distance0).." at pos "..pos_to_string(node)) + log("verbose", "[mcl_portals] found distance "..tostring(distance0).." at pos "..pos_to_string(node)) distance = distance0 pos0 = {x=node1.x, y=node1.y, z=node1.z} end @@ -626,7 +627,7 @@ end -- Pos can be any of the inner part. -- The frame MUST be filled only with air or any fire, which will be replaced with Nether portal blocks. -- If no Nether portal can be lit, nothing happens. --- Returns number of portals created (0, 1 or 2) +-- Returns true if portal created function mcl_portals.light_nether_portal(pos) -- Only allow to make portals in Overworld and Nether local dim = mcl_worlds.pos_to_dimension(pos) @@ -636,11 +637,6 @@ function mcl_portals.light_nether_portal(pos) local orientation = random(0, 1) for orientation_iteration = 1, 2 do if check_and_light_shape(pos, orientation) then - minetest.after(0.2, function(pos) -- generate target map chunk - local pos1 = add(mul(mcl_vars.pos_to_chunk(pos), mcl_vars.chunk_size_in_nodes), mcl_vars.central_chunk_offset_in_nodes) - local pos2 = add(pos1, mcl_vars.chunk_size_in_nodes - 1) - minetest.emerge_area(pos1, pos2) - end, vector.new(pos)) return true end orientation = 1 - orientation @@ -672,6 +668,7 @@ local function teleport_no_delay(obj, pos) if exit then finalize_teleport(obj, exit) else + dim = dimension_to_teleport[dim] -- need to create arrival portal create_portal(target, limits[dim].pmin, limits[dim].pmax, name, obj) end From dd69dcfd9f5fe5c8e481e275536f130853fc9e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Sat, 17 Apr 2021 23:03:57 +0200 Subject: [PATCH 7/9] Fix efficiency and unbreaking not working together This commit fixes an issue were tools enchanted with both efficiency and unbreaking would loose the effect of one of the enchantments in some conditions. --- mods/ITEMS/mcl_enchanting/enchantments.lua | 6 +++--- mods/ITEMS/mcl_enchanting/engine.lua | 1 + mods/ITEMS/mcl_enchanting/groupcaps.lua | 12 ++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index ca936c319..df6105d52 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -771,11 +771,11 @@ mcl_enchanting.enchantments.unbreaking = { curse = false, on_enchant = function(itemstack, level) local tool_capabilities = itemstack:get_tool_capabilities() - for group, capability in pairs(tool_capabilities.groupcaps) do - capability.uses = capability.uses * (1 + level) - end tool_capabilities.punch_attack_uses = tool_capabilities.punch_attack_uses * (1 + level) itemstack:get_meta():set_tool_capabilities(tool_capabilities) + + -- Unbreaking for groupcaps is handled in this function. + mcl_enchanting.update_groupcaps(itemstack) end, requires_tool = true, treasure = false, diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index ea69d1868..30e4a9a86 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -17,6 +17,7 @@ function mcl_enchanting.unload_enchantments(itemstack) local meta = itemstack:get_meta() if meta:get_string("name") == "" then meta:set_string("description", "") + meta:set_string("groupcaps_hash", "") end end diff --git a/mods/ITEMS/mcl_enchanting/groupcaps.lua b/mods/ITEMS/mcl_enchanting/groupcaps.lua index 375029547..1a4f8fd14 100644 --- a/mods/ITEMS/mcl_enchanting/groupcaps.lua +++ b/mods/ITEMS/mcl_enchanting/groupcaps.lua @@ -50,13 +50,21 @@ function mcl_enchanting.update_groupcaps(itemstack) end local name = itemstack:get_name() - local level = mcl_enchanting.get_enchantment(itemstack, "efficiency") - local groupcaps = get_efficiency_groupcaps(name, level) + local efficiency = mcl_enchanting.get_enchantment(itemstack, "efficiency") + local groupcaps = get_efficiency_groupcaps(name, efficiency) local hash = itemstack:get_meta():get_string("groupcaps_hash") if not hash or hash ~= groupcaps.hash then local tool_capabilities = itemstack:get_tool_capabilities() tool_capabilities.groupcaps = groupcaps.values + + -- Increase the number of uses depending on the unbreaking level + -- of the tool. + local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking") + for group, capability in pairs(tool_capabilities.groupcaps) do + capability.uses = capability.uses * (1 + unbreaking) + end + itemstack:get_meta():set_tool_capabilities(tool_capabilities) itemstack:get_meta():set_string("groupcaps_hash", groupcaps.hash) end From 573b1dc44b4376bca3fe4bf4d3ed18f24210723b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Sat, 17 Apr 2021 23:40:19 +0200 Subject: [PATCH 8/9] Do not include unnecessary tool_capabilities This commit makes enchanted tools which have no use for tool_capabilities to not include it in their metadata. It does this by not including tool_capabilities in the metadata of an enchanted tool if at least one of two cases is true: (1) The tool is not enchanted with unbreaking or efficiency (2) The tool does not have tool_capabilities defined in its definition The first case covers situations like having a pickaxe only being enchanted with silk_touch. The second case covers situations like a piece of armor being enchanted with unbreaking. --- mods/ITEMS/mcl_enchanting/enchantments.lua | 5 +++++ mods/ITEMS/mcl_enchanting/engine.lua | 2 +- mods/ITEMS/mcl_enchanting/groupcaps.lua | 10 +++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index df6105d52..fa3bc3ed5 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -770,6 +770,11 @@ mcl_enchanting.enchantments.unbreaking = { description = S("Increases item durability."), curse = false, on_enchant = function(itemstack, level) + local name = itemstack:get_name() + if not minetest.registered_tools[name].tool_capabilities then + return + end + local tool_capabilities = itemstack:get_tool_capabilities() tool_capabilities.punch_attack_uses = tool_capabilities.punch_attack_uses * (1 + level) itemstack:get_meta():set_tool_capabilities(tool_capabilities) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index 30e4a9a86..037134e4c 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -12,7 +12,7 @@ end function mcl_enchanting.unload_enchantments(itemstack) local itemdef = itemstack:get_definition() if itemdef.tool_capabilities then - itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities) + itemstack:get_meta():set_tool_capabilities(nil) end local meta = itemstack:get_meta() if meta:get_string("name") == "" then diff --git a/mods/ITEMS/mcl_enchanting/groupcaps.lua b/mods/ITEMS/mcl_enchanting/groupcaps.lua index 1a4f8fd14..0bc1b8e24 100644 --- a/mods/ITEMS/mcl_enchanting/groupcaps.lua +++ b/mods/ITEMS/mcl_enchanting/groupcaps.lua @@ -45,12 +45,17 @@ end -- To make it more efficient it will first check a hash value to determine if -- the tool needs to be updated. function mcl_enchanting.update_groupcaps(itemstack) - if not itemstack:get_meta():get("tool_capabilities") then + local name = itemstack:get_name() + if not minetest.registered_tools[name].tool_capabilities then return end - local name = itemstack:get_name() local efficiency = mcl_enchanting.get_enchantment(itemstack, "efficiency") + local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking") + if unbreaking == 0 and efficiency == 0 then + return + end + local groupcaps = get_efficiency_groupcaps(name, efficiency) local hash = itemstack:get_meta():get_string("groupcaps_hash") @@ -60,7 +65,6 @@ function mcl_enchanting.update_groupcaps(itemstack) -- Increase the number of uses depending on the unbreaking level -- of the tool. - local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking") for group, capability in pairs(tool_capabilities.groupcaps) do capability.uses = capability.uses * (1 + unbreaking) end From 5d9c3cd85bc5f5cd2650f5e982a9ae0626f4d385 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sun, 18 Apr 2021 14:41:44 +0200 Subject: [PATCH 9/9] Fix #1572 --- mods/PLAYER/mcl_playerplus/init.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 360f4fe5d..f7c430509 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -150,13 +150,6 @@ minetest.register_globalstep(function(dtime) for _,player in pairs(get_connected_players()) do - local c_x, c_y = unpack(player_collision(player)) - - if player:get_velocity().x + player:get_velocity().y < .5 and c_x + c_y > 0 then - --minetest.chat_send_player(player:get_player_name(), "pushed at " .. c_x + c_y .. " parsecs.") - player:add_velocity({x=c_x, y=0, z=c_y}) - end - --[[ _ _ _ __ _ _ __ (_)_ __ ___ __ _| |_(_) ___ _ __ ___ @@ -173,6 +166,14 @@ minetest.register_globalstep(function(dtime) local wielded = player:get_wielded_item() local player_velocity = player:get_velocity() or player:get_player_velocity() + local c_x, c_y = unpack(player_collision(player)) + + if player_velocity.x + player_velocity.y < .5 and c_x + c_y > 0 then + local add_velocity = player.add_player_velocity or player.add_velocity + add_velocity(player, {x = c_x, y = 0, z = c_y}) + player_velocity = player:get_velocity() or player:get_player_velocity() + end + -- control head bone local pitch = - degrees(player:get_look_vertical()) local yaw = degrees(player:get_look_horizontal())