From f498d3ae02b02d32d17fae639a655477c620a806 Mon Sep 17 00:00:00 2001 From: epCode Date: Tue, 13 Apr 2021 11:45:31 -0700 Subject: [PATCH 1/3] make elytra activate mor MC-like --- mods/PLAYER/mcl_playerplus/init.lua | 38 +++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 5ba73cd60..b1b994613 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -175,14 +175,14 @@ minetest.register_globalstep(function(dtime) ]]-- - local controls = player:get_player_control() + local control = player:get_player_control() local name = player:get_player_name() local meta = player:get_meta() local parent = player:get_attach() local wielded = player:get_wielded_item() local player_velocity = player:get_velocity() or player:get_player_velocity() - -- controls head bone + -- control head bone local pitch = - degrees(player:get_look_vertical()) local yaw = degrees(player:get_look_horizontal()) @@ -199,11 +199,22 @@ minetest.register_globalstep(function(dtime) minetest.log("action", "somehow player got of loaded areas") end + controls.register_on_press(function(player, key) + if key~="jump" then return end + 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 + 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 + 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 + end]] if elytra[player] == true then mcl_player.player_set_animation(player, "fly") @@ -213,9 +224,10 @@ minetest.register_globalstep(function(dtime) end if math.abs(player_velocity.x) + math.abs(player_velocity.z) < 20 then local dir = minetest.yaw_to_dir(player:get_look_horizontal()) - player:add_velocity({x=dir.x, y=0, z=dir.z}) + local pitch = 1 * player:get_look_vertical() * -.1 + player:add_velocity({x=dir.x, y=pitch, z=dir.z}) end - if controls.sneak then + if control.sneak then if player_velocity.y > -5 then player:add_velocity({x=0, y=-2, z=0}) end @@ -225,11 +237,11 @@ minetest.register_globalstep(function(dtime) end -- controls right and left arms pitch when shooting a bow - if string.find(wielded: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 + if string.find(wielded:get_name(), "mcl_bows:bow") and control.RMB and not control.LMB and not control.up and not control.down and not control.left and not control.right then player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch+90,-30,pitch * -1 * .35)) player:set_bone_position("Arm_Left_Pitch_Control", vector.new(3.5,5.785,0), vector.new(pitch+90,43,pitch * .35)) -- when punching - elseif controls.LMB and not parent then + elseif control.LMB and not parent then player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch,0,0)) player:set_bone_position("Arm_Left_Pitch_Control", vector.new(3,5.785,0), vector.new(0,0,0)) -- when holding an item. @@ -246,15 +258,15 @@ 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.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, 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 = 0, 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)) 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 = 225, 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 = 0, 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 controls.sneak then + elseif control.sneak then -- controls head pitch when sneaking player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+36,0,0)) -- sets eye height, and nametag color accordingly @@ -265,12 +277,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 = 225, 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 = 0, 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 = 225, 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 = 0, 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)) @@ -283,7 +295,7 @@ minetest.register_globalstep(function(dtime) mcl_playerplus_internal[name].jump_cooldown = mcl_playerplus_internal[name].jump_cooldown - dtime end - if controls.jump and mcl_playerplus_internal[name].jump_cooldown <= 0 then + if control.jump and mcl_playerplus_internal[name].jump_cooldown <= 0 then pos = player:get_pos() From 67c1bc973aca2bafb9d3a919c0701ab17f7b17f7 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 9 Apr 2021 01:38:34 -0400 Subject: [PATCH 2/3] Add lua locals into mcl_dungeons for performance --- mods/MAPGEN/mcl_dungeons/init.lua | 97 +++++++++++++++++++------------ 1 file changed, 60 insertions(+), 37 deletions(-) diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index dc9c6d619..928faaa11 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -9,15 +9,38 @@ if mcl_vars.mg_dungeons == false or mg_name == "singlenode" then return end -local min_y = math.max(mcl_vars.mg_overworld_min, mcl_vars.mg_bedrock_overworld_max) + 1 -local max_y = mcl_vars.mg_overworld_max - 1 +--lua locals +--minetest +local registered_nodes = minetest.registered_nodes +local swap_node = minetest.swap_node +local set_node = minetest.set_node +local dir_to_facedir = minetest.dir_to_facedir +local get_meta = minetest.get_meta +local emerge_area = minetest.emerge_area +--vector +local vector_add = vector.add +local vector_subtract = vector.subtract + +--table +local table_insert = table.insert +local table_sort = table.sort + +--math +local math_min = math.min +local math_max = math.max +local math_ceil = math.ceil + +--custom mcl_vars local get_node = mcl_vars.get_node + +local min_y = math_max(mcl_vars.mg_overworld_min, mcl_vars.mg_bedrock_overworld_max) + 1 +local max_y = mcl_vars.mg_overworld_max - 1 -- Calculate the number of dungeon spawn attempts -- In Minecraft, there 8 dungeon spawn attempts Minecraft chunk (16*256*16 = 65536 blocks). -- Minetest chunks don't have this size, so scale the number accordingly. -local attempts = math.ceil(((mcl_vars.chunksize * mcl_vars.MAP_BLOCKSIZE) ^ 3) / 8192) -- 63 = 80*80*80/8192 +local attempts = math_ceil(((mcl_vars.chunksize * mcl_vars.MAP_BLOCKSIZE) ^ 3) / 8192) -- 63 = 80*80*80/8192 local dungeonsizes = { { x=5, y=4, z=5}, @@ -51,8 +74,8 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) local y_floor = y local y_ceiling = y + dim.y + 1 if check then for tx = x+1, x+dim.x do for tz = z+1, z+dim.z do - if not minetest.registered_nodes[get_node({x = tx, y = y_floor , z = tz}).name].walkable - or not minetest.registered_nodes[get_node({x = tx, y = y_ceiling, z = tz}).name].walkable then return false end + if not registered_nodes[get_node({x = tx, y = y_floor , z = tz}).name].walkable + or not registered_nodes[get_node({x = tx, y = y_ceiling, z = tz}).name].walkable then return false end end end end -- Check for air openings (2 stacked air at ground level) in wall positions @@ -69,25 +92,25 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) openings_counter = openings_counter + 1 if not openings[x] then openings[x]={} end openings[x][z] = true - table.insert(corners, {x=x, z=z}) + table_insert(corners, {x=x, z=z}) end if get_node({x=x2, y=y+1, z=z}).name == "air" and get_node({x=x2, y=y+2, z=z}).name == "air" then openings_counter = openings_counter + 1 if not openings[x2] then openings[x2]={} end openings[x2][z] = true - table.insert(corners, {x=x2, z=z}) + table_insert(corners, {x=x2, z=z}) end if get_node({x=x, y=y+1, z=z2}).name == "air" and get_node({x=x, y=y+2, z=z2}).name == "air" then openings_counter = openings_counter + 1 if not openings[x] then openings[x]={} end openings[x][z2] = true - table.insert(corners, {x=x, z=z2}) + table_insert(corners, {x=x, z=z2}) end if get_node({x=x2, y=y+1, z=z2}).name == "air" and get_node({x=x2, y=y+2, z=z2}).name == "air" then openings_counter = openings_counter + 1 if not openings[x2] then openings[x2]={} end openings[x2][z2] = true - table.insert(corners, {x=x2, z=z2}) + table_insert(corners, {x=x2, z=z2}) end for wx = x+1, x+dim.x do @@ -180,16 +203,16 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) secondChance = false end lastRandom = r - table.insert(chestSlots, r) + table_insert(chestSlots, r) end - table.sort(chestSlots) + table_sort(chestSlots) local currentChest = 1 -- Calculate the mob spawner position, to be re-used for later - local sp = {x = x + math.ceil(dim.x/2), y = y+1, z = z + math.ceil(dim.z/2)} - local rn = minetest.registered_nodes[get_node(sp).name] + local sp = {x = x + math_ceil(dim.x/2), y = y+1, z = z + math_ceil(dim.z/2)} + local rn = registered_nodes[get_node(sp).name] if rn and rn.is_ground_content then - table.insert(spawner_posses, sp) + table_insert(spawner_posses, sp) end -- Generate walls and floor @@ -203,13 +226,13 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) -- Do not overwrite nodes with is_ground_content == false (e.g. bedrock) -- Exceptions: cobblestone and mossy cobblestone so neighborings dungeons nicely connect to each other local name = get_node(p).name - if minetest.registered_nodes[name].is_ground_content or name == "mcl_core:cobble" or name == "mcl_core:mossycobble" then + if registered_nodes[name].is_ground_content or name == "mcl_core:cobble" or name == "mcl_core:mossycobble" then -- Floor if ty == y then if pr:next(1,4) == 1 then - minetest.swap_node(p, {name = "mcl_core:cobble"}) + swap_node(p, {name = "mcl_core:cobble"}) else - minetest.swap_node(p, {name = "mcl_core:mossycobble"}) + swap_node(p, {name = "mcl_core:mossycobble"}) end -- Generate walls @@ -221,14 +244,14 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) -- Check if it's an opening first if (ty == maxy) or (not (openings[tx] and openings[tx][tz])) then -- Place wall or ceiling - minetest.swap_node(p, {name = "mcl_core:cobble"}) + swap_node(p, {name = "mcl_core:cobble"}) elseif ty < maxy - 1 then -- Normally the openings are already clear, but not if it is a corner -- widening. Make sure to clear at least the bottom 2 nodes of an opening. - if name ~= "air" then minetest.swap_node(p, {name = "air"}) end + if name ~= "air" then swap_node(p, {name = "air"}) end elseif name ~= "air" then -- This allows for variation between 2-node and 3-node high openings. - minetest.swap_node(p, {name = "mcl_core:cobble"}) + swap_node(p, {name = "mcl_core:cobble"}) end -- If it was an opening, the lower 3 blocks are not touched at all @@ -236,9 +259,9 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) else if (ty==y+1) and (tx==x+1 or tx==maxx-1 or tz==z+1 or tz==maxz-1) and (currentChest < totalChests + 1) and (chestSlots[currentChest] == chestSlotCounter) then currentChest = currentChest + 1 - table.insert(chests, {x=tx, y=ty, z=tz}) + table_insert(chests, {x=tx, y=ty, z=tz}) else - minetest.swap_node(p, {name = "air"}) + swap_node(p, {name = "air"}) end local forChest = ty==y+1 and (tx==x+1 or tx==maxx-1 or tz==z+1 or tz==maxz-1) @@ -246,9 +269,9 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) -- Place next chest at the wall (if it was its chosen wall slot) if forChest and (currentChest < totalChests + 1) and (chestSlots[currentChest] == chestSlotCounter) then currentChest = currentChest + 1 - table.insert(chests, {x=tx, y=ty, z=tz}) + table_insert(chests, {x=tx, y=ty, z=tz}) -- else - --minetest.swap_node(p, {name = "air"}) + --swap_node(p, {name = "air"}) end if forChest then chestSlotCounter = chestSlotCounter + 1 @@ -263,15 +286,15 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) local surroundings = {} for s=1, #surround_vectors do -- Detect the 4 horizontal neighbors - local spos = vector.add(pos, surround_vectors[s]) - local wpos = vector.subtract(pos, surround_vectors[s]) + local spos = vector_add(pos, surround_vectors[s]) + local wpos = vector_subtract(pos, surround_vectors[s]) local nodename = get_node(spos).name local nodename2 = get_node(wpos).name - local nodedef = minetest.registered_nodes[nodename] - local nodedef2 = minetest.registered_nodes[nodename2] + local nodedef = registered_nodes[nodename] + local nodedef2 = registered_nodes[nodename2] -- The chest needs an open space in front of it and a walkable node (except chest) behind it if nodedef and nodedef.walkable == false and nodedef2 and nodedef2.walkable == true and nodename2 ~= "mcl_chests:chest" then - table.insert(surroundings, spos) + table_insert(surroundings, spos) end end -- Set param2 (=facedir) of this chest @@ -282,11 +305,11 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) else -- 1 or multiple possible open directions: Choose random facedir local face_to = surroundings[pr:next(1, #surroundings)] - facedir = minetest.dir_to_facedir(vector.subtract(pos, face_to)) + facedir = dir_to_facedir(vector_subtract(pos, face_to)) end - minetest.set_node(pos, {name="mcl_chests:chest", param2=facedir}) - local meta = minetest.get_meta(pos) + set_node(pos, {name="mcl_chests:chest", param2=facedir}) + local meta = get_meta(pos) local loottable = { @@ -336,7 +359,7 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) -- Bonus loot for v6 mapgen: Otherwise unobtainable saplings. if mg_name == "v6" then - table.insert(loottable, { + table_insert(loottable, { stacks_min = 1, stacks_max = 3, items = { @@ -356,7 +379,7 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) for s=#spawner_posses, 1, -1 do local sp = spawner_posses[s] -- ... and place it and select a random mob - minetest.set_node(sp, {name = "mcl_mobspawners:spawner"}) + set_node(sp, {name = "mcl_mobspawners:spawner"}) local mobs = { "mobs_mc:zombie", "mobs_mc:zombie", @@ -370,7 +393,7 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) end local function dungeons_nodes(minp, maxp, blockseed) - local ymin, ymax = math.max(min_y, minp.y), math.min(max_y, maxp.y) + local ymin, ymax = math_max(min_y, minp.y), math_min(max_y, maxp.y) if ymax < ymin then return false end local pr = PseudoRandom(blockseed) for a=1, attempts do @@ -382,7 +405,7 @@ local function dungeons_nodes(minp, maxp, blockseed) local p2 = {x = x+dim.x+1, y = y+dim.y+1, z = z+dim.z+1} minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) local param = {p1=p1, p2=p2, dim=dim, pr=pr} - minetest.emerge_area(p1, p2, ecb_spawn_dungeon, param) + emerge_area(p1, p2, ecb_spawn_dungeon, param) end end @@ -392,7 +415,7 @@ function mcl_dungeons.spawn_dungeon(p1, _, pr) local p2 = {x = p1.x+dim.x+1, y = p1.y+dim.y+1, z = p1.z+dim.z+1} minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) local param = {p1=p1, p2=p2, dim=dim, pr=pr, dontcheck=true} - minetest.emerge_area(p1, p2, ecb_spawn_dungeon, param) + emerge_area(p1, p2, ecb_spawn_dungeon, param) end mcl_mapgen_core.register_generator("dungeons", nil, dungeons_nodes, 999999) From 399ed8571725e34bbd361f744f2e3c2be56ca1ef Mon Sep 17 00:00:00 2001 From: epCode Date: Tue, 13 Apr 2021 16:14:37 -0700 Subject: [PATCH 3/3] Make flying w elytra use pitch and not sneak --- mods/PLAYER/mcl_playerplus/init.lua | 31 +++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index b1b994613..3084474f3 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -24,6 +24,7 @@ local mcl_playerplus_internal = {} local def = {} local time = 0 +local look_pitch = 0 local player_collision = function(player) @@ -194,18 +195,27 @@ minetest.register_globalstep(function(dtime) player_vel_yaws[name] = player_vel_yaw if minetest.get_node_or_nil({x=player:get_pos().x, y=player:get_pos().y - 0.5, z=player:get_pos().z}) then - node_stand_return = minetest.get_node_or_nil({x=player:get_pos().x, y=player:get_pos().y - 0.5, z=player:get_pos().z}).name + node_stand_return = minetest.get_node_or_nil({x=player:get_pos().x, y=player:get_pos().y - 0.1, z=player:get_pos().z}).name else minetest.log("action", "somehow player got of loaded areas") end controls.register_on_press(function(player, key) - if key~="jump" then return end - 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 + 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 + local item = wielded:take_item() + player:set_wielded_item(wielded) + end + end end end) + local chestplate = player:get_inventory():get_stack("armor", 3) + 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 elytra[player] = false end @@ -216,6 +226,8 @@ minetest.register_globalstep(function(dtime) elytra[player] = false end]] + minetest.chat_send_all(degrees(player:get_look_vertical()) * -.01) + if elytra[player] == true then mcl_player.player_set_animation(player, "fly") playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1) @@ -224,13 +236,12 @@ minetest.register_globalstep(function(dtime) end if math.abs(player_velocity.x) + math.abs(player_velocity.z) < 20 then local dir = minetest.yaw_to_dir(player:get_look_horizontal()) - local pitch = 1 * player:get_look_vertical() * -.1 - player:add_velocity({x=dir.x, y=pitch, z=dir.z}) - end - if control.sneak then - if player_velocity.y > -5 then - player:add_velocity({x=0, y=-2, z=0}) + 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 else playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra")